summary refs log tree commit diff
path: root/nixos/modules/config/nix-channel.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-07-05 13:53:25 +0200
committerRobert Hensing <robert@roberthensing.nl>2023-07-05 14:54:29 +0200
commit5c0c96a8283de416891bb4f8fd67c6e5693ac1a2 (patch)
treef625b5594dcf53e58cfd959d8047cb1aa04a7872 /nixos/modules/config/nix-channel.nix
parent1c772cd857b40f86105c99297d7e41d823428c95 (diff)
downloadnixpkgs-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.nix35
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
+      '';
+  };
+}