136 lines
3.5 KiB
Nix
136 lines
3.5 KiB
Nix
{ lib, ... }@exportingFlake:
|
|
let
|
|
inherit (lib) mkOption types;
|
|
|
|
deploy-rs-for-system =
|
|
system:
|
|
(import exportingFlake.inputs.nixpkgs {
|
|
inherit system;
|
|
overlays = [
|
|
exportingFlake.inputs.deploy-rs.overlays.default
|
|
(_final: prev: {
|
|
deploy-rs = {
|
|
inherit (exportingFlake.inputs.nixpkgs.legacyPackages.${system}) deploy-rs;
|
|
inherit (prev.deploy-rs) lib;
|
|
};
|
|
})
|
|
];
|
|
}).deploy-rs;
|
|
in
|
|
{ config, ... }:
|
|
let
|
|
cfg = config.deploy;
|
|
in
|
|
{
|
|
options.deploy =
|
|
let
|
|
genericOptions =
|
|
let
|
|
mkGenericOption =
|
|
type:
|
|
mkOption {
|
|
type = types.nullOr type;
|
|
default = null;
|
|
};
|
|
in
|
|
{
|
|
options = {
|
|
sshUser = mkGenericOption types.str;
|
|
user = mkGenericOption types.str;
|
|
sshOpts = mkGenericOption (types.listOf types.str);
|
|
fastConnection = mkGenericOption types.bool;
|
|
autoRollback = mkGenericOption types.bool;
|
|
magicRollback = mkGenericOption types.bool;
|
|
confirmTimeout = mkGenericOption types.int;
|
|
activationTimeout = mkGenericOption types.int;
|
|
tempPath = mkGenericOption types.str;
|
|
interactiveSudo = mkGenericOption types.bool;
|
|
};
|
|
};
|
|
|
|
profileModule =
|
|
{ config, ... }:
|
|
{
|
|
imports = [ genericOptions ];
|
|
|
|
options = {
|
|
activation = mkOption {
|
|
type = types.oneOf [
|
|
(types.enum [
|
|
"nixos"
|
|
"home-manager"
|
|
"darwin"
|
|
"noop"
|
|
])
|
|
];
|
|
};
|
|
|
|
closure = mkOption { type = types.raw; };
|
|
|
|
profilePath = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = null;
|
|
};
|
|
|
|
path = mkOption {
|
|
type = types.raw;
|
|
internal = true;
|
|
};
|
|
};
|
|
|
|
config =
|
|
let
|
|
inherit (config.closure.config.nixpkgs.hostPlatform) system;
|
|
deploy-rs = deploy-rs-for-system system;
|
|
in
|
|
lib.mkMerge [
|
|
(lib.mkIf (lib.elem config.activation [
|
|
"nixos"
|
|
"home-manager"
|
|
"darwin"
|
|
"noop"
|
|
]) { path = deploy-rs.lib.activate.${config.activation} config.closure; })
|
|
];
|
|
};
|
|
|
|
nodeModule = {
|
|
imports = [ genericOptions ];
|
|
|
|
options = {
|
|
hostname = mkOption { type = types.str; };
|
|
|
|
profilesOrder = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [ ];
|
|
};
|
|
|
|
profiles = mkOption {
|
|
type = types.attrsOf (types.submoduleWith { modules = [ profileModule ]; });
|
|
|
|
apply = lib.mapAttrs (
|
|
_: profile:
|
|
lib.filterAttrs (
|
|
name: val:
|
|
!(lib.elem name [
|
|
"activation"
|
|
"closure"
|
|
])
|
|
&& val != null
|
|
) profile
|
|
);
|
|
|
|
default = { };
|
|
};
|
|
};
|
|
};
|
|
in
|
|
{
|
|
nodes = mkOption {
|
|
default = { };
|
|
type = types.attrsOf (types.submoduleWith { modules = [ nodeModule ]; });
|
|
apply = lib.mapAttrs (_: node: lib.filterAttrs (_: val: val != null) node);
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf (cfg.nodes != { }) { flake.deploy.nodes = cfg.nodes; };
|
|
}
|