Compare commits

...

3 Commits

Author SHA1 Message Date
e44ec3cba7
refactor(nix): overhaul nixos configurations
Some checks failed
Check Formatting of Files / Check-Formatting (push) Has been cancelled
2024-08-25 00:28:11 -05:00
d9db6e1938
refactor(hosts/luna): update price's password 2024-08-25 00:26:59 -05:00
6e0af2ca7a
refactor(hosts/luna): use btrfs-rollback service for handling rollbacks 2024-08-25 00:26:25 -05:00
14 changed files with 83 additions and 147 deletions

View File

@ -188,25 +188,7 @@
});
nixosConfigurations =
let
lib = (import ./lib { lib = nixpkgs.lib; }) // nixpkgs.lib;
persist-dir = "/persist";
defaults = {
config = {
environment.etc.machine-id.source = "${persist-dir}/ephemeral/etc/machine-id";
environment.persistence.save = {
hideMounts = true;
persistentStoragePath = "${persist-dir}/save";
};
environment.persistence.ephemeral = {
persistentStoragePath = "${persist-dir}/ephemeral";
hideMounts = true;
directories = [
"/var/lib"
"/etc/nixos"
];
};
};
};
clib = (import ./lib { lib = nixpkgs.lib; });
in
{
orion =
@ -220,12 +202,9 @@
inherit inputs;
inherit outputs;
inherit hostname;
inherit lib;
inherit persist-dir;
root-disk = "/dev/nvme0n1";
inherit clib;
};
modules = [
defaults
./modules/btrfs-rollback.nix
inputs.impermanence.nixosModules.impermanence
inputs.agenix.nixosModules.default
@ -234,7 +213,7 @@
config =
(import "${self}/secrets" {
agenix = false;
inherit lib;
inherit clib;
}).${hostname};
}
./hosts/${hostname}
@ -251,13 +230,10 @@
inherit inputs;
inherit hostname;
inherit nixpkgs;
inherit lib;
inherit persist-dir;
root-disk = "/dev/nvme0n1";
fqdn = "orion-technologies.io";
inherit clib;
};
modules = [
defaults
./modules/btrfs-rollback.nix
inputs.impermanence.nixosModules.impermanence
inputs.agenix.nixosModules.default
inputs.disko.nixosModules.disko
@ -267,7 +243,7 @@
config =
(import "${self}/secrets" {
agenix = false;
inherit lib;
inherit clib;
}).${hostname};
}
./hosts/${hostname}

View File

@ -1,7 +1,7 @@
{ lib, ... }:
{ clib, ... }:
{
imports = (
lib.recurseFilesInDirs [
clib.recurseFilesInDirs [
./os
./modules
] ".nix"

View File

@ -1,9 +1,4 @@
{
persist-dir,
pkgs,
config,
...
}:
{ pkgs, config, ... }:
let
laurel-user = "_laurel";
in
@ -145,7 +140,7 @@ in
"-a always,exit -F arch=b64 -S open -F dir=/opt -F success=0 -F key=unauthedfileaccess"
"-a always,exit -F arch=b64 -S open -F dir=/boot -F success=0 -F key=unauthedfileaccess"
"-a always,exit -F arch=b64 -S open -F dir=/nix -F success=0 -F key=unauthedfileaccess"
"-a always,exit -F arch=b64 -S open -F dir=${persist-dir} -F success=0 -F key=unauthedfileaccess"
"-a always,exit -F arch=b64 -S open -F dir=/persist -F success=0 -F key=unauthedfileaccess"
# File deletion events by users
"-a always,exit -F arch=b64 -S rmdir -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=-1 -F key=delete"

View File

@ -1,11 +1,6 @@
{
config,
pkgs,
fqdn,
...
}:
{ config, ... }:
let
grafana_host = "grafana.${fqdn}";
grafana_host = "grafana.orion-technologies.io";
in
{
services = {

View File

@ -1,11 +1,6 @@
{
config,
fqdn,
pkgs,
...
}:
{ config, pkgs, ... }:
let
prometheus_host = "prometheus.${fqdn}";
prometheus_host = "prometheus.orion-technologies.io";
in
{
services = {

View File

@ -1,13 +1,12 @@
{
config,
fqdn,
inputs,
pkgs,
lib,
...
}:
let
gitea_host = "git.${fqdn}";
gitea_host = "git.orion-technologies.io";
# TODO: Move this docker image out to a separate package and NixOS Module
# Huge thank you to https://icewind.nl/entry/gitea-actions-nix/ -- wouldn't have figured this out
# without that post 🙂

View File

@ -1,4 +1,4 @@
{ config, fqdn, ... }:
{ config, ... }:
{
services.lakewatch-api = {
enable = true;
@ -14,7 +14,7 @@
passwordFile = config.age.secrets.lakewatch-db-pass.path;
};
};
services.nginx.virtualHosts."lakewatch.${fqdn}" = {
services.nginx.virtualHosts."lakewatch.orion-technologies.io" = {
forceSSL = true;
enableACME = true;
locations."/".proxyPass = "http://${config.services.lakewatch-api.host}:${builtins.toString config.services.lakewatch-api.port}";

View File

@ -1,9 +1,4 @@
{
inputs,
pkgs,
fqdn,
...
}:
{ inputs, pkgs, ... }:
{
services.nginx = {
enable = true;
@ -19,7 +14,7 @@
};
services.nginx.virtualHosts = {
"blog.${fqdn}" = {
"blog.orion-technologies.io" = {
forceSSL = true;
enableACME = true;
globalRedirect = "price-hiller.com";

View File

@ -1,8 +1,15 @@
{ modulesPath, pkgs, ... }:
{ modulesPath, ... }:
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
services.btrfs-rollback = {
enable = true;
diskLabel = "NixOS-Primary";
subvolume = "root";
snapshot = "root-base";
};
boot = {
tmp = {
useTmpfs = true;
@ -24,58 +31,7 @@
"sd_mod"
];
kernelModules = [ ];
systemd = {
enable = true;
initrdBin = [
pkgs.libuuid
pkgs.gawk
];
services.rollback = {
description = "Rollback btrfs root subvolume";
wantedBy = [ "initrd.target" ];
before = [ "sysroot.mount" ];
after = [ "initrd-root-device.target" ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /mnt
DISK_LABEL="NixOS-Primary"
FOUND_DISK=0
ATTEMPTS=50
printf "Attempting to find disk with label '%s'\n" "$DISK_LABEL"
while ((ATTEMPTS > 0)); do
if findfs LABEL="$DISK_LABEL"; then
FOUND_DISK=1
printf "Found disk!\n"
break;
fi
((ATTEMPTS--))
sleep .1
printf "Remaining disk discovery attempts: %s\n" "$ATTEMPTS"
done
if (( FOUND_DISK == 0 )); then
printf "Discovery of disk with label '%s' failed! Cannot rollback!\n" "$DISK_LABEL"
exit 1
fi
mount -t btrfs -o subvol=/ $(findfs LABEL="$DISK_LABEL") /mnt
btrfs subvolume list -to /mnt/root \
| awk 'NR>2 { printf $4"\n" }' \
| while read subvol; do
printf "Removing Subvolume: %s\n" "$subvol";
btrfs subvolume delete "/mnt/$subvol"
done
printf "Removing /root subvolume\n"
btrfs subvolume delete /mnt/root
printf "Restoring base /root subvolume\n"
btrfs subvolume snapshot /mnt/root-base /mnt/root
umount /mnt
'';
};
};
systemd.enable = true;
};
};
}

View File

@ -1,10 +1,22 @@
{ lib, ... }:
let
root-disk = "/dev/nvme0n1";
persist-dir = "/persist";
in
{
lib,
root-disk,
persist-dir,
...
}:
{
environment.etc.machine-id.source = "${persist-dir}/ephemeral/etc/machine-id";
environment.persistence.save = {
hideMounts = true;
persistentStoragePath = "${persist-dir}/save";
};
environment.persistence.ephemeral = {
persistentStoragePath = "${persist-dir}/ephemeral";
hideMounts = true;
directories = [
"/var/lib"
"/etc/nixos"
];
};
services = {
fstrim.enable = true;
btrfs.autoScrub = {
@ -12,7 +24,7 @@
fileSystems = [
"/"
"/nix"
"/persist"
"${persist-dir}"
];
};
snapper = {

View File

@ -1,7 +1,7 @@
{ pkgs, lib, ... }:
{ pkgs, clib, ... }:
{
imports = (
lib.recurseFilesInDirs [
clib.recurseFilesInDirs [
./os
./modules
] ".nix"

View File

@ -1,9 +1,8 @@
{
lib,
root-disk,
persist-dir,
...
}:
{ lib, ... }:
let
root-disk = "/dev/nvme0n1";
persist-dir = "/persist";
in
{
services = {
fstrim.enable = true;
@ -17,6 +16,20 @@
};
};
environment.etc.machine-id.source = "${persist-dir}/ephemeral/etc/machine-id";
environment.persistence.save = {
hideMounts = true;
persistentStoragePath = "${persist-dir}/save";
};
environment.persistence.ephemeral = {
persistentStoragePath = "${persist-dir}/ephemeral";
hideMounts = true;
directories = [
"/var/lib"
"/etc/nixos"
];
};
fileSystems."${persist-dir}".neededForBoot = true;
disko.devices = {

View File

@ -1,6 +1,6 @@
{
agenix ? false,
lib ? import ../lib { },
clib ? import ../clib { },
}:
let
masterKeys = [
@ -54,7 +54,7 @@ if agenix then
else
(builtins.mapAttrs (
host: secrets:
(lib.recursiveMerge (
(clib.recursiveMerge (
builtins.map (secretName: { age.secrets.${secretName}.file = ./${secrets.${secretName}}; }) (
builtins.attrNames hosts.${host}
)

View File

@ -1,15 +1,15 @@
-----BEGIN AGE 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