|
|
@@ -5,7 +5,7 @@
|
|
|
{ config.facter.reportPath = ./facter.json; }
|
|
|
|
|
|
outputs.modules.global.nix-config
|
|
|
- # inputs.impermanence.nixosModules.impermanence
|
|
|
+ inputs.impermanence.nixosModules.impermanence
|
|
|
inputs.disko.nixosModules.disko
|
|
|
|
|
|
./disko.nix
|
|
|
@@ -37,50 +37,48 @@
|
|
|
"vm.swappiness" = 10;
|
|
|
"net.core.default_qdisc" = "cake";
|
|
|
};
|
|
|
- };
|
|
|
|
|
|
- # # Impermanence: reset root on boot
|
|
|
- # initrd.postDeviceCommands = lib.mkAfter ''
|
|
|
- # # Get device from disko config
|
|
|
- # DEVICE=/dev/disk/by-id/nvme-KINGSTON_SNV3S1000G_50026B7383CC0908-part2
|
|
|
- #
|
|
|
- # mkdir -p /mnt
|
|
|
- # mount -o subvol=/ $DEVICE /mnt
|
|
|
- #
|
|
|
- # # Create a directory for old roots if it doesn't exist
|
|
|
- # mkdir -p /mnt/old-roots
|
|
|
- #
|
|
|
- # # Move current root to old-roots with timestamp if it exists
|
|
|
- # if [[ -e /mnt/@root && ! -e /mnt/@root-blank ]]; then
|
|
|
- # timestamp=$(date --date="@$(stat -c %Y /mnt/@root)" "+%Y-%m-%d_%H:%M:%S")
|
|
|
- # mv /mnt/@root "/mnt/old-roots/@root-$timestamp"
|
|
|
- # fi
|
|
|
- #
|
|
|
- # # Function to recursively delete subvolumes
|
|
|
- # delete_subvolume_recursively() {
|
|
|
- # for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
|
|
- # delete_subvolume_recursively "/mnt/$i"
|
|
|
- # done
|
|
|
- # btrfs subvolume delete "$1"
|
|
|
- # }
|
|
|
- #
|
|
|
- # # Delete old roots older than 30 days
|
|
|
- # for i in $(find /mnt/old-roots/ -maxdepth 1 -mtime +30); do
|
|
|
- # delete_subvolume_recursively "$i"
|
|
|
- # done
|
|
|
- #
|
|
|
- # # Create fresh root from blank if needed or create blank if it doesn't exist
|
|
|
- # if [[ -e /mnt/@root-blank ]]; then
|
|
|
- # btrfs subvolume delete /mnt/@root || true
|
|
|
- # btrfs subvolume snapshot /mnt/@root-blank /mnt/@root
|
|
|
- # else
|
|
|
- # btrfs subvolume create /mnt/@root-blank
|
|
|
- # btrfs subvolume create /mnt/@root
|
|
|
- # fi
|
|
|
- #
|
|
|
- # umount /mnt
|
|
|
- # '';
|
|
|
- # };
|
|
|
+ # Impermanence: reset root on boot
|
|
|
+ initrd.postDeviceCommands = lib.mkAfter ''
|
|
|
+ DEVICE=${config.disko.devices.disk.main.device}-part2
|
|
|
+
|
|
|
+ mkdir -p /mnt
|
|
|
+ mount -o subvol=/ $DEVICE /mnt
|
|
|
+
|
|
|
+ # Create a directory for old roots if it doesn't exist
|
|
|
+ mkdir -p /mnt/old-roots
|
|
|
+
|
|
|
+ # Move current root to old-roots with timestamp if it exists
|
|
|
+ if [[ -e /mnt/@root && ! -e /mnt/@root-blank ]]; then
|
|
|
+ timestamp=$(date --date="@$(stat -c %Y /mnt/@root)" "+%Y-%m-%d_%H:%M:%S")
|
|
|
+ mv /mnt/@root "/mnt/old-roots/@root-$timestamp"
|
|
|
+ fi
|
|
|
+
|
|
|
+ # Function to recursively delete subvolumes
|
|
|
+ delete_subvolume_recursively() {
|
|
|
+ for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
|
|
+ delete_subvolume_recursively "/mnt/$i"
|
|
|
+ done
|
|
|
+ btrfs subvolume delete "$1"
|
|
|
+ }
|
|
|
+
|
|
|
+ # Delete old roots older than 30 days
|
|
|
+ for i in $(find /mnt/old-roots/ -maxdepth 1 -mtime +30); do
|
|
|
+ delete_subvolume_recursively "$i"
|
|
|
+ done
|
|
|
+
|
|
|
+ # Create fresh root from blank if needed or create blank if it doesn't exist
|
|
|
+ if [[ -e /mnt/@root-blank ]]; then
|
|
|
+ btrfs subvolume delete /mnt/@root || true
|
|
|
+ btrfs subvolume snapshot /mnt/@root-blank /mnt/@root
|
|
|
+ else
|
|
|
+ btrfs subvolume create /mnt/@root-blank
|
|
|
+ btrfs subvolume create /mnt/@root
|
|
|
+ fi
|
|
|
+
|
|
|
+ umount /mnt
|
|
|
+ '';
|
|
|
+ };
|
|
|
|
|
|
hardware = {
|
|
|
fancontrol = {
|
|
|
@@ -248,26 +246,27 @@
|
|
|
};
|
|
|
};
|
|
|
|
|
|
- # # Persistent directories for impermanence
|
|
|
- # environment.persistence."/persist" = {
|
|
|
- # hideMounts = true;
|
|
|
- # directories = [
|
|
|
- # "/etc/nixos"
|
|
|
- # "/etc/ssh"
|
|
|
- # "/var/lib/nixos"
|
|
|
- # "/var/lib/systemd"
|
|
|
- # "/srv"
|
|
|
- # ];
|
|
|
- # files = [
|
|
|
- # "/etc/machine-id"
|
|
|
- # ];
|
|
|
- # users.thomas = {
|
|
|
- # directories = [
|
|
|
- # ".ssh"
|
|
|
- # ".config"
|
|
|
- # ];
|
|
|
- # };
|
|
|
- # };
|
|
|
+ # Persistent directories for impermanence
|
|
|
+ fileSystems."/persist".neededForBoot = true;
|
|
|
+ environment.persistence."/persist" = {
|
|
|
+ hideMounts = true;
|
|
|
+ directories = [
|
|
|
+ "/etc/nixos"
|
|
|
+ "/etc/ssh"
|
|
|
+ "/var/lib/nixos"
|
|
|
+ "/var/lib/systemd"
|
|
|
+ "/srv"
|
|
|
+ ];
|
|
|
+ files = [
|
|
|
+ "/etc/machine-id"
|
|
|
+ ];
|
|
|
+ users.thomas = {
|
|
|
+ directories = [
|
|
|
+ ".ssh"
|
|
|
+ ".config"
|
|
|
+ ];
|
|
|
+ };
|
|
|
+ };
|
|
|
|
|
|
# System state version
|
|
|
system.stateVersion = "25.05";
|