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

View File

@ -59,15 +59,19 @@ let
profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything);
default = os: {
sshUser = "root";
user = "admin";
path = inputs.deploy.lib.${os.system}.activate.nixos os.config;
system = {
sshUser = "root";
user = "admin";
path = inputs.deploy.lib.${os.system}.activate.nixos os.config;
};
};
defaultText = lib.literalExpression ''
os: {
sshUser = "root";
user = "admin";
path = inputs.deploy-rs.lib.''${os.system}.activate.nixos os.config;
system = {
sshUser = "root";
user = "admin";
path = <deploy-rs>.lib.''${os.system}.activate.nixos os.config;
};
}
'';
description = ''
@ -178,7 +182,10 @@ let
type = with lib.types; nullOr (submodule deployNodeType);
default = null;
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 = {
hostname = "work1.example.com";
@ -327,7 +334,19 @@ in
(name: configs:
lib.mapAttrs'
(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)
validConfigs;
};