default-specialisation: add test for default specialisation

This commit is contained in:
Weathercold 2022-10-08 16:29:46 -04:00
parent 01a518ba06
commit c00a3920ce
No known key found for this signature in database
GPG key ID: 059102E35214D867
3 changed files with 43 additions and 36 deletions

View file

@ -11,8 +11,7 @@ in {
type = types.attrsOf (types.submodule {
options = {
configuration = mkOption {
type =
let
type = let
extended = extendModules {
modules = [{
# Prevent infinite recursion
@ -26,8 +25,7 @@ in {
_module.args.name = mkForce name;
}];
};
in
extended.type;
in extended.type;
default = { };
visible = "shallow";
description = ''
@ -89,22 +87,18 @@ in {
message = "There can only be one default specialisation";
}];
home.extraBuilderCommands =
let
home.extraBuilderCommands = let
link = n: v:
let pkg = v.configuration.home.activationPackage;
in "ln -s ${pkg} $out/specialisation/${n}";
in
''
in ''
mkdir $out/specialisation
${concatStringsSep "\n" (mapAttrsToList link cfg)}
'';
home.activation =
let
home.activation = let
defaultSpecialisation = findFirst (s: s.default) null (attrValues cfg);
in
mkIf (defaultSpecialisation != null) (mkForce {
in mkIf (defaultSpecialisation != null) (mkForce {
activateSpecialisation = ''
${defaultSpecialisation.configuration.home.activationPackage}/activate
'';

View file

@ -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"
'';
}

View file

@ -1 +1,4 @@
{ specialisation = ./specialisation.nix; }
{
specialisation = ./specialisation.nix;
default-specialisation = ./default-specialisation.nix;
}