Move to using flake nixos config

This commit is contained in:
2021-11-18 11:49:04 -08:00
parent 381d2710e3
commit d8322b2d10
13 changed files with 134 additions and 129 deletions

69
common/deployment.nix Normal file
View File

@@ -0,0 +1,69 @@
{ hostnames, description, ... }:
{ self, nixpkgs, fudo-home, fudo-nixos, fudo-pkgs, fudo-secrets, ... }:
with nixpkgs.lib;
let
build-timestamp = self.sourceInfo.lastModified;
helpers = import ./helpers.nix { lib = nixpkgs.lib; };
networks = with nixpkgs.lib; let
network-files = helpers.nix-files (fudo-nixos + /config/networks);
networks = map helpers.strip-ext network-files;
in genAttrs networks
(network: import (fudo-nixos + /config/networks/${network}.nix));
hosts = with nixpkgs.lib; let
in genAttrs hostnames
(hostname: import (fudo-nixos + /config/hosts/${host}.nix));
pkgs-for = system: import nixpkgs {
inherit system;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"openssh-with-gssapi-8.4p1"
];
overlays = [
(import (fudo-pkgs + /overlay.nix))
(import (fudo-nixos + /lib/overlay.nix))
];
};
};
in {
nixopsConfigurations.default = {
inherit nixpkgs;
network = {
inherit description;
enableRollback = true;
};
} // (genAttrs hostnames (hostname: let
host-cfg = hosts.${hostname}
pkgs = pkgs-for host-cfg.arch;
domain = host-cfg.domain;
network-hosts = config.fudo.networks.${network}.hosts;
host-filesystem-keys = config.fudo.secrets.files.host-filesystem-keys;
in {config, ... }: {
nixpkgs.pkgs = pkgs;
imports = [
fudo-home.nixModule
fudo-secrets.nixModule
fudo-nixos.nixosConfigurations.${hostname}
];
deployment = {
targetHost = network-hosts.${hostname}.ipv4-address;
keys = mkIf (hasAttr hostname host-filesystem-keys)
(mapAttrs (secret: secret-file: {
keyFile = secret-file;
user = "root";
permissions = "0400";
}) host-filesystem-keys.${hostname});
};
}));
}

27
common/helpers.nix Normal file
View File

@@ -0,0 +1,27 @@
{ lib, ... }:
with lib;
let
regular-files = path: let
is-regular-file = filename: type: type == "regular" || type == "link";
in attrNames (filterAttrs is-regular-file (builtins.readDir path));
nix-files = path: let
is-nix-file = filename: (builtins.match "^(.+)\.nix$" filename) != null;
in
map
(file: path + "/${file}")
(filter is-nix-file (regular-files path));
strip-ext = filename: head (builtins.match "^(.+)[.]nix$" filename);
basename-to-map = path:
listToAttrs
(map
(file:
nameValuePair (strip-ext file)
(import (path + "${file}")))
(nix-files path));
in {
inherit regular-files nix-files strip-ext basename-to-map;
}

19
common/inputs.nix Normal file
View File

@@ -0,0 +1,19 @@
{ nixos-version, ... }:
{
nixpkgs.url = "nixpkgs/nixos-${nixos-version}";
fudo-home = {
url = "git+https://git.fudo.org/niten/nix-home.git?ref=flake";
inputs.nixpkgs.follows = "nixpkgs";
};
fudo-secrets.url = "path:/state/secrets";
fudo-pkgs.url = "git+https://git.fudo.org/fudo-public/fudo-pkgs.git";
fudo-nixos = {
url = "git+ssh://fudo_git@git.fudo.org:2222/fudosys/NixOS.git?ref=nixops-flake";
inputs.nixpkgs.follows = "nixpkgs";
};
}