nix-community / nix-index

Quickly locate nix packages with specific files [maintainers=@bennofs @figsoda @raitobezarius]
Other
817 stars 50 forks source link

Make use of Nix flake registry instead of channel #167

Open ambroisie opened 3 years ago

ambroisie commented 3 years ago

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.

malob commented 2 years ago

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.

LunNova commented 2 years ago

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.

malob commented 2 years ago

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

srid commented 2 years ago

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.

dfrankland commented 2 years ago

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

anajuliabit commented 1 year ago

@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 ...
figsoda commented 1 year ago

@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

anajuliabit commented 1 year ago

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

hpfr commented 7 months ago

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?

srid commented 7 months ago

@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

boomshroom commented 7 months ago

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