dotfiles/systems/ceres/config/filesystem.nix

109 lines
2.3 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-05 12:14:28 -06:00
device = "/dev/disk/by-uuid/8596aaba-338f-1f9d-ba9d-a63bcbc38523";
2025-11-04 14:57:25 -06:00
fsType = "btrfs";
2025-11-05 12:14:28 -06:00
options = [
"subvol=root"
];
2025-11-04 14:57:25 -06:00
};
2025-11-05 01:46:22 -06:00
2025-11-04 14:57:25 -06:00
"/nix" = {
2025-11-05 12:14:28 -06:00
device = "/dev/disk/by-uuid/8596aaba-338f-1f9d-ba9d-a63bcbc38523";
2025-11-04 14:57:25 -06:00
fsType = "btrfs";
2025-11-05 12:14:28 -06:00
options = [
"subvol=nix"
];
2025-11-04 14:57:25 -06:00
};
2025-11-05 01:46:22 -06:00
2025-11-04 14:57:25 -06:00
"/persistent" = {
2025-11-05 12:14:28 -06:00
device = "/dev/disk/by-uuid/8596aaba-338f-1f9d-ba9d-a63bcbc38523";
2025-11-04 14:57:25 -06:00
fsType = "btrfs";
neededForBoot = true;
2025-11-05 12:14:28 -06:00
options = [
"subvol=persistent"
];
2025-11-04 03:30:52 -06:00
};
2025-11-05 01:46:22 -06:00
"/boot" = {
2025-11-05 12:14:28 -06:00
device = "/dev/disk/by-uuid/7328-07C6";
fsType = "vfat";
2025-11-05 12:14:28 -06:00
options = [
"fmask=0077"
"dmask=0077"
];
};
2025-11-05 01:46:22 -06:00
"/mnt/storage" = {
2025-11-04 14:57:25 -06:00
device = "/dev/disk/by-label/storage";
fsType = "ext4";
};
};
2025-11-05 01:08:00 -06:00
boot.initrd.postResumeCommands = lib.mkAfter ''
2025-11-05 01:06:47 -06:00
mkdir /btrfs_tmp
2025-11-05 12:04:46 -06:00
mount -o subvolid=5 /dev/sdb2 /btrfs_tmp
2025-11-04 14:57:25 -06:00
2025-11-05 12:04:46 -06:00
if [[ -e /btrfs_tmp/root ]]; then
2025-11-05 00:40:03 -06:00
mkdir -p /btrfs_tmp/old_roots
2025-11-05 12:04:46 -06:00
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
2025-11-04 14:57:25 -06:00
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
2025-11-04 23:16:03 -06:00
delete_subvolume_recursively "/btrfs_tmp/$i"
2025-11-04 14:57:25 -06:00
done
btrfs subvolume delete "$1"
}
2025-11-05 01:06:47 -06:00
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
2025-11-04 14:57:25 -06:00
delete_subvolume_recursively "$i"
done
2025-11-05 12:04:46 -06:00
btrfs subvolume create /btrfs_tmp/root
2025-11-04 23:16:03 -06:00
umount /btrfs_tmp
2025-11-04 14:57:25 -06:00
'';
environment.persistence."/persistent" = {
directories = [
"/var/cache"
2025-11-05 00:04:49 -06:00
"/var/lib"
{
directory = "/etc/ssh";
mode = "u=rwx,g=rx,o=rx";
user = "root";
}
2025-11-04 14:57:25 -06:00
];
2025-11-05 00:04:49 -06:00
hideMounts = true;
2025-11-04 14:57:25 -06:00
users.${user0} = {
directories = [
2025-11-05 00:04:49 -06:00
".cache"
".config"
".local/share/direnv"
".local/state/nix"
{
directory = ".ssh";
mode = "u=rwx,g=,o=";
}
2025-11-04 14:57:25 -06:00
];
};
};
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;
}