-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
nixos: Disable nix-channel #242098
nixos: Disable nix-channel #242098
Changes from all commits
218ef2f
faa1b3b
d00e242
61afc4d
a1d0ee8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ | |||||||||||||||||||||||||
{ config, lib, ... }: | ||||||||||||||||||||||||||
let | ||||||||||||||||||||||||||
inherit (lib) | ||||||||||||||||||||||||||
mkDefault | ||||||||||||||||||||||||||
mkIf | ||||||||||||||||||||||||||
mkOption | ||||||||||||||||||||||||||
stringAfter | ||||||||||||||||||||||||||
|
@@ -21,13 +22,42 @@ in | |||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
options = { | ||||||||||||||||||||||||||
nix = { | ||||||||||||||||||||||||||
channel = { | ||||||||||||||||||||||||||
enable = mkOption { | ||||||||||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||||||||||
Whether the `nix-channel` command and state files are made available on the machine. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
The following files are initialized when enabled: | ||||||||||||||||||||||||||
- `/nix/var/nix/profiles/per-user/root/channels` | ||||||||||||||||||||||||||
- `/root/.nix-channels` | ||||||||||||||||||||||||||
- `$HOME/.nix-defexpr/channels` (on login) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Disabling this option will not remove the state files from the system. | ||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||
type = types.bool; | ||||||||||||||||||||||||||
default = true; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
nixPath = mkOption { | ||||||||||||||||||||||||||
type = types.listOf types.str; | ||||||||||||||||||||||||||
default = [ | ||||||||||||||||||||||||||
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos" | ||||||||||||||||||||||||||
"nixos-config=/etc/nixos/configuration.nix" | ||||||||||||||||||||||||||
"/nix/var/nix/profiles/per-user/root/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 []; | ||||||||||||||||||||||||||
defaultText = '' | ||||||||||||||||||||||||||
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 []; | ||||||||||||||||||||||||||
Comment on lines
+53
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is harder to understand for someone who doesn't contribute to nixpkgs or other expressions regularly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documentation should not require someone to know the |
||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||
description = lib.mdDoc '' | ||||||||||||||||||||||||||
The default Nix expression search path, used by the Nix | ||||||||||||||||||||||||||
evaluator to look up paths enclosed in angle brackets | ||||||||||||||||||||||||||
|
@@ -49,22 +79,30 @@ in | |||||||||||||||||||||||||
config = mkIf cfg.enable { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
environment.extraInit = | ||||||||||||||||||||||||||
'' | ||||||||||||||||||||||||||
mkIf cfg.channel.enable '' | ||||||||||||||||||||||||||
if [ -e "$HOME/.nix-defexpr/channels" ]; then | ||||||||||||||||||||||||||
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}" | ||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
environment.extraSetup = mkIf (!cfg.channel.enable) '' | ||||||||||||||||||||||||||
rm $out/bin/nix-channel | ||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# NIX_PATH has a non-empty default according to Nix docs, so we don't unset | ||||||||||||||||||||||||||
# it when empty. | ||||||||||||||||||||||||||
environment.sessionVariables = { | ||||||||||||||||||||||||||
NIX_PATH = cfg.nixPath; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
system.activationScripts.nix-channel = stringAfter [ "etc" "users" ] | ||||||||||||||||||||||||||
'' | ||||||||||||||||||||||||||
nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault ""); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. The point of this is one really doesn't want to use a populated One can always set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, yeah, that sounds about right. Maybe I misunderstood the feature a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Kind of debatable, IMO. Feels like you're assuming that disabling channels automatically implies that:
The reality is that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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:
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
system.activationScripts.nix-channel = mkIf cfg.channel.enable | ||||||||||||||||||||||||||
(stringAfter [ "etc" "users" ] '' | ||||||||||||||||||||||||||
# Subscribe the root user to the NixOS channel by default. | ||||||||||||||||||||||||||
if [ ! -e "/root/.nix-channels" ]; then | ||||||||||||||||||||||||||
echo "${config.system.defaultChannel} nixos" > "/root/.nix-channels" | ||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||
''; | ||||||||||||||||||||||||||
''); | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This file gets copied into the installation | ||
|
||
{ | ||
# To keep things simple, we'll use an absolute path dependency here. | ||
inputs.nixpkgs.url = "@nixpkgs@"; | ||
|
||
outputs = { nixpkgs, ... }: { | ||
|
||
nixosConfigurations.xyz = nixpkgs.lib.nixosSystem { | ||
modules = [ | ||
./configuration.nix | ||
( nixpkgs + "/nixos/modules/testing/test-instrumentation.nix" ) | ||
{ | ||
# We don't need nix-channel anymore | ||
nix.channel.enable = false; | ||
} | ||
]; | ||
}; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exactly equal to the documented default. Let's keep them in sync, and see other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference?