From c5b69910c3e8a68e9ed57a76d27132a30ac4517e Mon Sep 17 00:00:00 2001 From: Pyrox Date: Sun, 23 Jun 2024 21:03:22 -0400 Subject: [PATCH] [checks] Add deploy-rs checks --- checks/deploy/default.nix | 2 ++ lib/deploy/default.nix | 62 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 checks/deploy/default.nix create mode 100644 lib/deploy/default.nix diff --git a/checks/deploy/default.nix b/checks/deploy/default.nix new file mode 100644 index 00000000..84b64a8b --- /dev/null +++ b/checks/deploy/default.nix @@ -0,0 +1,2 @@ +{ inputs, ... }: +builtins.mapAttrs (_: deployLib: deployLib.deployChecks inputs.self.deploy) inputs.deploy-rs.lib diff --git a/lib/deploy/default.nix b/lib/deploy/default.nix new file mode 100644 index 00000000..408cffca --- /dev/null +++ b/lib/deploy/default.nix @@ -0,0 +1,62 @@ +# From https://github.com/khaneliman/khanelinix + +{ + lib, + inputs, + namespace, +}: +let + inherit (inputs) deploy-rs; +in +rec { + ## Create deployment configuration for use with deploy-rs. + ## + ## ```nix + ## mkDeploy { + ## inherit self; + ## overrides = { + ## my-host.system.sudo = "doas -u"; + ## }; + ## } + ## ``` + ## + #@ { self: Flake, overrides: Attrs ? {} } -> Attrs + mkDeploy = + { + self, + overrides ? { }, + }: + let + hosts = self.nixosConfigurations or { }; + names = builtins.attrNames hosts; + nodes = lib.foldl ( + result: name: + let + host = hosts.${name}; + user = host.config.${namespace}.user.name or null; + inherit (host.pkgs) system; + in + result + // { + ${name} = (overrides.${name} or { }) // { + hostname = overrides.${name}.hostname or "${name}"; + profiles = (overrides.${name}.profiles or { }) // { + system = + (overrides.${name}.profiles.system or { }) + // { + path = deploy-rs.lib.${system}.activate.nixos host; + } + // lib.optionalAttrs (user != null) { + user = "root"; + sshUser = user; + } + // lib.optionalAttrs (host.config.${namespace}.security.doas.enable or false) { sudo = "doas -u"; }; + }; + }; + } + ) { } names; + in + { + inherit nodes; + }; +} -- 2.51.2