dotfiles/systems/eris/config/filesystem.nix

142 lines
3.1 KiB
Nix
Executable file

{
flake,
config,
lib,
...
}:
let
inherit (flake.config.people) user0;
rootDevice = "/dev/disk/by-label/root";
bootDevice = "/dev/disk/by-label/BOOT";
in
{
fileSystems = {
"/" = {
device = rootDevice;
fsType = "btrfs";
options = [
"subvol=root"
];
};
"/nix" = {
device = rootDevice;
fsType = "btrfs";
options = [
"subvol=nix"
];
};
"/persist" = {
device = rootDevice;
fsType = "btrfs";
neededForBoot = true;
options = [
"subvol=persist"
];
};
"/boot" = {
device = bootDevice;
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
"/mnt/storage" = {
device = "/dev/md0";
fsType = "ext4";
options = [
"defaults"
"nofail"
"x-systemd.device-timeout=10"
];
};
"/etc/ssh" = {
neededForBoot = true;
};
};
environment.persistence."/persist" = {
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=";
}
];
};
};
boot = {
initrd.postResumeCommands = lib.mkAfter ''
mkdir /btrfs_tmp
mount -o subvolid=5 ${rootDevice} /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/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); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
swraid = {
enable = true;
mdadmConf = ''
ARRAY /dev/md0 metadata=1.2 name=eris:storage UUID=64659038:a939a18d:8cdc0f3f:97171a50
'';
};
};
systemd.tmpfiles.rules = [
"Z ${config.home-manager.users.${user0}.home.homeDirectory} 0755 ${user0} users -"
"d /mnt/storage 2775 root root -"
];
services.udisks2.enable = true;
}
# sudo mount /dev/disk/by-label/root /mnt
# sudo btrfs subvolume create /mnt/persist
# sudo btsfs subvolume create /mnt/root
# sudo btrfs subvolume create /mnt/nix
# sudo umount /mnt
# sudo mount -o subvol=root /dev/disk/by-label/root /mnt
# sudo mount -o subvol=nix /dev/disk/by-label/root /mnt/nix
# sudo mount -o subvol=persist /dev/disk/by-label/root /mnt/persist
# sudo mount /dev/disk/by-label/BOOT /mnt/boot
# sudo nixos-generate-config --root /mnt
# sudo nixos-install --root /mnt
# sudo nixos-enter --root /mnt
# nixos-rebuild boot
# exit
# sudo reboot