mirror of
https://gitlab.com/upRootNutrition/dotfiles.git
synced 2025-12-06 21:17:14 -06:00
98 lines
1.9 KiB
Nix
Executable file
98 lines
1.9 KiB
Nix
Executable file
{
|
|
flake,
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
inherit (flake.config.people) user0;
|
|
in
|
|
{
|
|
fileSystems = {
|
|
"/" = {
|
|
device = "/dev/disk/by-label/root";
|
|
fsType = "btrfs";
|
|
options = [
|
|
"subvol=@"
|
|
];
|
|
};
|
|
|
|
"/nix" = {
|
|
device = "/dev/disk/by-label/root";
|
|
fsType = "btrfs";
|
|
options = [
|
|
"subvol=@nix"
|
|
];
|
|
};
|
|
|
|
"/persistent" = {
|
|
device = "/dev/disk/by-label/root";
|
|
fsType = "btrfs";
|
|
neededForBoot = true;
|
|
options = [
|
|
"subvol=@persistent"
|
|
];
|
|
};
|
|
|
|
"/boot" = {
|
|
device = "/dev/disk/by-label/BOOT";
|
|
fsType = "vfat";
|
|
};
|
|
|
|
"/mnt/storage" = {
|
|
device = "/dev/disk/by-label/storage";
|
|
fsType = "ext4";
|
|
};
|
|
};
|
|
|
|
boot.initrd.postResumeCommands = lib.mkAfter ''
|
|
mkdir -p /mnt
|
|
mount -o subvol=/ /dev/disk/by-label/root /mnt
|
|
|
|
if [[ -e /mnt/@ ]]; then
|
|
mkdir -p /mnt/@old_roots
|
|
timestamp=$(date --date="@$(stat -c %Y /mnt/@)" "+%Y-%m-%d_%H:%M:%S")
|
|
mv /mnt/@ "/mnt/@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 "/mnt/$i"
|
|
done
|
|
btrfs subvolume delete "$1"
|
|
}
|
|
|
|
for i in $(find /mnt/@old_roots/ -maxdepth 1 -mtime +30); do
|
|
delete_subvolume_recursively "$i"
|
|
done
|
|
|
|
btrfs subvolume create /mnt/@
|
|
umount /mnt
|
|
'';
|
|
|
|
environment.persistence."/persistent" = {
|
|
hideMounts = true;
|
|
directories = [
|
|
"/var/log"
|
|
"/var/lib"
|
|
"/var/cache"
|
|
"/etc/ssh"
|
|
];
|
|
files = [
|
|
"/etc/machine-id"
|
|
];
|
|
users.${user0} = {
|
|
directories = [
|
|
".ssh"
|
|
];
|
|
};
|
|
};
|
|
|
|
systemd.tmpfiles.rules = [
|
|
"Z ${config.home-manager.users.${user0}.home.homeDirectory} 0755 ${user0} users -"
|
|
"Z /mnt/storage 2775 root root -"
|
|
];
|
|
|
|
services.udisks2.enable = true;
|
|
}
|