Conversation
For those who wish to get rid of nix-channel.
SuperSandro2000
left a comment
There was a problem hiding this comment.
I like the idea, then I no longer need to hack around removing channels
| default = | ||
| if cfg.channel.enable | ||
| then [ | ||
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | ||
| "nixos-config=/etc/nixos/configuration.nix" | ||
| "/nix/var/nix/profiles/per-user/root/channels" | ||
| ] | ||
| else []; |
There was a problem hiding this comment.
| default = | |
| if cfg.channel.enable | |
| then [ | |
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | |
| "nixos-config=/etc/nixos/configuration.nix" | |
| "/nix/var/nix/profiles/per-user/root/channels" | |
| ] | |
| else []; | |
| default = lib.optionals cfg.channel.enable [ | |
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | |
| "nixos-config=/etc/nixos/configuration.nix" | |
| "/nix/var/nix/profiles/per-user/root/channels" | |
| ]; |
There was a problem hiding this comment.
This is not exactly equal to the documented default. Let's keep them in sync, and see other comment.
| if nix.channel.enable | ||
| then [ | ||
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | ||
| "nixos-config=/etc/nixos/configuration.nix" | ||
| "/nix/var/nix/profiles/per-user/root/channels" | ||
| ] | ||
| else []; |
There was a problem hiding this comment.
| if nix.channel.enable | |
| then [ | |
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | |
| "nixos-config=/etc/nixos/configuration.nix" | |
| "/nix/var/nix/profiles/per-user/root/channels" | |
| ] | |
| else []; | |
| lib.optionals cfg.channel.enable [ | |
| "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | |
| "nixos-config=/etc/nixos/configuration.nix" | |
| "/nix/var/nix/profiles/per-user/root/channels" | |
| ]; |
There was a problem hiding this comment.
This is harder to understand for someone who doesn't contribute to nixpkgs or other expressions regularly. optionals is idiosyncratic to Nixpkgs lib, whereas everyone understand if then else.
There was a problem hiding this comment.
we had multiple treewide replacement for this already, so I don't think we should add new candidates for this
There was a problem hiding this comment.
This documentation should not require someone to know the optionals function.
Co-authored-by: Sandro <[email protected]>
|
Successfully created backport PR for |
|
|
||
| system.activationScripts.nix-channel = stringAfter [ "etc" "users" ] | ||
| '' | ||
| nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault ""); |
There was a problem hiding this comment.
I don't think we want to set this to empty string here because that clears the default nix-path setting of nix which breaks many programs like nix-tree or comma which rely on it to find some nixpkgs which in my case points to a flake.
There was a problem hiding this comment.
I don't think so. The point of this is one really doesn't want to use a populated NIX_PATH. If other programs can't cope with that, they should be fixed.
One can always set nix.settings.nix-path elsewhere than this module instead.
There was a problem hiding this comment.
By default nix-path is left empty which means it default to NIX_PATH env. When we explicitly set it to empty, that is no longer the case and things completely break for many tools which makes this option rather useless.
➜ nix show-config | rg nix-path
nix-path = nixpkgs=/nix/store/x6ly3m0dylzsbrgz0sx937xxcyswr2yp-source nixos=/nix/store/x6ly3m0dylzsbrgz0sx937xxcyswr2yp-source nixos-config=/etc/nixos/configuration.nix
➜ (unset NIX_PATH; nix show-config | rg nix-path)
nix-path =
➜ (unset NIX_PATH; nix --option nix-path "" show-config | rg nix-path)
nix-path =
➜ nix --option nix-path "" show-config | rg nix-path
nix-path =
There was a problem hiding this comment.
That seems like the behaviour that someone ripping out a formerly-mandatory system component to avoid non-flakes things would want, given that properly flakes-aware tools like nixos-rebuild(8) won't look at the Nix path when used correctly.
There was a problem hiding this comment.
hmmm, yeah, that sounds about right. Maybe I misunderstood the feature a bit.
There was a problem hiding this comment.
I don't think so. The point of this is one really doesn't want to use a populated
NIX_PATH
Kind of debatable, IMO. Feels like you're assuming that disabling channels automatically implies that:
- The person is using flakes
- The person wants to use a PURE flake workflow everywhere.
The reality is that:
- nixpkgs is kind of special
- You can use --impure with flakes
- Some people may want a more "it just works" sort of thing with certain types of commands/ and /or the ability to build their system against a flake and then have all other commands use the same version of nixpkgs that their system was built against, or maybe still allow the NIX_PATH variable to take effect.
There was a problem hiding this comment.
That seems like the behaviour that someone ripping out a formerly-mandatory system component to avoid non-flakes things would want, given that properly flakes-aware tools like
nixos-rebuild(8)won't look at the Nix path when used correctly.
This is a weird position that doesn't make sense.
You can only use NIX_PATH at all, if you pass the --impure flag to these commands. If you dont, you'll get:
error: cannot look up '<nixpkgs>' in pure evaluation mode (use '--impure' to override)
If you're explicitly opting IN by passing the --impure flag, this behavior makes absolutely no sense.
Really, the problem is not setting nix-path to the empty string, the problem is NixOS/nix#8890 and NixOS/nix#8890
There was a problem hiding this comment.
I'm also encountered the problem where I don't use channels but put aliases in NIX_PATH for commands. This setting disables NIX_PATH envvar entirely, which is not what I want. I'm kinda thinking we should revert this line.
|
@roberth I find some of the details of this a little confusing: In particular, this: is very weird, because it makes it so that there are now two variables for setting the nix path: nix.settings.nix-path and nix.nixPath and nix.settings.nix-path is not defaulted to the value of nix.nixPath it also seems to me that nix.settings.nix-path should be defined in nix.nix, not in nix-channel.nix, but yeah I'm finding all of this pretty confusing. This is especially an issue in light of NixOS/nix#8890 which is the same as NixOS/nix#8890 |
I have only preserved Main thing is that I wasn't aware of Nix's strange treatment of My original intent with this PR had two layers
It was not my intent to break |
Yeah I guess its just kind of confusing. If someone sets the value of that variable to something but disables channels, it actually just has no effect. I wasn't aware of the distinction. Would it really be so bad to default the nix-path setting to whatever nixPath is in the event where channels are disabled? Alternatively, maybe we should make it an error to set nixPath at all when channels are disabled. Or maybe its just fine to have different settings for the environment variable and the nix.conf setting, as long as my nix PR is merged. |
Yeah. It shouldn't be like that. I almost started explaining that it does have an effect, but that's the entire point of the bug, which I consider it to be. Though I think it is worth noting that in the case where the bug is fixed in nix, we'll probably still want the NixOS behavior that we currently have. The difference between the To be honest, applying a fix to both projects seems a bit daunting as we'll have three scenarios to consider, while even a single scenario is already quite confusing. So I'd prefer to focus on making Nix treat its option more sensibly, and come back to this NixOS change later if needed. |
|
I created #273170 to revert the line setting an empty nix-path. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation
This fixes a warning that's been bothering me.
Description of changes
Allow users to remove nix-channel and its accompanying files. Opt-in.
configuration.nix:Extends the installer test case to make sure users can switch from a traditional config to a flake.
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)