nixos/nix-channel: replace activationScript via tmpfiles

nikstur cb08d3dd a8f50f99

Changed files
+21 -7
nixos
modules
tests
+4 -7
nixos/modules/config/nix-channel.nix
···
nix.settings.nix-path = mkIf (! cfg.channel.enable) (mkDefault "");
-
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
-
'');
+
systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [
+
"f /root/.nix-channels -"
+
''w "/root/.nix-channels" - - - - "${config.system.defaultChannel} nixos\n"''
+
];
};
}
+16
nixos/tests/activation/nix-channel.nix
···
+
{ lib, ... }:
+
+
{
+
+
name = "activation-nix-channel";
+
+
meta.maintainers = with lib.maintainers; [ nikstur ];
+
+
nodes.machine = {
+
nix.channel.enable = true;
+
};
+
+
testScript = ''
+
print(machine.succeed("cat /root/.nix-channels"))
+
'';
+
}
+1
nixos/tests/all-tests.nix
···
etc = pkgs.callPackage ../modules/system/etc/test.nix { inherit evalMinimalConfig; };
activation = pkgs.callPackage ../modules/system/activation/test.nix { };
activation-var = runTest ./activation/var.nix;
+
activation-nix-channel = runTest ./activation/nix-channel.nix;
etcd = handleTestOn ["x86_64-linux"] ./etcd.nix {};
etcd-cluster = handleTestOn ["x86_64-linux"] ./etcd-cluster.nix {};
etebase-server = handleTest ./etebase-server.nix {};