dotfiles/systems/ceres/config/filesystem.nix
2025-11-05 00:22:35 -06:00

96 lines
2.2 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=root" ];
};
"/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";
options = [ "umask=0077" ];
};
"/mnt/storage" = {
device = "/dev/disk/by-label/storage";
fsType = "ext4";
};
};
boot.initrd.postResumeCommands = lib.mkAfter ''
mkdir -p /btrfs_tmp
mount -o subvol=/ /dev/disk/by-label/root /btrfs_tmp
if [[ -e /btrfs_tmp/@ ]]; then
mkdir -p /btrfs_tmp/@old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@)" "+%Y-%m-%d_%H:%M:%S")
mv /btrfs_tmp/@ "/btrfs_tmp/@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 "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/@old_roots/ -maxdepth 1 -mtime +30 2>/dev/null); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/@
umount /btrfs_tmp
'';
environment.persistence."/persistent" = {
directories = [
"/var/cache"
"/var/lib"
{
directory = "/etc/ssh";
mode = "u=rwx,g=rx,o=rx";
user = "root";
}
];
hideMounts = true;
users.${user0} = {
directories = [
".cache"
".config"
".local/share/direnv"
".local/state/nix"
{
directory = ".ssh";
mode = "u=rwx,g=,o=";
}
];
};
};
systemd.tmpfiles.rules = [
"Z ${config.home-manager.users.${user0}.home.homeDirectory} 0755 ${user0} users -"
"Z /mnt/storage 2775 root root -"
];
services.udisks2.enable = true;
}