Format repo

This commit is contained in:
Pim Kunis 2024-10-28 14:12:06 +01:00
parent eed797fb13
commit 5341235bc3
21 changed files with 1200 additions and 1076 deletions

View file

@ -1,26 +1,26 @@
{ self, deploy-rs, ... }: {
let self,
deploy-rs,
...
}: let
deployArch = "x86_64-linux"; deployArch = "x86_64-linux";
mkDeployNodes = nodeDef: mkDeployNodes = nodeDef:
builtins.mapAttrs builtins.mapAttrs
(name: machine: nodeDef name machine) (name: machine: nodeDef name machine)
self.machines.${deployArch}; self.machines.${deployArch};
in in {
{
deploy = { deploy = {
sshUser = "root"; sshUser = "root";
user = "root"; user = "root";
nodes = mkDeployNodes (name: machine: nodes = mkDeployNodes (name: machine: let
let nixosConfiguration = self.nixosConfigurations.${name};
nixosConfiguration = self.nixosConfigurations.${name}; in {
in hostname = nixosConfiguration.config.networking.fqdn;
{ profiles.system = {
hostname = nixosConfiguration.config.networking.fqdn; remoteBuild = machine.arch != deployArch;
profiles.system = { path = deploy-rs.lib.${machine.arch}.activate.nixos nixosConfiguration;
remoteBuild = machine.arch != deployArch; };
path = deploy-rs.lib.${machine.arch}.activate.nixos nixosConfiguration; });
};
});
}; };
} }

View file

@ -109,6 +109,22 @@
"type": "github" "type": "github"
} }
}, },
"flake-compat_4": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": [
@ -163,6 +179,27 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"kubenix": { "kubenix": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_2",
@ -262,6 +299,22 @@
} }
}, },
"nixpkgs-stable": { "nixpkgs-stable": {
"locked": {
"lastModified": 1720386169,
"narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "194846768975b7ad2c4988bdb82572c00222c0d7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable_2": {
"locked": { "locked": {
"lastModified": 1729357638, "lastModified": 1729357638,
"narHash": "sha256-66RHecx+zohbZwJVEPF7uuwHeqf8rykZTMCTqIrOew4=", "narHash": "sha256-66RHecx+zohbZwJVEPF7uuwHeqf8rykZTMCTqIrOew4=",
@ -309,6 +362,45 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_3": {
"locked": {
"lastModified": 1726871744,
"narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat_4",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs-unstable"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1729104314,
"narHash": "sha256-pZRZsq5oCdJt3upZIU4aslS9XwFJ+/nVtALHIciX/BI=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "3c3e88f0f544d6bb54329832616af7eb971b6be6",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"deploy-rs": "deploy-rs", "deploy-rs": "deploy-rs",
@ -321,7 +413,9 @@
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs_2",
"nixpkgs-unstable": "nixpkgs-unstable", "nixpkgs-unstable": "nixpkgs-unstable",
"sops-nix": "sops-nix" "pre-commit-hooks": "pre-commit-hooks",
"sops-nix": "sops-nix",
"treefmt-nix": "treefmt-nix"
} }
}, },
"sops-nix": { "sops-nix": {
@ -329,7 +423,7 @@
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable_2"
}, },
"locked": { "locked": {
"lastModified": 1729775275, "lastModified": 1729775275,
@ -410,6 +504,24 @@
"type": "github" "type": "github"
} }
}, },
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1730025913,
"narHash": "sha256-Y9NtFmP8ciLyRsopcCx1tyoaaStKeq+EndwtGCgww7I=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "bae131e525cc8718da22fbeb8d8c7c43c4ea502a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"utils": { "utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"

View file

@ -55,8 +55,11 @@
}; };
}; };
outputs = outputs = inputs @ {
inputs@{ nixpkgs, flake-utils, ... }: nixpkgs,
flake-utils,
...
}:
flake-utils.lib.meld inputs [ flake-utils.lib.meld inputs [
./scripts ./scripts
./deploy.nix ./deploy.nix

View file

@ -1,9 +1,14 @@
{ nixpkgs, treefmt-nix, flake-utils, ...}: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{ {
formatter = treefmtEval.config.build.wrapper; nixpkgs,
} treefmt-nix,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in {
formatter = treefmtEval.config.build.wrapper;
}
) )

View file

@ -1,9 +1,13 @@
{ nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: {
let nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib; lib = pkgs.lib;
machineOpts = { config, ... }: { machineOpts = {config, ...}: {
options = { options = {
arch = lib.mkOption { arch = lib.mkOption {
default = null; default = null;
@ -19,7 +23,7 @@ let
}; };
nixosModule = lib.mkOption { nixosModule = lib.mkOption {
default = { ... }: { }; default = {...}: {};
type = lib.types.anything; type = lib.types.anything;
description = '' description = ''
Customized configuration for this machine in the form of a NixOS module. Customized configuration for this machine in the form of a NixOS module.
@ -43,17 +47,19 @@ let
}; };
}; };
}; };
in in {
{ machines =
machines = (lib.modules.evalModules { (lib.modules.evalModules {
modules = [ modules = [
allOpts allOpts
./warwick.nix ./warwick.nix
./atlas.nix ./atlas.nix
./jefke.nix ./jefke.nix
./lewis.nix ./lewis.nix
# ./talos.nix # ./talos.nix
# ./pikvm.nix # ./pikvm.nix
]; ];
}).config.machines; })
.config
.machines;
}) })

View file

@ -3,7 +3,12 @@
arch = "aarch64-linux"; arch = "aarch64-linux";
isRaspberryPi = true; isRaspberryPi = true;
nixosModule = { config, inputs, lib, ... }: { nixosModule = {
config,
inputs,
lib,
...
}: {
# imports = [ "${inputs.nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" ]; # imports = [ "${inputs.nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" ];
lab = { lab = {
storage.profile = "pi"; storage.profile = "pi";
@ -17,7 +22,7 @@
v4l-utils v4l-utils
]; ];
boot.extraModulePackages = with config.boot.kernelPackages; [ v4l2loopback ]; boot.extraModulePackages = with config.boot.kernelPackages; [v4l2loopback];
}; };
}; };
} }

View file

@ -2,7 +2,7 @@
machines.talos = { machines.talos = {
arch = "x86_64-linux"; arch = "x86_64-linux";
nixosModule = { lib, ... }: { nixosModule = {lib, ...}: {
lab.storage.profile = "normal"; lab.storage.profile = "normal";
# boot.loader.systemd-boot.enable = lib.mkForce false; # boot.loader.systemd-boot.enable = lib.mkForce false;

View file

@ -1,12 +1,16 @@
{ pkgs, lib, config, ... }: {
let pkgs,
lib,
config,
...
}: let
cfg = config.lab.backups; cfg = config.lab.backups;
borgmaticConfig = pkgs.writeTextFile { borgmaticConfig = pkgs.writeTextFile {
name = "borgmatic-config.yaml"; name = "borgmatic-config.yaml";
text = lib.generators.toYAML { } { text = lib.generators.toYAML {} {
source_directories = [ "/mnt/longhorn/persistent/longhorn-backup" ]; source_directories = ["/mnt/longhorn/persistent/longhorn-backup"];
repositories = [ repositories = [
{ {
@ -27,8 +31,7 @@ let
encryption_passcommand = "${pkgs.coreutils}/bin/cat ${config.sops.secrets."borg/borgPassphrase".path}"; encryption_passcommand = "${pkgs.coreutils}/bin/cat ${config.sops.secrets."borg/borgPassphrase".path}";
}; };
}; };
in in {
{
options.lab.backups = { options.lab.backups = {
enable = lib.mkOption { enable = lib.mkOption {
default = false; default = false;
@ -48,13 +51,13 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = with pkgs; [ borgbackup ]; environment.systemPackages = with pkgs; [borgbackup];
# Converted from: # Converted from:
# https://github.com/borgmatic-collective/borgmatic/tree/84823dfb912db650936e3492f6ead7e0e0d32a0f/sample/systemd # https://github.com/borgmatic-collective/borgmatic/tree/84823dfb912db650936e3492f6ead7e0e0d32a0f/sample/systemd
systemd.services.borgmatic = { systemd.services.borgmatic = {
description = "borgmatic backup"; description = "borgmatic backup";
wants = [ "network-online.target" ]; wants = ["network-online.target"];
after = [ "network-online.target" ]; after = ["network-online.target"];
unitConfig.ConditionACPower = true; unitConfig.ConditionACPower = true;
preStart = "${pkgs.coreutils}/bin/sleep 10s"; preStart = "${pkgs.coreutils}/bin/sleep 10s";
@ -75,7 +78,7 @@ in
systemd.timers.borgmatic = { systemd.timers.borgmatic = {
description = "Run borgmatic backup"; description = "Run borgmatic backup";
wantedBy = [ "timers.target" ]; wantedBy = ["timers.target"];
timerConfig = { timerConfig = {
OnCalendar = "*-*-* 3:00:00"; OnCalendar = "*-*-* 3:00:00";
Persistent = true; Persistent = true;
@ -84,8 +87,8 @@ in
}; };
sops.secrets = { sops.secrets = {
"borg/borgPassphrase" = { }; "borg/borgPassphrase" = {};
"borg/borgbasePrivateKey" = { }; "borg/borgbasePrivateKey" = {};
}; };
}; };
} }

View file

@ -1,5 +1,8 @@
{ lib, config, ... }: {
let lib,
config,
...
}: let
cfg = config.lab.data-sharing; cfg = config.lab.data-sharing;
nfsShares = [ nfsShares = [
@ -13,13 +16,12 @@ let
nfsExports = lib.strings.concatLines ( nfsExports = lib.strings.concatLines (
builtins.map builtins.map
(share: (
"${share} 192.168.30.0/16(rw,sync,no_subtree_check,no_root_squash) 127.0.0.1/8(rw,sync,no_subtree_check,no_root_squash) 10.0.0.0/8(rw,sync,no_subtree_check,no_root_squash)" share: "${share} 192.168.30.0/16(rw,sync,no_subtree_check,no_root_squash) 127.0.0.1/8(rw,sync,no_subtree_check,no_root_squash) 10.0.0.0/8(rw,sync,no_subtree_check,no_root_squash)"
) )
nfsShares nfsShares
); );
in in {
{
options.lab.data-sharing = { options.lab.data-sharing = {
enable = lib.mkOption { enable = lib.mkOption {
default = false; default = false;

View file

@ -1,17 +1,27 @@
{ self, pkgs, config, lib, inputs, machine, ... }: { {
imports = [ self,
./storage.nix pkgs,
./backups.nix config,
./networking lib,
./data-sharing.nix inputs,
./monitoring machine,
./k3s ...
./tailscale.nix }: {
machine.nixosModule imports =
inputs.disko.nixosModules.disko [
inputs.sops-nix.nixosModules.sops ./storage.nix
inputs.nix-snapshotter.nixosModules.nix-snapshotter ./backups.nix
] ++ lib.lists.optional (machine.isRaspberryPi) inputs.nixos-hardware.nixosModules.raspberry-pi-4; ./networking
./data-sharing.nix
./monitoring
./k3s
./tailscale.nix
machine.nixosModule
inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops
inputs.nix-snapshotter.nixosModules.nix-snapshotter
]
++ lib.lists.optional (machine.isRaspberryPi) inputs.nixos-hardware.nixosModules.raspberry-pi-4;
config = { config = {
time.timeZone = "Europe/Amsterdam"; time.timeZone = "Europe/Amsterdam";
@ -31,7 +41,9 @@
i18n = { i18n = {
defaultLocale = "en_US.UTF-8"; defaultLocale = "en_US.UTF-8";
extraLocaleSettings = let extraLocale = "nl_NL.UTF-8"; in { extraLocaleSettings = let
extraLocale = "nl_NL.UTF-8";
in {
LC_ADDRESS = extraLocale; LC_ADDRESS = extraLocale;
LC_IDENTIFICATION = extraLocale; LC_IDENTIFICATION = extraLocale;
LC_MEASUREMENT = extraLocale; LC_MEASUREMENT = extraLocale;
@ -97,12 +109,12 @@
]; ];
boot = lib.mkIf (! machine.isRaspberryPi) { boot = lib.mkIf (! machine.isRaspberryPi) {
kernelModules = [ "kvm-intel" ]; kernelModules = ["kvm-intel"];
extraModulePackages = [ ]; extraModulePackages = [];
kernel.sysctl."fs.inotify.max_user_instances" = 256; kernel.sysctl."fs.inotify.max_user_instances" = 256;
initrd = { initrd = {
kernelModules = [ ]; kernelModules = [];
availableKernelModules = [ availableKernelModules = [
"ahci" "ahci"

View file

@ -1,5 +1,5 @@
{ kubenix, ... }: { {kubenix, ...}: {
imports = [ kubenix.modules.k8s ]; imports = [kubenix.modules.k8s];
kubernetes.resources.clusterRoleBindings.cluster-admins = { kubernetes.resources.clusterRoleBindings.cluster-admins = {
roleRef = { roleRef = {
apiGroup = "rbac.authorization.k8s.io"; apiGroup = "rbac.authorization.k8s.io";

View file

@ -1,8 +1,13 @@
{ self, inputs, pkgs, lib, config, ... }:
let
cfg = config.lab.k3s;
in
{ {
self,
inputs,
pkgs,
lib,
config,
...
}: let
cfg = config.lab.k3s;
in {
options.lab.k3s = { options.lab.k3s = {
enable = lib.mkOption { enable = lib.mkOption {
default = false; default = false;
@ -62,68 +67,66 @@ in
address = "/run/nix-snapshotter/nix-snapshotter.sock"; address = "/run/nix-snapshotter/nix-snapshotter.sock";
}; };
plugins = plugins = let
let k3s-cni-plugins = pkgs.buildEnv {
k3s-cni-plugins = pkgs.buildEnv { name = "k3s-cni-plugins";
name = "k3s-cni-plugins"; paths = with pkgs; [
paths = with pkgs; [ cni-plugins
cni-plugins cni-plugin-flannel
cni-plugin-flannel ];
]; };
}; in {
in "io.containerd.grpc.v1.cri" = {
{ stream_server_address = "127.0.0.1";
"io.containerd.grpc.v1.cri" = { stream_server_port = "10010";
stream_server_address = "127.0.0.1"; enable_selinux = false;
stream_server_port = "10010"; enable_unprivileged_ports = true;
enable_selinux = false; enable_unprivileged_icmp = true;
enable_unprivileged_ports = true; disable_apparmor = true;
enable_unprivileged_icmp = true; disable_cgroup = true;
disable_apparmor = true; restrict_oom_score_adj = true;
disable_cgroup = true; sandbox_image = "rancher/mirrored-pause:3.6";
restrict_oom_score_adj = true; containerd.snapshotter = "nix";
sandbox_image = "rancher/mirrored-pause:3.6";
containerd.snapshotter = "nix";
cni = { cni = {
conf_dir = "/var/lib/rancher/k3s/agent/etc/cni/net.d/"; conf_dir = "/var/lib/rancher/k3s/agent/etc/cni/net.d/";
bin_dir = "${k3s-cni-plugins}/bin"; bin_dir = "${k3s-cni-plugins}/bin";
};
}; };
};
"io.containerd.transfer.v1.local".unpack_config = [{ "io.containerd.transfer.v1.local".unpack_config = [
{
platform = "linux/amd64"; platform = "linux/amd64";
snapshotter = "nix"; snapshotter = "nix";
}]; }
}; ];
};
}; };
}; };
services = { services = {
nix-snapshotter.enable = true; nix-snapshotter.enable = true;
k3s = k3s = let
let serverFlagList = [
serverFlagList = [ "--image-service-endpoint=unix:///run/nix-snapshotter/nix-snapshotter.sock"
"--image-service-endpoint=unix:///run/nix-snapshotter/nix-snapshotter.sock" "--snapshotter=overlayfs"
"--snapshotter=overlayfs" "--container-runtime-endpoint=unix:///run/containerd/containerd.sock"
"--container-runtime-endpoint=unix:///run/containerd/containerd.sock" "--tls-san=${config.networking.fqdn}"
"--tls-san=${config.networking.fqdn}" "--disable=servicelb"
"--disable=servicelb" "--cluster-cidr=10.42.0.0/16,2001:cafe:42::/56"
"--cluster-cidr=10.42.0.0/16,2001:cafe:42::/56" "--service-cidr=10.43.0.0/16,2001:cafe:43::/112"
"--service-cidr=10.43.0.0/16,2001:cafe:43::/112" ];
];
serverFlags = builtins.concatStringsSep " " serverFlagList; serverFlags = builtins.concatStringsSep " " serverFlagList;
in in {
{ enable = true;
enable = true; role = cfg.role;
role = cfg.role; tokenFile = config.sops.secrets."k3s/serverToken".path;
tokenFile = config.sops.secrets."k3s/serverToken".path; extraFlags = lib.mkIf (cfg.role == "server") (lib.mkForce serverFlags);
extraFlags = lib.mkIf (cfg.role == "server") (lib.mkForce serverFlags); clusterInit = cfg.clusterInit;
clusterInit = cfg.clusterInit; serverAddr = lib.mkIf (! (cfg.serverAddr == null)) cfg.serverAddr;
serverAddr = lib.mkIf (! (cfg.serverAddr == null)) cfg.serverAddr; };
};
# Required for Longhorn # Required for Longhorn
openiscsi = { openiscsi = {
@ -143,11 +146,14 @@ in
k3s-bootstrap = lib.mkIf (cfg.role == "server") { k3s-bootstrap = lib.mkIf (cfg.role == "server") {
text = ( text = (
let let
k3sBootstrapFile = (inputs.kubenix.evalModules.x86_64-linux { k3sBootstrapFile =
module = import ./bootstrap.nix; (inputs.kubenix.evalModules.x86_64-linux {
}).config.kubernetes.result; module = import ./bootstrap.nix;
in })
'' .config
.kubernetes
.result;
in ''
mkdir -p /var/lib/rancher/k3s/server/manifests mkdir -p /var/lib/rancher/k3s/server/manifests
ln -sf ${k3sBootstrapFile} /var/lib/rancher/k3s/server/manifests/k3s-bootstrap.json ln -sf ${k3sBootstrapFile} /var/lib/rancher/k3s/server/manifests/k3s-bootstrap.json
'' ''
@ -166,18 +172,16 @@ in
}; };
}; };
sops.secrets = sops.secrets = let
let keyPathBase = "/var/lib/rancher/k3s/server/tls";
keyPathBase = "/var/lib/rancher/k3s/server/tls"; in {
in "k3s/serverToken" = {};
{ "k3s/keys/clientCAKey".path = "${keyPathBase}/client-ca.key";
"k3s/serverToken" = { }; "k3s/keys/requestHeaderCAKey".path = "${keyPathBase}/request-header-ca.key";
"k3s/keys/clientCAKey".path = "${keyPathBase}/client-ca.key"; "k3s/keys/serverCAKey".path = "${keyPathBase}/server-ca.key";
"k3s/keys/requestHeaderCAKey".path = "${keyPathBase}/request-header-ca.key"; "k3s/keys/serviceKey".path = "${keyPathBase}/service.key";
"k3s/keys/serverCAKey".path = "${keyPathBase}/server-ca.key"; "k3s/keys/etcd/peerCAKey".path = "${keyPathBase}/etcd/peer-ca.key";
"k3s/keys/serviceKey".path = "${keyPathBase}/service.key"; "k3s/keys/etcd/serverCAKey".path = "${keyPathBase}/etcd/server-ca.key";
"k3s/keys/etcd/peerCAKey".path = "${keyPathBase}/etcd/peer-ca.key"; };
"k3s/keys/etcd/serverCAKey".path = "${keyPathBase}/etcd/server-ca.key";
};
}; };
} }

View file

@ -1,8 +1,11 @@
{ lib, config, machines, ... }:
let
cfg = config.lab.monitoring;
in
{ {
lib,
config,
machines,
...
}: let
cfg = config.lab.monitoring;
in {
options = { options = {
lab.monitoring = { lab.monitoring = {
enable = lib.mkOption { enable = lib.mkOption {
@ -18,8 +21,9 @@ in
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ config.services.prometheus.exporters.node.port ] networking.firewall.allowedTCPPorts =
++ lib.lists.optionals cfg.server.enable [ 80 ]; [config.services.prometheus.exporters.node.port]
++ lib.lists.optionals cfg.server.enable [80];
services.prometheus = { services.prometheus = {
enable = cfg.server.enable; enable = cfg.server.enable;
@ -32,12 +36,15 @@ in
scrapeConfigs = lib.mkIf cfg.server.enable ( scrapeConfigs = lib.mkIf cfg.server.enable (
let let
generated = lib.attrsets.mapAttrsToList generated =
lib.attrsets.mapAttrsToList
(name: machine: { (name: machine: {
job_name = name; job_name = name;
static_configs = [{ static_configs = [
targets = [ "${name}.dmz:${toString config.services.prometheus.exporters.node.port}" ]; {
}]; targets = ["${name}.dmz:${toString config.services.prometheus.exporters.node.port}"];
}
];
}) })
machines; machines;
@ -53,12 +60,14 @@ in
password = "admin"; password = "admin";
}; };
static_configs = [{ static_configs = [
targets = [ "pikvm.dmz" ]; {
}]; targets = ["pikvm.dmz"];
}
];
}; };
in in
generated ++ [ pikvm ] generated ++ [pikvm]
); );
}; };

View file

@ -1,4 +1,8 @@
{ lib, machine, ... }: { {
lib,
machine,
...
}: {
config = { config = {
networking = { networking = {
domain = "dmz"; domain = "dmz";

View file

@ -1,5 +1,8 @@
{ lib, config, ... }: {
let lib,
config,
...
}: let
cfg = config.lab.storage; cfg = config.lab.storage;
modules = [ modules = [
{ {
@ -7,7 +10,7 @@ let
fileSystems."/" = { fileSystems."/" = {
device = "/dev/disk/by-label/NIXOS_SD"; device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4"; fsType = "ext4";
options = [ "noatime" ]; options = ["noatime"];
}; };
}; };
} }
@ -87,7 +90,7 @@ let
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/"; mountpoint = "/";
mountOptions = [ "defaults" ]; mountOptions = ["defaults"];
}; };
}; };
@ -145,7 +148,7 @@ let
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/"; mountpoint = "/";
mountOptions = [ "defaults" ]; mountOptions = ["defaults"];
}; };
}; };
}; };
@ -155,8 +158,7 @@ let
}; };
} }
]; ];
in in {
{
imports = modules; imports = modules;
options.lab.storage = { options.lab.storage = {

View file

@ -1,8 +1,10 @@
{ lib, config, ... }:
let
cfg = config.lab.tailscale;
in
{ {
lib,
config,
...
}: let
cfg = config.lab.tailscale;
in {
options = { options = {
lab.tailscale = { lab.tailscale = {
enable = lib.mkEnableOption "tailscale"; enable = lib.mkEnableOption "tailscale";
@ -21,15 +23,17 @@ in
useRoutingFeatures = "server"; useRoutingFeatures = "server";
openFirewall = true; openFirewall = true;
extraUpFlags = [ extraUpFlags =
"--accept-dns=false" [
"--hostname=${config.networking.hostName}" "--accept-dns=false"
] ++ lib.lists.optional cfg.advertiseExitNode "--advertise-exit-node" "--hostname=${config.networking.hostName}"
++ lib.lists.optional cfg.advertiseExitNode "--advertise-routes=192.168.30.0/24"; ]
++ lib.lists.optional cfg.advertiseExitNode "--advertise-exit-node"
++ lib.lists.optional cfg.advertiseExitNode "--advertise-routes=192.168.30.0/24";
}; };
sops.secrets."tailscale/authKey" = { }; sops.secrets."tailscale/authKey" = {};
systemd.network.wait-online.ignoredInterfaces = [ "tailscale0" ]; systemd.network.wait-online.ignoredInterfaces = ["tailscale0"];
}; };
} }

View file

@ -1,23 +1,26 @@
{ self, nixpkgs, ... }@inputs: {
let self,
nixpkgs,
...
} @ inputs: let
deployArch = "x86_64-linux"; deployArch = "x86_64-linux";
machines = self.machines.${deployArch}; machines = self.machines.${deployArch};
mkNixosSystems = systemDef: mkNixosSystems = systemDef:
builtins.mapAttrs builtins.mapAttrs
(name: machine: (
name: machine:
nixpkgs.lib.nixosSystem (systemDef name machine) nixpkgs.lib.nixosSystem (systemDef name machine)
) )
machines; machines;
in in {
{
nixosConfigurations = mkNixosSystems (name: machine: { nixosConfigurations = mkNixosSystems (name: machine: {
system = machine.arch; system = machine.arch;
specialArgs = { inherit self inputs machine machines; }; specialArgs = {inherit self inputs machine machines;};
modules = [ modules = [
"${self}/modules" "${self}/modules"
{ networking.hostName = name; } {networking.hostName = name;}
]; ];
}); });
} }

View file

@ -1,23 +1,31 @@
{ nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: {
let nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
createScript = { name, runtimeInputs, scriptPath, extraWrapperFlags ? "", ... }: createScript = {
let name,
script = (pkgs.writeScriptBin name (builtins.readFile scriptPath)).overrideAttrs (old: { runtimeInputs,
buildCommand = "${old.buildCommand}\n patchShebangs $out"; scriptPath,
}); extraWrapperFlags ? "",
in ...
}: let
script = (pkgs.writeScriptBin name (builtins.readFile scriptPath)).overrideAttrs (old: {
buildCommand = "${old.buildCommand}\n patchShebangs $out";
});
in
pkgs.symlinkJoin { pkgs.symlinkJoin {
inherit name; inherit name;
paths = [ script ] ++ runtimeInputs; paths = [script] ++ runtimeInputs;
buildInputs = [ pkgs.makeWrapper ]; buildInputs = [pkgs.makeWrapper];
postBuild = "wrapProgram $out/bin/${name} --set PATH $out/bin ${extraWrapperFlags}"; postBuild = "wrapProgram $out/bin/${name} --set PATH $out/bin ${extraWrapperFlags}";
}; };
in in {
{
packages.bootstrap = createScript { packages.bootstrap = createScript {
name = "bootstrap"; name = "bootstrap";
runtimeInputs = with pkgs; [ sops coreutils nixos-anywhere ]; runtimeInputs = with pkgs; [sops coreutils nixos-anywhere];
scriptPath = ./bootstrap.sh; scriptPath = ./bootstrap.sh;
}; };
}) })

View file

@ -1,9 +1,12 @@
{ flake-utils, nixpkgs, ... }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{ {
flake-utils,
nixpkgs,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ ansible ]; buildInputs = with pkgs; [ansible];
}; };
}) })

View file

@ -1,14 +1,14 @@
{ nixpkgs, flake-utils, ... }: {
nixpkgs,
let flake-utils,
systemAttrs = flake-utils.lib.eachDefaultSystem (system: ...
let }: let
pkgs = nixpkgs.legacypackages.${system}; systemAttrs = flake-utils.lib.eachDefaultSystem (system: let
lib = pkgs.lib; pkgs = nixpkgs.legacypackages.${system};
in lib = pkgs.lib;
{ in {
net = import ./net.nix lib; net = import ./net.nix lib;
}); });
nonSystemAttrs = { nonSystemAttrs = {
globals = import ./globals.nix; globals = import ./globals.nix;
@ -16,4 +16,4 @@ let
allAttrs = systemAttrs // nonSystemAttrs; allAttrs = systemAttrs // nonSystemAttrs;
in in
allAttrs allAttrs

File diff suppressed because it is too large Load diff