From a066ff0960e6a3798cd6e843bfef1d1913d131bc Mon Sep 17 00:00:00 2001 From: Dmitriy Kholkin Date: Mon, 10 Mar 2025 20:04:25 +0300 Subject: [PATCH] feat: add remote hosts deploy with deploy-rs --- flake.nix | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 6815815..6fa62ff 100644 --- a/flake.nix +++ b/flake.nix @@ -55,7 +55,7 @@ outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } ( - { self, ... }: + { self, withSystem, ... }: { imports = [ inputs.devenv.flakeModule @@ -109,7 +109,7 @@ name = "nixos-config"; packages = builtins.attrValues { - inherit (pkgs) nixfmt-rfc-style sops; + inherit (pkgs) deploy-rs nixfmt-rfc-style sops; }; languages.nix = { enable = true; @@ -151,6 +151,62 @@ }; }; }; + + flake = { + # deploy-rs nodes + deploy = { + # default settings for all deploys + fastConnection = true; + remoteBuild = false; + sshUser = "deploy"; + sudo = "doas -u"; + user = "root"; + # nodes for each system + nodes = withSystem "x86_64-linux" ( + { + liteConfigNixpkgs, + pkgs, + ... + }: + let + # take advantage of the nixpkgs binary cache + deployPkgs = import liteConfigNixpkgs { + system = "x86_64-linux"; + overlays = [ + inputs.deploy-rs.overlay + (_final: prev: { + deploy-rs = { + inherit (pkgs) deploy-rs; + lib = prev.deploy-rs.lib; + }; + }) + ]; + }; + mkDeploy = + name: conf: + pkgs.lib.recursiveUpdate { + profiles.system = { + path = deployPkgs.deploy-rs.lib.activate.nixos self.nixosConfigurations.${name}; + }; + } conf; + in + builtins.mapAttrs mkDeploy { + redshift = { + hostname = "104.164.54.197"; + fastConnection = false; + sshOpts = [ + "-p" + "32323" + ]; + }; + } + ); + }; + + checks = builtins.mapAttrs ( + _system: deployLib: deployLib.deployChecks self.deploy + ) inputs.deploy-rs.lib; + }; } ); }