diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-07-05 13:53:25 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-07-05 14:54:29 +0200 |
commit | 5c0c96a8283de416891bb4f8fd67c6e5693ac1a2 (patch) | |
tree | f625b5594dcf53e58cfd959d8047cb1aa04a7872 /nixos/modules/config/nix-channel.nix | |
parent | 1c772cd857b40f86105c99297d7e41d823428c95 (diff) | |
download | nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.gz nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.bz2 nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.lz nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.xz nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.tar.zst nixpkgs-5c0c96a8283de416891bb4f8fd67c6e5693ac1a2.zip |
nixos/config/nix-channel: Factor out root channel initialization
Diffstat (limited to 'nixos/modules/config/nix-channel.nix')
-rw-r--r-- | nixos/modules/config/nix-channel.nix | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/nixos/modules/config/nix-channel.nix b/nixos/modules/config/nix-channel.nix new file mode 100644 index 00000000000..8e6061e4956 --- /dev/null +++ b/nixos/modules/config/nix-channel.nix @@ -0,0 +1,35 @@ +{ config, lib, ... }: +let + inherit (lib) + mkIf + mkOption + stringAfter + types + ; + + cfg = config.nix; + +in +{ + options = { + system = { + defaultChannel = mkOption { + internal = true; + type = types.str; + default = "https://nixos.org/channels/nixos-unstable"; + description = lib.mdDoc "Default NixOS channel to which the root user is subscribed."; + }; + }; + }; + + config = mkIf cfg.enable { + + system.activationScripts.nix-channel = 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 + ''; + }; +} |