flake-parts/setups: fix deploy-rs nodes config

This commit is contained in:
Gabriel Arazas 2024-01-16 15:29:27 +08:00
parent d3e0802d38
commit 1825a97c74
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 65 additions and 26 deletions

View File

@ -19,7 +19,7 @@ let
modules = extraModules; modules = extraModules;
}; };
deploySettingsType = { config, lib, ... }: { deploySettingsType = { config, lib, username, ... }: {
freeformType = with lib.types; attrsOf anything; freeformType = with lib.types; attrsOf anything;
options = { options = {
@ -30,26 +30,30 @@ let
profiles = lib.mkOption { profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything); type = with lib.types; functionTo (attrsOf anything);
default = os: { default = os: {
sshUser = "root"; home = {
user = "admin"; sshUser = username;
path = inputs.deploy-rs.lib.${os.system}.activate.nixos os.config; user = username;
path = inputs.deploy.lib.${os.system}.activate.home-manager os.config;
};
}; };
defaultText = lib.literalExpression '' defaultText = lib.literalExpression ''
os: { os: {
sshUser = "root"; home = {
user = "admin"; sshUser = "$USERNAME";
path = inputs.deploy-rs.lib.''${os.system}.activate.nixos os.config; user = "$USERNAME";
path = <deploy-rs>.lib.''${os.system}.activate.home-manager os.config;
};
} }
''; '';
description = '' description = ''
A set of profiles for the resulting deploy node. A set of profiles for the resulting deploy node.
Since each config can result in more than one NixOS system, it has to Since each config can result in more than one home-manager
be a function where the passed argument is an attribute set with the environment, it has to be a function where the passed argument is an
following values: attribute set with the following values:
* `name` is the attribute name from `configs`. * `name` is the attribute name from `configs`.
* `config` is the NixOS configuration itself. * `config` is the home-manager configuration itself.
* `system` is a string indicating the platform of the NixOS system. * `system` is a string indicating the platform of the NixOS system.
If unset, it will create a deploy-rs node profile called `home` If unset, it will create a deploy-rs node profile called `home`
@ -129,10 +133,16 @@ let
}; };
deploy = lib.mkOption { deploy = lib.mkOption {
type = with lib.types; nullOr (submodule deploySettingsType); type = with lib.types; nullOr (submoduleWith {
specialArgs = {
username = name;
};
modules = [ deploySettingsType ];
});
default = null; default = null;
description = '' description = ''
deploy-rs settings to be passed onto the home-manager configuration node. deploy-rs settings to be passed onto the home-manager configuration
node.
''; '';
}; };
}; };
@ -218,10 +228,7 @@ in
lib.listToAttrs lib.listToAttrs
(builtins.map (builtins.map
(system: (system:
let lib.nameValuePair system (mkHome {
name = "${username}-${system}";
in
lib.nameValuePair name (mkHome {
inherit (metadata) nixpkgs-branch home-manager-branch; inherit (metadata) nixpkgs-branch home-manager-branch;
inherit system; inherit system;
extraModules = extraModules =
@ -257,7 +264,20 @@ in
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs'
(system: config: lib.nameValuePair "home-manager-${name}-${system}" (system: config: lib.nameValuePair "home-manager-${name}-${system}"
(cfg.configs.${name}.deploy.profiles { inherit name config system; }))) (
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
))
configs)
validConfigs; validConfigs;
}; };
}; };

View File

@ -59,15 +59,19 @@ let
profiles = lib.mkOption { profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything); type = with lib.types; functionTo (attrsOf anything);
default = os: { default = os: {
sshUser = "root"; system = {
user = "admin"; sshUser = "root";
path = inputs.deploy.lib.${os.system}.activate.nixos os.config; user = "admin";
path = inputs.deploy.lib.${os.system}.activate.nixos os.config;
};
}; };
defaultText = lib.literalExpression '' defaultText = lib.literalExpression ''
os: { os: {
sshUser = "root"; system = {
user = "admin"; sshUser = "root";
path = inputs.deploy-rs.lib.''${os.system}.activate.nixos os.config; user = "admin";
path = <deploy-rs>.lib.''${os.system}.activate.nixos os.config;
};
} }
''; '';
description = '' description = ''
@ -178,7 +182,10 @@ let
type = with lib.types; nullOr (submodule deployNodeType); type = with lib.types; nullOr (submodule deployNodeType);
default = null; default = null;
description = '' description = ''
deploy-rs node settings for the resulting NixOS configuration. deploy-rs node settings for the resulting NixOS configuration. When
this attribute is given with a non-null value, it will be included in
`nixosConfigurations` even if
{option}`setups.nixos.configs.<config>.formats` is set.
''; '';
example = { example = {
hostname = "work1.example.com"; hostname = "work1.example.com";
@ -327,7 +334,19 @@ in
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs'
(system: config: lib.nameValuePair "nixos-${name}-${system}" (system: config: lib.nameValuePair "nixos-${name}-${system}"
(cfg.configs.${name}.deploy.profiles { inherit name config system; })) (
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
))
configs) configs)
validConfigs; validConfigs;
}; };