2 Manages the things that are needed for a traditional nix-channel based
28 Whether the `nix-channel` command and state files are made available on the machine.
30 The following files are initialized when enabled:
31 - `/nix/var/nix/profiles/per-user/root/channels`
32 - `/root/.nix-channels`
33 - `$HOME/.nix-defexpr/channels` (on login)
35 Disabling this option will not remove the state files from the system.
43 type = types.listOf types.str;
47 "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
48 "nixos-config=/etc/nixos/configuration.nix"
49 "/nix/var/nix/profiles/per-user/root/channels"
55 "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
56 "nixos-config=/etc/nixos/configuration.nix"
57 "/nix/var/nix/profiles/per-user/root/channels"
62 The default Nix expression search path, used by the Nix
63 evaluator to look up paths enclosed in angle brackets
70 defaultChannel = mkOption {
73 default = "https://nixos.org/channels/nixos-unstable";
74 description = "Default NixOS channel to which the root user is subscribed.";
79 config = mkIf cfg.enable {
81 environment.extraInit =
82 mkIf cfg.channel.enable ''
83 if [ -e "$HOME/.nix-defexpr/channels" ]; then
84 export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
88 environment.extraSetup = mkIf (!cfg.channel.enable) ''
89 rm --force $out/bin/nix-channel
92 # NIX_PATH has a non-empty default according to Nix docs, so we don't unset
94 environment.sessionVariables = {
95 NIX_PATH = cfg.nixPath;
98 systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [
99 ''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n''
102 system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable)
103 (stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh));