Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma tries to use nix-channels with flakes #43

Open
Tungsten842 opened this issue Dec 29, 2022 · 7 comments
Open

Comma tries to use nix-channels with flakes #43

Tungsten842 opened this issue Dec 29, 2022 · 7 comments

Comments

@Tungsten842
Copy link

Tungsten842 commented Dec 29, 2022

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)
@Artturin
Copy link
Member

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

.contains("nixpkgs");

what is the output of echo $NIX_PATH

@Tungsten842
Copy link
Author

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

.contains("nixpkgs");

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

run_cmd.args([format!("nixpkgs#{}", choice)]);

@fmoda3
Copy link

fmoda3 commented Apr 5, 2023

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?

@Artturin
Copy link
Member

Artturin commented Apr 5, 2023

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 e27a636 thanks for the report

@Artturin
Copy link
Member

Artturin commented Apr 5, 2023

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

implemented in 17a4f33

panchoh added a commit to panchoh/nixos that referenced this issue Jun 7, 2023
nix-community/comma#43
In my case, $NIX_ENV is not even defined, but still fails.
@huantianad
Copy link

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?

@marienz
Copy link

marienz commented Jun 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants