nixos-config/nixos/krops.nix

117 lines
2.8 KiB
Nix
Raw Normal View History

2021-09-25 20:28:25 +02:00
{ pkgs, writeCommand, lib, secrets }:
let
# command that ensures we use flake.nix during switch
command = targetPath:
let
commandLine =
2021-10-31 17:49:44 +01:00
"TMPDIR=/tmp nixos-rebuild build --flake ${targetPath} -L --keep-going";
2021-09-25 20:28:25 +02:00
in ''
echo '${commandLine}'
nix-shell \
-E "with import <nixpkgs> {}; mkShell { buildInputs = [ git (nixos { nix.package = nixFlakes; }).nixos-rebuild ]; }" \
--run '${commandLine}'
'';
source = {
2021-10-26 07:54:50 +02:00
secrets.file = {
path = "${secrets}/secrets";
useChecksum = true;
};
2021-09-25 20:28:25 +02:00
private_assets.pass = {
dir = toString ~/.password-store;
name = "krops/private_assets";
};
2021-10-26 07:54:50 +02:00
assets.file = {
path = toString ./assets;
useChecksum = true;
};
configs.file = {
path = toString ./configs;
useChecksum = true;
};
library.file = {
path = toString ./library;
useChecksum = true;
};
modules.file = {
path = toString ./modules;
useChecksum = true;
};
pkgs.file = {
path = toString ./pkgs;
useChecksum = true;
};
system.file = {
path = toString ./system;
useChecksum = true;
};
"flake.nix".file = {
path = toString ./flake.nix;
useChecksum = true;
};
"flake.lock".file = {
path = toString ./flake.lock;
useChecksum = true;
};
2021-09-25 20:28:25 +02:00
};
2021-09-25 20:30:49 +02:00
server = { name, host }:
let
system = writeCommand "/bin/system" {
source = lib.evalSource [ source ];
force = true;
target = lib.mkTarget "root@${host}/var/krops";
inherit command;
};
in {
"${name}" = pkgs.writers.writeBashBin name ''
echo "deploy system"
${system}/bin/system
'';
};
2021-09-25 20:28:25 +02:00
desktop = { name, host }:
let
system = writeCommand "/bin/system" {
source = lib.evalSource [ source ];
force = true;
target = lib.mkTarget "root@${host}/var/krops";
inherit command;
};
network = writeCommand "/bin/secrets" {
source = lib.evalSource [{
system-connections.pass = {
dir = toString ~/.password-store;
name = "krops/desktop_secrets/network-manager/system-connections";
};
}];
force = true;
target = lib.mkTarget "root@${host}/etc/NetworkManager";
};
in {
2021-09-26 10:18:18 +02:00
"${name}" = pkgs.writers.writeBashBin "${name}-all" ''
2021-09-25 20:28:25 +02:00
echo "deploy network secerts"
${network}/bin/secrets
echo "deploy system"
${system}/bin/system
'';
};
2021-09-25 20:30:49 +02:00
in (desktop {
name = "sterni";
host = "sterni.private";
2021-09-25 20:32:19 +02:00
}) // (desktop {
name = "sternchen";
host = "sternchen.secret";
2021-09-25 20:30:49 +02:00
}) // (server {
name = "pepe";
host = "pepe.private";
}) // (server {
name = "workhorse";
host = "workhorse.private";
}) // (server {
name = "sputnik";
host = "sputnik.private";
})