nix-index icon indicating copy to clipboard operation
nix-index copied to clipboard

Make use of Nix flake registry instead of channel

Open ambroisie opened this issue 3 years ago • 11 comments

I would like nix-index to make use of a pinned version of nixpkgs that I set in the Nix registry, instead of Nix channels which I do not use and do not update.

ambroisie avatar Jun 04 '21 21:06 ambroisie

In case it's helpful to you or others, my current workaround is to set nixpkgs on my NIX_PATH to point to a nixpkgs.nix file included in my Nix configs flake.

malob avatar Nov 13 '21 02:11 malob

On nixos it seems to be as easy as setting it to the flake input, no need to construct the URL yourself from the flake.lock or have a local path.

nix.nixPath = [ "nixpkgs=${nixpkgs}" ];

https://github.com/TransLunarInjection/nixos-configs/commit/0258db82d809491c1453cbe7beba9d038a48b244

Not sure if this works on darwin although I don't know why it wouldn't.

LunNova avatar Dec 09 '21 13:12 LunNova

@LunNova, great point! I had forgotten that I was doing things the way I was so that the nixpkgs in NIX_PATH would support workflows that don't support flakes.

malob avatar Dec 14 '21 00:12 malob

If flakes is enabled, it automatically should use nix profile install instead of nix-env -iA. And nix run nixpkgs#<pkg> ... instead of nix-shell ---run.

srid avatar Apr 16 '22 15:04 srid

I can confirm that using nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; works on darwin

dfrankland avatar Jun 10 '22 22:06 dfrankland

@srid @dfrankland I have flakes enabled and set nix.nixPath = [ "nixpkgs=${nixpkgs}" ], but it is still using the channel. Any suggestions for what I could do? :)

The program 'tldr' is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixpkgs.tldr-hs.out
  nix-env -iA nixpkgs.tldr.out
  nix-env -iA nixpkgs.tealdeer.out

Or run it once with:
  nix-shell -p tldr-hs.out --run ...
  nix-shell -p tldr.out --run ...
  nix-shell -p tealdeer.out --run ...

anajuliabit avatar Jun 15 '23 22:06 anajuliabit

@anajuliabit I think you are experiencing #210, currently nix-index's command-not-found only suggests the flake commands if your user profile is with flakes, which I think only happens if you've run one of the nix profile commands once

figsoda avatar Jun 15 '23 22:06 figsoda

@figsoda, you are correct actually, I hid the comment because I reached the same conclusion after writing it. But I will keep it visible for anyone who may find it useful. Thank you!

anajuliabit avatar Jun 17 '23 21:06 anajuliabit

I recently stopped using home-manager and nix-index broke. I’m also using flakes and setting NIX_PATH accordingly. I tried installing something (nix-index, in fact) with nix profile, but still get this error:

0 2024-01-14 12:05:05 $ nix-index
+ querying available packages
error: querying available packages failed
caused by: nix-env failed with error: nix-env failed with exit status: 1:
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

2 2024-01-14 12:05:12 $ printenv NIX_PATH
nixpkgs=/etc/nix/inputs/nixpkgs
0 2024-01-14 12:05:17 $ ls /etc/nix/inputs/nixpkgs/
doc  maintainers  pkgs             COPYING      flake.nix
lib  nixos        CONTRIBUTING.md  default.nix  README.md
0 2024-01-14 12:05:23 $ nix profile list
Index:              0
Flake attribute:    legacyPackages.x86_64-linux.nix-index
Original flake URL: flake:nixpkgs
Locked flake URL:   path:/nix/store/7ix7lj4h8q5jl740bkwvpi611safrq0v-source?lastModified=1702645756&narHash=sha256-qKI6OR3TYJYQB3Q8mAZ%2BDG4o/BR9ptcv9UnRV2hzljc%3D&rev=40c3c94c241286dd2243ea34d3aef8a488f9e4d0
Store paths:        /nix/store/3mashfgk5g2xnsqyl4ljwm44n768dcx7-nix-index-0.1.7

Index:              1
Flake attribute:    legacyPackages.x86_64-linux.nix-index
Original flake URL: flake:nixpkgs
Locked flake URL:   path:/nix/store/7ix7lj4h8q5jl740bkwvpi611safrq0v-source?lastModified=1702645756&narHash=sha256-qKI6OR3TYJYQB3Q8mAZ%2BDG4o/BR9ptcv9UnRV2hzljc%3D&rev=40c3c94c241286dd2243ea34d3aef8a488f9e4d0
Store paths:        /nix/store/3mashfgk5g2xnsqyl4ljwm44n768dcx7-nix-index-0.1.7

What am I missing here?

hpfr avatar Jan 14 '24 18:01 hpfr

@srid @dfrankland I have flakes enabled and set nix.nixPath = [ "nixpkgs=${nixpkgs}" ], but it is still using the channel.

@anajuliabit You can try the workaround mentioned in the Zulip thread linked in https://github.com/nix-community/nix-index/issues/191#issuecomment-1899881356

srid avatar Jan 19 '24 07:01 srid

While nix-index detects the use of flakes if ~/.nix-profile/manifest.nix exists, it fails if nix is set with use-xdg-base-directories = true, which doesn't use ~/.nix-profile, but instead uses $XDG_STATE_HOME/nix/profile (or ~/.local/state/nix/profile if $XDG_STATE_HOME isn't set).

boomshroom avatar Jan 28 '24 20:01 boomshroom