feat(a1d1): init
Co-Authored-By: Samuel Shuert <coded@clicks.codes>
Change-Id: Iaf1499b8cde6d3f6bdb024374f6830d582006aeb
Reviewed-on: https://git.clicks.codes/c/Infra/NixFiles/+/720
Tested-by: Samuel Shuert <coded@clicks.codes>
Reviewed-by: Samuel Shuert <coded@clicks.codes>
diff --git a/lib/deploy/default.nix b/lib/deploy/default.nix
new file mode 100644
index 0000000..1eaa186
--- /dev/null
+++ b/lib/deploy/default.nix
@@ -0,0 +1,60 @@
+# SPDX-FileCopyrightText: 2024 Auxolotl Infrastructure Contributors
+# SPDX-FileCopyrightText: 2024 Clicks Codes
+#
+# SPDX-License-Identifier: GPL-3.0-only
+
+{ lib, inputs }:
+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.users.infra 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;
+ }
+ // {
+ user = "root";
+ }
+ // lib.optionalAttrs host.config.clicks.security.doas.enable { sudo = "doas -u"; };
+ };
+ };
+ }
+ ) { } names;
+ in
+ {
+ inherit nodes;
+ };
+}