feat(arcturus): add impermanence

This commit is contained in:
tux
2024-11-13 22:31:10 +05:30
parent c7868e8b5f
commit 56d194f454
4 changed files with 146 additions and 77 deletions

View File

@ -1,12 +1,18 @@
{
pkgs,
modulesPath,
inputs,
username,
config,
lib,
email,
config,
...
}: {
imports = [
./hardware-configuration.nix
(modulesPath + "/installer/scan/not-detected.nix")
(modulesPath + "/profiles/qemu-guest.nix")
inputs.disko.nixosModules.default
(import ./disko.nix {device = "/dev/sda";})
../common
../../modules/nixos/postgresql.nix
../../modules/nixos/headscale.nix
@ -57,17 +63,57 @@
};
};
nixpkgs = {
hostPlatform = "x86_64-linux";
};
boot = {
kernel.sysctl = {
"vm.swappiness" = 10;
};
kernelPackages = pkgs.linuxPackages_zen;
initrd.systemd.enable = true;
initrd.systemd = {
enable = lib.mkForce true;
services.wipe-my-fs = {
wantedBy = ["initrd.target"];
after = ["initrd-root-device.target"];
before = ["sysroot.mount"];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
mkdir /btrfs_tmp
mount /dev/disk/by-partlabel/disk-primary-root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
};
};
loader = {
grub.device = "/dev/sda";
timeout = 1;
grub = {
efiSupport = true;
efiInstallAsRemovable = true;
};
};
};
@ -88,6 +134,7 @@
defaults.email = "${email}";
certs = {
"tux.rs" = {
group = "nginx";
domain = "*.tux.rs";
extraDomainNames = ["tux.rs"];
dnsProvider = "cloudflare";
@ -111,36 +158,32 @@
recommendedProxySettings = true;
recommendedZstdSettings = true;
};
borgbackup.jobs.arcturus-backup = {
paths = [
"/var/lib/bitwarden_rs"
"/var/lib/gitea"
"/var/lib/headscale"
"/var/lib/grafana"
"/var/lib/loki"
"/var/lib/private/ntfy-sh"
];
encryption = {
mode = "repokey-blake2";
passCommand = "cat ${config.sops.secrets.borg_encryption_key.path}";
};
environment.BORG_RSH = "ssh -i /home/${username}/.ssh/storagebox";
repo = "ssh://u416910@u416910.your-storagebox.de:23/./arcturus-backups";
compression = "auto,zstd";
startAt = "daily";
};
};
programs = {
zsh.enable = true;
dconf.enable = true;
};
fonts.packages = with pkgs; [(nerdfonts.override {fonts = ["FiraCode" "JetBrainsMono"];})];
programs.fuse.userAllowOther = true;
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist" = {
enable = false;
hideMounts = true;
directories = [
"/var/log"
"/var/lib/nixos"
"/var/lib/acme"
"/var/lib/postgresql"
"/var/lib/headscale"
"/var/lib/vaultwarden"
"/var/lib/gitea"
"/var/lib/clickhouse"
"/var/lib/grafana"
"/var/lib/promtail"
"/var/lib/private"
"/var/lib/nextcloud"
];
files = [
"/etc/ssh/ssh_host_ed25519_key"
"/etc/ssh/ssh_host_ed25519_key.pub"
"/etc/ssh/ssh_host_rsa_key"
"/etc/ssh/ssh_host_rsa_key.pub"
];
};
home-manager.users.${username} = {
@ -149,5 +192,5 @@
];
};
system.stateVersion = "23.11";
system.stateVersion = "24.11";
}