feat(nixos): add settings option for builder config
Allow defining builder repository configuration directly in Nix using the `settings.repos` option, which is more idiomatic for NixOS modules. Users can now choose between: - `settings.repos` - Define repos in Nix (recommended) - `configFile` - Point to an external YAML file The module generates a YAML config file from settings when configFile is not specified. An assertion ensures at least one method is used. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,20 @@ let
|
||||
listenerCfg = config.services.homelab-deploy.listener;
|
||||
builderCfg = config.services.homelab-deploy.builder;
|
||||
|
||||
# Generate YAML config from settings
|
||||
generatedConfigFile = pkgs.writeText "builder.yaml" (lib.generators.toYAML {} {
|
||||
repos = lib.mapAttrs (name: repo: {
|
||||
url = repo.url;
|
||||
default_branch = repo.defaultBranch;
|
||||
}) builderCfg.settings.repos;
|
||||
});
|
||||
|
||||
# Use provided configFile or generate from settings
|
||||
builderConfigFile =
|
||||
if builderCfg.configFile != null
|
||||
then builderCfg.configFile
|
||||
else generatedConfigFile;
|
||||
|
||||
# Build command line arguments for listener from configuration
|
||||
listenerArgs = lib.concatStringsSep " " ([
|
||||
"--hostname ${lib.escapeShellArg listenerCfg.hostname}"
|
||||
@@ -26,7 +40,7 @@ let
|
||||
builderArgs = lib.concatStringsSep " " ([
|
||||
"--nats-url ${lib.escapeShellArg builderCfg.natsUrl}"
|
||||
"--nkey-file ${lib.escapeShellArg builderCfg.nkeyFile}"
|
||||
"--config ${lib.escapeShellArg builderCfg.configFile}"
|
||||
"--config ${builderConfigFile}"
|
||||
"--timeout ${toString builderCfg.timeout}"
|
||||
]
|
||||
++ lib.optionals builderCfg.metrics.enable [
|
||||
@@ -161,11 +175,52 @@ in
|
||||
};
|
||||
|
||||
configFile = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "Path to builder configuration file (YAML)";
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
Path to builder configuration file (YAML).
|
||||
If not specified, a config file will be generated from the `settings` option.
|
||||
'';
|
||||
example = "/etc/homelab-deploy/builder.yaml";
|
||||
};
|
||||
|
||||
settings = {
|
||||
repos = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule {
|
||||
options = {
|
||||
url = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Git flake URL for the repository";
|
||||
example = "git+https://git.example.com/org/nixos-configs.git";
|
||||
};
|
||||
defaultBranch = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "master";
|
||||
description = "Default branch to build when not specified in request";
|
||||
example = "main";
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
description = ''
|
||||
Repository configuration for the builder.
|
||||
Each key is the repository name used in build requests.
|
||||
'';
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
nixos-servers = {
|
||||
url = "git+https://git.example.com/org/nixos-servers.git";
|
||||
defaultBranch = "master";
|
||||
};
|
||||
homelab = {
|
||||
url = "git+ssh://git@github.com/user/homelab.git";
|
||||
defaultBranch = "main";
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
timeout = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 1800;
|
||||
@@ -198,6 +253,15 @@ in
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf builderCfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = builderCfg.configFile != null || builderCfg.settings.repos != {};
|
||||
message = "services.homelab-deploy.builder: either configFile or settings.repos must be specified";
|
||||
}
|
||||
];
|
||||
})
|
||||
|
||||
(lib.mkIf listenerCfg.enable {
|
||||
systemd.services.homelab-deploy-listener = {
|
||||
description = "homelab-deploy listener";
|
||||
|
||||
Reference in New Issue
Block a user