From ee9a017c467036778b32882cd2441e5d65d9f8a2 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 30 Jul 2022 16:42:46 +0200 Subject: [PATCH] remove deploy-rs --- flake.lock | 86 +++++++++++++++++++++++------------------- flake.nix | 108 ++++++++++++++++------------------------------------- 2 files changed, 80 insertions(+), 114 deletions(-) diff --git a/flake.lock b/flake.lock index 20c5d67..dd5b9e2 100644 --- a/flake.lock +++ b/flake.lock @@ -26,23 +26,20 @@ "deploy-rs": { "inputs": { "flake-compat": "flake-compat_2", - "nixpkgs": [ - "nixpkgs" - ], - "utils": "utils_2" + "nixpkgs": "nixpkgs_2", + "utils": "utils_3" }, "locked": { - "lastModified": 1653594315, - "narHash": "sha256-kJ0ENmnQJ4qL2FeYKZba9kvv1KmIuB3NVpBwMeI7AJQ=", + "lastModified": 1648475189, + "narHash": "sha256-gAGAS6IagwoUr1B0ohE3iR6sZ8hP4LSqzYLC8Mq3WGU=", "owner": "serokell", "repo": "deploy-rs", - "rev": "184349d8149436748986d1bdba087e4149e9c160", + "rev": "83e0c78291cd08cb827ba0d553ad9158ae5a95c3", "type": "github" }, "original": { - "owner": "serokell", - "repo": "deploy-rs", - "type": "github" + "id": "deploy-rs", + "type": "indirect" } }, "flake-compat": { @@ -203,7 +200,7 @@ "nixpkgs": [ "nixpkgs" ], - "utils": "utils_3" + "utils": "utils_2" }, "locked": { "lastModified": 1659144434, @@ -222,7 +219,7 @@ "nix": { "inputs": { "lowdown-src": "lowdown-src", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1633098935, @@ -240,7 +237,7 @@ "nix_2": { "inputs": { "lowdown-src": "lowdown-src_2", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { "lastModified": 1633098935, @@ -273,17 +270,18 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1632864508, - "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", "type": "github" }, "original": { - "id": "nixpkgs", - "ref": "nixos-21.05-small", - "type": "indirect" + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" } }, "nixpkgs_3": { @@ -301,10 +299,24 @@ "type": "indirect" } }, + "nixpkgs_4": { + "locked": { + "lastModified": 1632864508, + "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.05-small", + "type": "indirect" + } + }, "root": { "inputs": { "colmena": "colmena", - "deploy-rs": "deploy-rs", "minecraft-servers": "minecraft-servers", "nixpkgs": "nixpkgs", "serokell-nix": "serokell-nix", @@ -313,9 +325,7 @@ }, "serokell-nix": { "inputs": { - "deploy-rs": [ - "deploy-rs" - ], + "deploy-rs": "deploy-rs", "flake-compat": "flake-compat_3", "flake-utils": "flake-utils_2", "gitignore-nix": "gitignore-nix", @@ -370,21 +380,6 @@ } }, "utils_2": { - "locked": { - "lastModified": 1648297722, - "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "utils_3": { "inputs": { "flake-utils": "flake-utils" }, @@ -402,6 +397,21 @@ "type": "github" } }, + "utils_3": { + "locked": { + "lastModified": 1648297722, + "narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "vault-secrets": { "inputs": { "flake-compat": "flake-compat_4", diff --git a/flake.nix b/flake.nix index 105f09c..215c76c 100644 --- a/flake.nix +++ b/flake.nix @@ -8,15 +8,11 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - deploy-rs.url = "github:serokell/deploy-rs"; - deploy-rs.inputs.nixpkgs.follows = "nixpkgs"; - colmena.url = "github:zhaofengli/colmena"; colmena.inputs.nixpkgs.follows = "nixpkgs"; serokell-nix.url = "github:serokell/serokell.nix"; serokell-nix.inputs.nixpkgs.follows = "nixpkgs"; - serokell-nix.inputs.deploy-rs.follows = "deploy-rs"; vault-secrets.url = "github:serokell/vault-secrets"; vault-secrets.inputs.nixpkgs.follows = "nixpkgs"; @@ -26,13 +22,14 @@ }; outputs = - { self, nixpkgs, deploy-rs, vault-secrets, serokell-nix, minecraft-servers, ... }@inputs: + { self, nixpkgs, vault-secrets, serokell-nix, minecraft-servers, ... }@inputs: let inherit (nixpkgs) lib; inherit (builtins) filter mapAttrs; system = "x86_64-linux"; hosts = import ./hosts.nix; + # TODO: consolidate with mkColmenaHost # Create a nixosConfiguration based on a foldername (nixname) and if the host is an LXC container or a VM. mkConfig = { hostname, profile ? hostname, lxc ? true, ... }: { "${profile}" = lib.nixosSystem { @@ -49,79 +46,53 @@ }; }; - # Same as above, but for the nodes part of deploy. - mkDeploy = { ip, hostname, profile ? hostname, ... }: { + # Import all nixos host definitions that are actual nix machines + nixHosts = filter ({ nix ? true, ... }: nix) hosts; + + mkColmenaHost = { ip, hostname, profile ? hostname, lxc ? true, ... }: { "${hostname}" = { - hostname = ip; - fastConnection = true; - profiles.system = { - user = "root"; - path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.${profile}; + imports = [ + vault-secrets.nixosModules.vault-secrets + ./nixos/common + "${./.}/nixos/hosts/${profile}/configuration.nix" + ] ++ (if lxc then [ + "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" + ./nixos/common/generic-lxc.nix + ] else [ ./nixos/common/generic-vm.nix ]); + + deployment = { + targetHost = ip; + targetUser = null; # Defaults to $USER }; }; }; - # Generates hosts.auto.tfvars.json for Terraform - genTFVars = - let - hostToVar = z@{ hostname, mac, ... }: { - "${hostname}" = { inherit mac; }; - }; - hostSet = lib.foldr (el: acc: acc // hostToVar el) { } hosts; - json = builtins.toJSON { hosts = hostSet; }; - in - pkgs.writeScriptBin "gen-tf-vars" '' - echo '${json}' | ${pkgs.jq}/bin/jq > terraform/hosts.auto.tfvars.json; - echo "Generated Terraform Variables"; - ''; - - # Import all nixos host definitions that are actual nix machines - nixHosts = filter ({ nix ? true, ... }: nix) hosts; - pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system} [ vault-secrets.overlay ]; in { # Make the config and deploy sets - # nixosConfigurations = lib.foldr (el: acc: acc // mkConfig el) { } nixHosts; - # deploy.nodes = lib.foldr (el: acc: acc // mkDeploy el) { } nixHosts; + nixosConfigurations = lib.foldr (el: acc: acc // mkConfig el) { } nixHosts; - colmena = { - meta = { - nixpkgs = import nixpkgs { - system = "x86_64-linux"; - overlays = [ - (import ./nixos/pkgs) - minecraft-servers.overlays.default - ]; + colmena = lib.foldr (el: acc: acc // mkColmenaHost el) + { + meta = { + nixpkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ + (import ./nixos/pkgs) + vault-secrets.overlay + minecraft-servers.overlays.default + ]; + }; specialArgs = { inherit hosts; }; }; - }; - - minecraft = { - imports = [ - vault-secrets.nixosModules.vault-secrets - ./nixos/common - "${./.}/nixos/hosts/minecraft/configuration.nix" - "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" - ./nixos/common/generic-lxc.nix - ]; - deployment = { - targetHost = "10.42.42.21"; - targetUser = "victor"; - }; - }; - }; - + } + nixHosts; apps.${system} = rec { - default = deploy; - deploy = { - type = "app"; - program = "${deploy-rs.packages.${system}.deploy-rs}/bin/deploy"; - }; vault-push-approles = { type = "app"; program = "${pkgs.vault-push-approles self}/bin/vault-push-approles"; @@ -131,10 +102,6 @@ program = "${pkgs.vault-push-approle-envs self}/bin/vault-push-approle-envs"; }; - tfvars = { - type = "app"; - program = "${genTFVars}/bin/gen-tf-vars"; - }; }; # Use by running `nix develop` @@ -144,7 +111,6 @@ shellHook = "zsh; exit $?"; buildInputs = with pkgs; [ colmena - deploy-rs.packages.${system}.deploy-rs fluxcd k9s kubectl @@ -153,17 +119,7 @@ nixfmt nixUnstable vault - # (vault-push-approles self { }) - # (vault-push-approle-envs self { }) - genTFVars ]; }; - - # Filter out non-system checks: https://github.com/NixOS/nixpkgs/issues/175875#issuecomment-1152996862 - checks = lib.filterAttrs - (a: _: a == system) - (builtins.mapAttrs - (system: deployLib: deployLib.deployChecks self.deploy) - deploy-rs.lib); }; }