colmena + multi location #64
2 changed files with 80 additions and 114 deletions
86
flake.lock
86
flake.lock
|
@ -26,23 +26,20 @@
|
||||||
"deploy-rs": {
|
"deploy-rs": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat_2",
|
"flake-compat": "flake-compat_2",
|
||||||
"nixpkgs": [
|
"nixpkgs": "nixpkgs_2",
|
||||||
"nixpkgs"
|
"utils": "utils_3"
|
||||||
],
|
|
||||||
"utils": "utils_2"
|
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1653594315,
|
"lastModified": 1648475189,
|
||||||
"narHash": "sha256-kJ0ENmnQJ4qL2FeYKZba9kvv1KmIuB3NVpBwMeI7AJQ=",
|
"narHash": "sha256-gAGAS6IagwoUr1B0ohE3iR6sZ8hP4LSqzYLC8Mq3WGU=",
|
||||||
"owner": "serokell",
|
"owner": "serokell",
|
||||||
"repo": "deploy-rs",
|
"repo": "deploy-rs",
|
||||||
"rev": "184349d8149436748986d1bdba087e4149e9c160",
|
"rev": "83e0c78291cd08cb827ba0d553ad9158ae5a95c3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "serokell",
|
"id": "deploy-rs",
|
||||||
"repo": "deploy-rs",
|
"type": "indirect"
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-compat": {
|
"flake-compat": {
|
||||||
|
@ -203,7 +200,7 @@
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"utils": "utils_3"
|
"utils": "utils_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1659144434,
|
"lastModified": 1659144434,
|
||||||
|
@ -222,7 +219,7 @@
|
||||||
"nix": {
|
"nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"lowdown-src": "lowdown-src",
|
"lowdown-src": "lowdown-src",
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1633098935,
|
"lastModified": 1633098935,
|
||||||
|
@ -240,7 +237,7 @@
|
||||||
"nix_2": {
|
"nix_2": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"lowdown-src": "lowdown-src_2",
|
"lowdown-src": "lowdown-src_2",
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_4"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1633098935,
|
"lastModified": 1633098935,
|
||||||
|
@ -273,17 +270,18 @@
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1632864508,
|
"lastModified": 1648219316,
|
||||||
"narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=",
|
"narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "82891b5e2c2359d7e58d08849e4c89511ab94234",
|
"rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-21.05-small",
|
"ref": "nixpkgs-unstable",
|
||||||
"type": "indirect"
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_3": {
|
"nixpkgs_3": {
|
||||||
|
@ -301,10 +299,24 @@
|
||||||
"type": "indirect"
|
"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": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"colmena": "colmena",
|
"colmena": "colmena",
|
||||||
"deploy-rs": "deploy-rs",
|
|
||||||
"minecraft-servers": "minecraft-servers",
|
"minecraft-servers": "minecraft-servers",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"serokell-nix": "serokell-nix",
|
"serokell-nix": "serokell-nix",
|
||||||
|
@ -313,9 +325,7 @@
|
||||||
},
|
},
|
||||||
"serokell-nix": {
|
"serokell-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"deploy-rs": [
|
"deploy-rs": "deploy-rs",
|
||||||
"deploy-rs"
|
|
||||||
],
|
|
||||||
"flake-compat": "flake-compat_3",
|
"flake-compat": "flake-compat_3",
|
||||||
"flake-utils": "flake-utils_2",
|
"flake-utils": "flake-utils_2",
|
||||||
"gitignore-nix": "gitignore-nix",
|
"gitignore-nix": "gitignore-nix",
|
||||||
|
@ -370,21 +380,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"utils_2": {
|
"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": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils"
|
"flake-utils": "flake-utils"
|
||||||
},
|
},
|
||||||
|
@ -402,6 +397,21 @@
|
||||||
"type": "github"
|
"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": {
|
"vault-secrets": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat_4",
|
"flake-compat": "flake-compat_4",
|
||||||
|
|
98
flake.nix
98
flake.nix
|
@ -8,15 +8,11 @@
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
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.url = "github:zhaofengli/colmena";
|
||||||
colmena.inputs.nixpkgs.follows = "nixpkgs";
|
colmena.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
serokell-nix.url = "github:serokell/serokell.nix";
|
serokell-nix.url = "github:serokell/serokell.nix";
|
||||||
serokell-nix.inputs.nixpkgs.follows = "nixpkgs";
|
serokell-nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
serokell-nix.inputs.deploy-rs.follows = "deploy-rs";
|
|
||||||
|
|
||||||
vault-secrets.url = "github:serokell/vault-secrets";
|
vault-secrets.url = "github:serokell/vault-secrets";
|
||||||
vault-secrets.inputs.nixpkgs.follows = "nixpkgs";
|
vault-secrets.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
@ -26,13 +22,14 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ self, nixpkgs, deploy-rs, vault-secrets, serokell-nix, minecraft-servers, ... }@inputs:
|
{ self, nixpkgs, vault-secrets, serokell-nix, minecraft-servers, ... }@inputs:
|
||||||
let
|
let
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
inherit (builtins) filter mapAttrs;
|
inherit (builtins) filter mapAttrs;
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
hosts = import ./hosts.nix;
|
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.
|
# 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, ... }: {
|
mkConfig = { hostname, profile ? hostname, lxc ? true, ... }: {
|
||||||
"${profile}" = lib.nixosSystem {
|
"${profile}" = lib.nixosSystem {
|
||||||
|
@ -49,79 +46,53 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Same as above, but for the nodes part of deploy.
|
|
||||||
mkDeploy = { ip, hostname, profile ? hostname, ... }: {
|
|
||||||
"${hostname}" = {
|
|
||||||
hostname = ip;
|
|
||||||
fastConnection = true;
|
|
||||||
profiles.system = {
|
|
||||||
user = "root";
|
|
||||||
path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.${profile};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# 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
|
# Import all nixos host definitions that are actual nix machines
|
||||||
nixHosts = filter ({ nix ? true, ... }: nix) hosts;
|
nixHosts = filter ({ nix ? true, ... }: nix) hosts;
|
||||||
|
|
||||||
|
mkColmenaHost = { ip, hostname, profile ? hostname, lxc ? true, ... }: {
|
||||||
|
"${hostname}" = {
|
||||||
|
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
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system} [ vault-secrets.overlay ];
|
pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system} [ vault-secrets.overlay ];
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Make the config and deploy sets
|
# Make the config and deploy sets
|
||||||
# nixosConfigurations = lib.foldr (el: acc: acc // mkConfig el) { } nixHosts;
|
nixosConfigurations = lib.foldr (el: acc: acc // mkConfig el) { } nixHosts;
|
||||||
# deploy.nodes = lib.foldr (el: acc: acc // mkDeploy el) { } nixHosts;
|
|
||||||
|
|
||||||
colmena = {
|
colmena = lib.foldr (el: acc: acc // mkColmenaHost el)
|
||||||
|
{
|
||||||
meta = {
|
meta = {
|
||||||
nixpkgs = import nixpkgs {
|
nixpkgs = import nixpkgs {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
overlays = [
|
overlays = [
|
||||||
(import ./nixos/pkgs)
|
(import ./nixos/pkgs)
|
||||||
|
vault-secrets.overlay
|
||||||
minecraft-servers.overlays.default
|
minecraft-servers.overlays.default
|
||||||
];
|
];
|
||||||
|
};
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit hosts;
|
inherit hosts;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
nixHosts;
|
||||||
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";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
apps.${system} = rec {
|
apps.${system} = rec {
|
||||||
default = deploy;
|
|
||||||
deploy = {
|
|
||||||
type = "app";
|
|
||||||
program = "${deploy-rs.packages.${system}.deploy-rs}/bin/deploy";
|
|
||||||
};
|
|
||||||
vault-push-approles = {
|
vault-push-approles = {
|
||||||
type = "app";
|
type = "app";
|
||||||
program = "${pkgs.vault-push-approles self}/bin/vault-push-approles";
|
program = "${pkgs.vault-push-approles self}/bin/vault-push-approles";
|
||||||
|
@ -131,10 +102,6 @@
|
||||||
program =
|
program =
|
||||||
"${pkgs.vault-push-approle-envs self}/bin/vault-push-approle-envs";
|
"${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`
|
# Use by running `nix develop`
|
||||||
|
@ -144,7 +111,6 @@
|
||||||
shellHook = "zsh; exit $?";
|
shellHook = "zsh; exit $?";
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
colmena
|
colmena
|
||||||
deploy-rs.packages.${system}.deploy-rs
|
|
||||||
fluxcd
|
fluxcd
|
||||||
k9s
|
k9s
|
||||||
kubectl
|
kubectl
|
||||||
|
@ -153,17 +119,7 @@
|
||||||
nixfmt
|
nixfmt
|
||||||
nixUnstable
|
nixUnstable
|
||||||
vault
|
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);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue