dotfiles/systems/ceres/config/filesystem.nix

102 lines
2 KiB
Nix
Raw Normal View History

2025-10-01 19:51:55 -05:00
{
flake,
config,
2025-11-04 14:57:25 -06:00
lib,
2025-10-01 19:51:55 -05:00
...
}:
let
inherit (flake.config.people) user0;
2025-10-01 19:51:55 -05:00
in
{
fileSystems = {
"/" = {
2025-11-04 14:57:25 -06:00
device = "/dev/disk/by-label/root";
fsType = "btrfs";
options = [
"subvol=@"
2025-11-04 22:27:30 -06:00
"compress=zstd"
"noatime"
2025-11-04 14:57:25 -06:00
];
};
"/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"
];
2025-11-04 03:30:52 -06:00
};
2025-11-04 14:57:25 -06:00
"/boot" = {
2025-11-04 14:57:25 -06:00
device = "/dev/disk/by-label/BOOT";
fsType = "vfat";
};
2025-11-04 14:57:25 -06:00
"/mnt/storage" = {
2025-11-04 14:57:25 -06:00
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"
2025-11-04 22:27:30 -06:00
"/var/lib/nixos"
"/var/lib/systemd/coredump"
2025-11-04 14:57:25 -06:00
"/var/cache"
"/etc/ssh"
];
files = [
"/etc/machine-id"
];
users.${user0} = {
directories = [
".ssh"
];
};
};
2025-10-01 19:51:55 -05:00
systemd.tmpfiles.rules = [
"Z ${config.home-manager.users.${user0}.home.homeDirectory} 0755 ${user0} users -"
"Z /mnt/storage 2775 root root -"
2025-10-01 19:51:55 -05:00
];
services.udisks2.enable = true;
}