comma icon indicating copy to clipboard operation
comma copied to clipboard

Comma tries to use nix-channels with flakes

Open Tungsten842 opened this issue 2 years ago • 7 comments

I installed comma with: $ nix profile install github:nix-community/comma When running: , cbonsai I get:

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

Tungsten842 avatar Dec 29 '22 10:12 Tungsten842

Currently we're checking if NIX_PATH contains nixpkgs(users usually remove it if using flakes) and determining if we should use flakes or channels

https://github.com/nix-community/comma/blob/c83ff3839983b3cb8deb407ff618ca12179de588/src/main.rs#L106

what is the output of echo $NIX_PATH

Artturin avatar Dec 29 '22 12:12 Artturin

Currently we're checking if NIX_PATH contains nixpkgs(users usually remove it if using flakes) and determining if we should use flakes or channels

https://github.com/nix-community/comma/blob/c83ff3839983b3cb8deb407ff618ca12179de588/src/main.rs#L106

what is the output of echo $NIX_PATH

❯ echo $NIX_PATH
/home/quantmint/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

Isn't there a better way to find out if a user is using flakes? I use flakes, but NIX_PATH is set by default. Also, is it possible to use a different flake for comma (instead of nixpkgs)? https://github.com/nix-community/comma/blob/c83ff3839983b3cb8deb407ff618ca12179de588/src/main.rs#L50

Tungsten842 avatar Dec 29 '22 19:12 Tungsten842

I ran into this same issue. I use flakes, and my NIX_PATH is

/Users/fmoda3/.nix-defexpr/channels:darwin-config=/Users/fmoda3/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels

which happens to contain "nixpkgs" in one of the entries, making comma think I am using channels.

To fix it, i had to add nix.nixPath = [ "nixpkgs=${nixpkgs}" ]; to my flake, to force a nixpkgs entry that points to my flake.

After this addition, NIX_PATH becomes

/Users/fmoda3/.nix-defexpr/channels:darwin-config=/Users/fmoda3/.nixpkgs/darwin-configuration.nix:nixpkgs=/nix/store/v0vq1p4c17x97w2py57xanh4nlh4v4cn-source:/nix/var/nix/profiles/per-user/root/channels

I wonder if the .contains("nixpkgs") should be .contains("nixpkgs=") in order to differentiate when nixpkgs is explicitly specified, or just happens to be in the path of a different entry?

fmoda3 avatar Apr 05 '23 21:04 fmoda3

I wonder if the .contains("nixpkgs") should be .contains("nixpkgs=") in order to differentiate when nixpkgs is explicitly specified, or just happens to be in the path of a different entry?

fixed https://github.com/nix-community/comma/commit/e27a6369909e324ef845c4ece512c2e2e09c2a68 thanks for the report

Artturin avatar Apr 05 '23 21:04 Artturin

is it possible to use a different flake for comma (instead of nixpkgs)?

implemented in https://github.com/nix-community/comma/commit/17a4f3384954a43cec0f91361f153cda908fe3d3

Artturin avatar Apr 05 '23 22:04 Artturin

My current NIX_PATH is nixpkgs=flake:nixpkgs as set by the nixpkgs.flake.setNixPath option, but this causes comma to error on usage with error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I). Is there something I need to do on my end to fix this?

huantianad avatar Mar 12 '24 22:03 huantianad

To hopefully save others finding this issue through the error mentioned above some time: if you have nix.channel.enable = false in your NixOS configuration, NixOS puts nix-path = (empty path) in /etc/nix/nix.conf, which overrides NIX_PATH. So if you then leave nixpkgs.flake.setNixPath enabled (the new default in 24.05), that sets a NIX_PATH in the environment that Nix doesn't actually use, which trips up comma (it assumes that if there's a nixpkgs= in NIX_PATH it can and should use that).

Until this is fixed in Nix and/or NixOS, you may have to mess with settings a bit to get nix-path in the configuration file and NIX_PATH in the environment back in sync (personally I just disabled nixpkgs.flake.setNixPath, but enabling nix.channel.enable or fiddling with nix.settings.nix-path so that it matches NIX_PATH or at least has nixpkgs=flake:nixpkgs probably also works).

(I think comma could check for nixpkgs in nix-path in nix show-config / nix config show to work around this, but that seems like a hassle to deal with a setup that doesn't really make sense...)

marienz avatar Jun 01 '24 07:06 marienz