Modularize code

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-06-20 11:42:31 +03:00
parent 4e4fb9c86c
commit ea01ac7fe0
17 changed files with 440 additions and 374 deletions

View File

@@ -0,0 +1,22 @@
{ inputs, lib, ... }:
{
imports = [ inputs.impermanence.nixosModules.impermanence ];
fileSystems."/persist".neededForBoot = true;
boot.initrd.postDeviceCommands = lib.mkAfter (builtins.readFile ./impermanence.sh);
environment.persistence."/persist" = {
hideMounts = true;
directories = [
"/etc/nixos"
"/etc/NetworkManager/system-connections"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
"/var/log"
];
files = [
"/etc/machine-id"
];
};
}

View File

@@ -0,0 +1,25 @@
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/mnt/btrfs/$i"
done
btrfs subvolume delete "$1"
}
mkdir -p /mnt/btrfs
mount /dev/mapper/luks /mnt/btrfs
if [[ -e /mnt/btrfs/root ]]; then
mkdir -p /mnt/btrfs/root.bak
timestamp=$(date --date="@$(stat -c %Y /mnt/btrfs/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /mnt/btrfs/root "/mnt/btrfs/root.bak/$timestamp"
fi
find /mnt/btrfs/root.bak/ -maxdepth 1 -mtime +14 | while IFS= read -r i; do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /mnt/btrfs/root
umount /mnt/btrfs
rmdir /mnt/btrfs

View File

@@ -0,0 +1,16 @@
{ inputs, pkgs, ... }:
{
imports = [ inputs.sops-nix.nixosModules.sops ];
environment = {
persistence."/persist".files = [ "/etc/ssh/ssh_host_ed25519_key" ];
systemPackages = with pkgs; [ sops ];
};
sops.age = {
generateKey = true;
sshKeyPaths = [ "/persist/etc/ssh/ssh_host_ed25519_key" ];
keyFile = "/var/lib/sops-nix/key.txt";
};
}

View File

@@ -3,4 +3,6 @@
enable = true;
histFile = "/var/lib/zsh/history";
};
environment.persistence."/persist".directories = [ "/var/lib/zsh" ];
}