@Aravind Gopal You were talking about this -- telling the user to display a nix-friendly message when they try to run something that's not already (thus not encouraging them towards of homebrew and the like).
Let me find the config I have for this.
This uses a program called nix-index
, which uses old-style commands unfortunately: https://github.com/nix-community/nix-index/issues/191
^ Potential OSS contribution here
Here's the home-manager config for enabling this:
programs = {
nix-index = {
enable = true;
enableZshIntegration = true;
};
}
https://github.com/juspay/nix-dev-home/commit/4f4ab11b5f76c054289969d3927e6bbc31e2d981
Oh, nix-index does use new style commands but only if ~/.nix-profile/manifest.json
exists:
https://github.com/nix-community/nix-index/commit/cd7cdcb06f3552fc55cf0cded66de90461006c00
I did nix profile install nixpkgs#hello
just to populate this manifest, and now it shows the right thing:
$ cat .nix-profile/manifest.json
{"elements":[],"version":2}
This is a good tool to motivate users towards full nix.
One glitch. The installation is not seamless. You need to generate the index manually the first time,
@Aravind Gopal We've automated the nix-index DB generation part,
https://github.com/juspay/nix-dev-home/pull/14
Came here from this issue: https://github.com/nix-community/nix-index/issues/191
Any ideas if I can get nix-index
to suggest new "nix" commands instead of nix-env
/ nix-shell
?
@Gabriel Volpe Welcome.
Looks like this now works only after initializing the profile with some package:
(Creatring just .nix-profile/manifest.json
doesn't seem sufficient)
❯ more ~/.nix-profile/manifest.json
{"elements":{"hello":{"active":true,"attrPath":"legacyPackages.x86_64-linux.hel
lo","originalUrl":"flake:nixpkgs","outputs":null,"priority":5,"storePaths":["/n
ix/store/1q8w6gl1ll0mwfkqc3c2yx005s6wwfrl-hello-2.12.1"],"url":"path:/nix/store
/22r7q7s9552gn1vpjigkbhfgcvhsrz68-source?lastModified=1734119587&narHash=sha256
-AKU6qqskl0yf2%2BJdRdD0cfxX4b9x3KKV5RqA6wijmPM%3D&rev=3566ab7246670a43abd2ffa91
3cc62dad9cdf7d5"}},"version":3}
@Srid thanks. It's not supported without using Nix profile, right? I don't use nix profile at all
Sorry for the delay, first time using Zulip, a bit lost here :D
I don't use nix profile at all
Yea, me neither. But the above (manifest.json) is basically a workaround, until upstream implements this support.
I do notice that the Nix core community cares little about flakes, which is unfortunate.
Got it. I do recall having all sort of weird issues in the past when mixing up flakes/nix profile/channels, so I think I'll pass on enabling nix profiles just for this. I think I'll just fork the project and fix up the script: https://github.com/nix-community/nix-index/blob/master/command-not-found.sh
Ah, cool. Let me know if you get something working, perhaps we'll switch to it too.
That script should probably check if flakes is enabled this way, rather than look for manifest.json
❯ nix config show | grep 'experimental-features.*flakes'
experimental-features = fetch-tree flakes nix-command
@Srid I think that's just trying to be smart about it. A simple script argument will be enough. Just let the user pass a simple flag and call it a day :man_shrugging:
Agreed.
And it would be compatible if flakes ever become a stable feature
s/stable/non-experimental (I think flakes are already stable and well established)
Would this flag be configurable in home-manager (i.e., here) - and if not how would you set it up?
Yes, that would need to be adapted, but that's easy if the script supports it. Exactly what I wrote about here: https://github.com/nix-community/nix-index/issues/210#issuecomment-2554098215
BTW pleasure to chat with you, followed a lot of your writings since my early adventures with Nix and Haskell :)
Cheers :-)
@Srid if you'd like to give it a try :)
https://github.com/gvolpe/nix-index/pull/1
Great, using this hm module, I get:
> error: collision between `/nix/store/9fw6gqi3h1shbsiagkv3r0gy0kmy8nh1-nix-index-with-db-0.1.8/etc/profile.d/command-not-found.sh' and `/nix/store/rfv2qmpf436ynpnacpkp30ccs9wwmiy3-nix-index-0.1.8/etc/profile.d/command-not-found.sh'
hmm that's strange, perhaps the overlay is not taking effect? do you have the old nix-index installed?
this is all I had to do to import it in my nix config: https://github.com/gvolpe/nix-config/commit/2d0486c3de66effdaab9df7485ed3fb83522bd77
the home manager module is adding the nixpkgs.overlay here: https://github.com/gvolpe/nix-index/blob/master/flake.nix#L24
but it could be the case that may need to be done explicitly in your packages instance? I can expose that separately
Here's mine: https://github.com/srid/nixos-config/pull/72
Can be reproduced using:
nix build github:srid/nixos-config/nix-index-fork#nixosConfigurations.vixen.config.system.build.toplevel
(I'll revisit this later; engaged in something else now).
@Srid think I found the issue, left a comment on your PR
Last updated: Jan 18 2025 at 04:45 UTC