Stream: nix

Topic: nix-index


view this post on Zulip Srid (Jan 19 2024 at 06:59):

image.png

@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.

view this post on Zulip Srid (Jan 19 2024 at 07:00):

This uses a program called nix-index, which uses old-style commands unfortunately: https://github.com/nix-community/nix-index/issues/191

view this post on Zulip Srid (Jan 19 2024 at 07:02):

^ Potential OSS contribution here

view this post on Zulip Srid (Jan 19 2024 at 07:03):

Here's the home-manager config for enabling this:

  programs = {
    nix-index = {
      enable = true;
      enableZshIntegration = true;
    };
  }

view this post on Zulip Srid (Jan 19 2024 at 07:04):

https://github.com/juspay/nix-dev-home/commit/4f4ab11b5f76c054289969d3927e6bbc31e2d981

view this post on Zulip Srid (Jan 19 2024 at 07:06):

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

view this post on Zulip Srid (Jan 19 2024 at 07:08):

I did nix profile install nixpkgs#hello just to populate this manifest, and now it shows the right thing:

image.png

view this post on Zulip Srid (Jan 19 2024 at 07:12):

$ cat .nix-profile/manifest.json
{"elements":[],"version":2}

view this post on Zulip Aravind Gopal (Jan 19 2024 at 08:31):

This is a good tool to motivate users towards full nix.

view this post on Zulip Srid (Jan 19 2024 at 08:42):

One glitch. The installation is not seamless. You need to generate the index manually the first time,

image.png

view this post on Zulip Srid (Feb 10 2024 at 07:26):

@Aravind Gopal We've automated the nix-index DB generation part,

https://github.com/juspay/nix-dev-home/pull/14

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 13:38):

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?

view this post on Zulip Srid (Dec 19 2024 at 13:42):

@Gabriel Volpe Welcome.

Looks like this now works only after initializing the profile with some package:

image.png

(Creatring just .nix-profile/manifest.json doesn't seem sufficient)

view this post on Zulip Srid (Dec 19 2024 at 13:44):

❯ 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}

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:20):

@Srid thanks. It's not supported without using Nix profile, right? I don't use nix profile at all

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:20):

Sorry for the delay, first time using Zulip, a bit lost here :D

view this post on Zulip Srid (Dec 19 2024 at 14:24):

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.

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:27):

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

view this post on Zulip Srid (Dec 19 2024 at 14:33):

Ah, cool. Let me know if you get something working, perhaps we'll switch to it too.

view this post on Zulip Srid (Dec 19 2024 at 14:35):

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

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:38):

@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:

view this post on Zulip Srid (Dec 19 2024 at 14:39):

Agreed.

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:39):

And it would be compatible if flakes ever become a stable feature

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:40):

s/stable/non-experimental (I think flakes are already stable and well established)

view this post on Zulip Srid (Dec 19 2024 at 14:40):

Would this flag be configurable in home-manager (i.e., here) - and if not how would you set it up?

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:41):

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

view this post on Zulip Gabriel Volpe (Dec 19 2024 at 14:42):

BTW pleasure to chat with you, followed a lot of your writings since my early adventures with Nix and Haskell :)

view this post on Zulip Srid (Dec 19 2024 at 14:42):

Cheers :-)

view this post on Zulip Gabriel Volpe (Dec 20 2024 at 12:35):

@Srid if you'd like to give it a try :)

https://github.com/gvolpe/nix-index/pull/1

view this post on Zulip Srid (Dec 20 2024 at 14:53):

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'

view this post on Zulip Gabriel Volpe (Dec 20 2024 at 14:55):

hmm that's strange, perhaps the overlay is not taking effect? do you have the old nix-index installed?

view this post on Zulip Gabriel Volpe (Dec 20 2024 at 14:56):

this is all I had to do to import it in my nix config: https://github.com/gvolpe/nix-config/commit/2d0486c3de66effdaab9df7485ed3fb83522bd77

view this post on Zulip Gabriel Volpe (Dec 20 2024 at 14:57):

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

view this post on Zulip Srid (Dec 20 2024 at 15:45):

Here's mine: https://github.com/srid/nixos-config/pull/72

view this post on Zulip Srid (Dec 20 2024 at 15:47):

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).

view this post on Zulip Gabriel Volpe (Dec 20 2024 at 16:49):

@Srid think I found the issue, left a comment on your PR


Last updated: Jan 18 2025 at 04:45 UTC