From 88f25b5f478a966d33e09e284c5ee59cc54fbd54 Mon Sep 17 00:00:00 2001 From: niten Date: Fri, 19 Nov 2021 22:30:51 -0800 Subject: [PATCH] Sigh. Still trying. --- common/deployment-config.nix | 12 ++------ common/deployment.nix | 46 +++++++++++------------------ deployments/seattle/flake.lock | 2 +- deployments/seattle/flake.nix | 32 +++++++++++++------- deployments/seattle/host-config.nix | 41 +++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 deployments/seattle/host-config.nix diff --git a/common/deployment-config.nix b/common/deployment-config.nix index c57bf85..5ecf30d 100644 --- a/common/deployment-config.nix +++ b/common/deployment-config.nix @@ -1,6 +1,4 @@ -{ build-timestamp, networks, pkgs-for }: - -hostname: hostOpts: +build-timestamp: hostname: { config, lib, ... }: @@ -11,21 +9,15 @@ with lib; inherit build-timestamp; }; - nixpkgs.pkgs = pkgs-for hostOpts.arch; - deployment = let - domain = hostOpts.domain; - host-ip = networks.${domain}.hosts.${hostname}.ipv4-address; fs-keys = config.fudo.secrets.files.host-filesystem-keys; + in { keys = if (hasAttr hostname fs-keys) then mapAttrs (secret: secret-file: { keyFile = secret-file; user = "root"; permissions = "0400"; }) fs-keys.${hostname} else {}; - in { - inherit keys; - targetHost = host-ip; }; }; } diff --git a/common/deployment.nix b/common/deployment.nix index 398a612..591da6c 100644 --- a/common/deployment.nix +++ b/common/deployment.nix @@ -1,19 +1,7 @@ -{ deployment-hosts, description, ... }: +lib: build-timestamp: hostname: hostOpts: -{ self, nixpkgs, fudo-nixos, fudo-secrets, ... }: -with nixpkgs.lib; +with lib; let - - build-timestamp = self.sourceInfo.lastModified; - - # helpers = import ./helpers.nix { lib = nixpkgs.lib; }; - - # syslib = import (fudo-nixos + /lib/system.nix) { lib = nixpkgs.lib; }; - - # networks = syslib.networks (fudo-nixos + /config/networks); - - # deployment-hosts = getAttrs hostnames fudo-nixos.fudoHosts; - pkgs-for = system: import nixpkgs { inherit system; config = { @@ -28,22 +16,22 @@ let }; }; - host-config = let - networks = fudo-nixos.fudoNetworks; - in import ./deployment-config.nix { - inherit build-timestamp networks pkgs-for; - }; +in fudo-nixos.nixosConfigurations.${hostname} { -in { - inherit nixpkgs; +} // mapAttrs (hostname: hostOpts: let + pkgs = pkgs-for hostOpts.arch; + host-ip = networks.${hostOpts.domain}.hosts.${hostname}.ipv4-address; +in fudo-nixos.nixosConfigurations.${hostname} // { - network = { - inherit description; - enableRollback = true; + config = { + nixpkgs.pkgs = pkgs; + + imports = [ + (host-config hostname) + ]; + + instance = { inherit hostname; }; + + deployment.targetHost = host-ip; }; -} // mapAttrs (hostname: hostOpts: { - imports = [ - (host-config hostname hostOpts) - fudo-nixos.nixosConfigurations.${hostname} - ]; }) deployment-hosts diff --git a/deployments/seattle/flake.lock b/deployments/seattle/flake.lock index 4826586..e2f18e8 100644 --- a/deployments/seattle/flake.lock +++ b/deployments/seattle/flake.lock @@ -303,7 +303,7 @@ ] }, "locked": { - "narHash": "sha256-B2M99aciJcFkAfyNk5c0KXMc3wtfUxDZuBM8xeaYzes=", + "narHash": "sha256-1Z8ZrVFDTq9ohhYwD7Ti4KFYLgnRZG58OHvAQQAKZOU=", "path": "/state/nixops/fudo-nixos", "type": "path" }, diff --git a/deployments/seattle/flake.nix b/deployments/seattle/flake.nix index bc56956..331577d 100644 --- a/deployments/seattle/flake.nix +++ b/deployments/seattle/flake.nix @@ -13,17 +13,27 @@ }; }; - outputs = { self, nixpkgs, fudo-nixos, ... } @ inputs: with nixpkgs.lib; - let - deployment = import ../../common/deployment.nix { - description = "Seattle NixOps network"; - deployment-hosts = let - domain = "sea.fudo.org"; - in filterAttrs - (hostname: hostOpts: hostOpts.domain == domain) + outputs = { self, nixpkgs, fudo-nixos, fudo-secrets, ... } @ inputs: + with nixpkgs.lib; { + nixopsConfigurations.default = let + deployment-hosts = filterAttrs + (hostname: hostOpts: hostOpts.domain == "sea.fudo.org") fudo-nixos.fudoHosts; - }; - in { - nixopsConfigurations.default = (deployment inputs); + + build-timestamp = self.sourceInfo.lastModified; + + host-gen-config = import ./host-config.nix { + inherit inputs build-timestamp; + }; + + host-configs = mapAttrs host-gen-config deployment-hosts; + in { + inherit nixpkgs; + + network = { + description = "Seattle NixOps network"; + enableRollback = true; + }; + } // host-configs; }; } diff --git a/deployments/seattle/host-config.nix b/deployments/seattle/host-config.nix new file mode 100644 index 0000000..6f42bca --- /dev/null +++ b/deployments/seattle/host-config.nix @@ -0,0 +1,41 @@ +inputs: build-timestamp: hostname: hostOpts: + +{ config, ... }: + +let + pkgs-for = system: import inputs.nixpkgs { + inherit system; + config = { + allowUnfree = true; + permittedInsecurePackages = [ + "openssh-with-gssapi-8.4p1" + ]; + overlays = [ + (import (inputs.fudo-pkgs + /overlay.nix)) + (import (inputs.fudo-nixos + /lib/overlay.nix)) + ]; + }; + }; + + host-ip = hostname: + inputs.fudo-nixos.fudoNetworks.${hostOpts.domain}.hosts.${hostname}.ipv4-address; + + +in { + config = { + nixpkgs.pkgs = pkgs-for hostOpts.arch; + + imports = [ + inputs.fudo-nixos.nixosModule + inputs.fudo-secrets.nixosModule + ]; + + instance = { + inherit hostname build-timestamp; + }; + + deployments = { + targetHost = host-ip hostname; + }; + }; +}