diff --git a/modules/misc/specialisation.nix b/modules/misc/specialisation.nix index 62a12470..946f7ae4 100644 --- a/modules/misc/specialisation.nix +++ b/modules/misc/specialisation.nix @@ -11,23 +11,21 @@ in { type = types.attrsOf (types.submodule { options = { configuration = mkOption { - type = - let - extended = extendModules { - modules = [{ - # Prevent infinite recursion - specialisation = mkOverride 0 { }; + type = let + extended = extendModules { + modules = [{ + # Prevent infinite recursion + specialisation = mkOverride 0 { }; - # If used inside the NixOS/nix-darwin module, we get conflicting definitions - # of `name` inside the specialisation: one is the user name coming from the - # NixOS module definition and the other is `configuration`, the name of this - # option. Thus we need to explicitly wire the former into the module arguments. - # See discussion at https://github.com/nix-community/home-manager/issues/3716 - _module.args.name = mkForce name; - }]; - }; - in - extended.type; + # If used inside the NixOS/nix-darwin module, we get conflicting definitions + # of `name` inside the specialisation: one is the user name coming from the + # NixOS module definition and the other is `configuration`, the name of this + # option. Thus we need to explicitly wire the former into the module arguments. + # See discussion at https://github.com/nix-community/home-manager/issues/3716 + _module.args.name = mkForce name; + }]; + }; + in extended.type; default = { }; visible = "shallow"; description = '' @@ -89,25 +87,21 @@ in { message = "There can only be one default specialisation"; }]; - home.extraBuilderCommands = - let - link = n: v: - let pkg = v.configuration.home.activationPackage; - in "ln -s ${pkg} $out/specialisation/${n}"; - in - '' - mkdir $out/specialisation - ${concatStringsSep "\n" (mapAttrsToList link cfg)} - ''; + home.extraBuilderCommands = let + link = n: v: + let pkg = v.configuration.home.activationPackage; + in "ln -s ${pkg} $out/specialisation/${n}"; + in '' + mkdir $out/specialisation + ${concatStringsSep "\n" (mapAttrsToList link cfg)} + ''; - home.activation = - let - defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg); - in - mkIf (defaultSpecialisation != null) (mkForce { - activateSpecialisation = '' - ${defaultSpecialisation.configuration.home.activationPackage}/activate - ''; - }); + home.activation = let + defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg); + in mkIf (defaultSpecialisation != null) (mkForce { + activateSpecialisation = '' + ${defaultSpecialisation.configuration.home.activationPackage}/activate + ''; + }); }; } diff --git a/tests/modules/misc/specialisation/default-specialisation.nix b/tests/modules/misc/specialisation/default-specialisation.nix new file mode 100644 index 00000000..e1e69ce8 --- /dev/null +++ b/tests/modules/misc/specialisation/default-specialisation.nix @@ -0,0 +1,10 @@ +{ config, ... }: { + home.file.testfile.text = "not special"; + specialisation = { test.default = true; }; + + nmt.script = '' + assertFileExists activate + assertFileContains activate \ + "${config.specialisation.test.configuration.home.activationPackage}/activate" + ''; +} diff --git a/tests/modules/misc/specialisation/default.nix b/tests/modules/misc/specialisation/default.nix index 33c240ff..74cf0f1a 100644 --- a/tests/modules/misc/specialisation/default.nix +++ b/tests/modules/misc/specialisation/default.nix @@ -1 +1,4 @@ -{ specialisation = ./specialisation.nix; } +{ + specialisation = ./specialisation.nix; + default-specialisation = ./default-specialisation.nix; +}