dotfiles/systems/ceres/config/filesystem.nix

142 lines
2.9 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-11-09 02:42:22 -06:00
inherit (flake.config.machines.devices) eris;
erisSecrets = config.sops.secrets."network/server".path;
2025-11-05 12:51:52 -06:00
2025-11-05 21:40:56 -06:00
rootDevice = "/dev/disk/by-label/root";
bootDevice = "/dev/disk/by-label/BOOT";
2025-11-09 02:42:22 -06:00
sambaDrives = [
"samba0"
];
sambaFolders = [
"raid0"
];
sambaMounts = sambaDrive: folder: {
name = "${eris.${sambaDrive}.mount}/${folder}";
value = {
device = "${eris.${sambaDrive}.device}/${folder}";
fsType = "cifs";
options = eris.${sambaDrive}.options ++ [
"credentials=${erisSecrets}"
];
};
};
2025-10-01 19:51:55 -05:00
in
{
2025-11-05 12:51:52 -06:00
fileSystems = {
"/" = {
device = rootDevice;
fsType = "btrfs";
options = [
"subvol=root"
];
};
2025-11-05 01:46:22 -06:00
2025-11-05 12:51:52 -06:00
"/nix" = {
device = rootDevice;
fsType = "btrfs";
options = [
"subvol=nix"
];
};
2025-11-05 01:46:22 -06:00
2025-11-05 21:40:56 -06:00
"/persist" = {
2025-11-05 12:51:52 -06:00
device = rootDevice;
fsType = "btrfs";
neededForBoot = true;
options = [
2025-11-05 21:40:56 -06:00
"subvol=persist"
2025-11-05 12:51:52 -06:00
];
};
2025-11-05 01:46:22 -06:00
2025-11-05 12:51:52 -06:00
"/boot" = {
device = bootDevice;
2025-11-05 12:51:52 -06:00
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
2025-11-05 01:46:22 -06:00
2025-11-05 12:51:52 -06:00
"/mnt/storage" = {
device = "/dev/disk/by-label/storage";
fsType = "ext4";
2025-11-04 14:57:25 -06:00
};
"/etc/ssh" = {
neededForBoot = true;
};
2025-11-09 02:42:22 -06:00
}
// (builtins.listToAttrs (
builtins.concatMap (drive: map (folder: sambaMounts drive folder) sambaFolders) sambaDrives
));
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:51:52 -06:00
mount -o subvolid=5 ${rootDevice} /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
'';
2025-11-05 22:17:28 -06:00
environment.persistence."/persist" = {
2025-11-04 14:57:25 -06:00
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;
}