Compare commits
No commits in common. "8882eaa3abffaf55e6e1944b021a06d4f3225b7a" and "58726dc1bafb4385751be7bee36763f91a2205af" have entirely different histories.
8882eaa3ab
...
58726dc1ba
3 changed files with 127 additions and 188 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
{
|
{
|
||||||
config,
|
|
||||||
utils,
|
utils,
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
|
@ -16,124 +14,93 @@ let
|
||||||
|
|
||||||
primaryDeviceUnit = "${escapeSystemdPath PRIMARY}.device";
|
primaryDeviceUnit = "${escapeSystemdPath PRIMARY}.device";
|
||||||
in
|
in
|
||||||
lib.mkMerge [
|
{
|
||||||
# Main filesystems
|
# BOOT
|
||||||
{
|
fileSystems."/boot" = {
|
||||||
# BOOT
|
device = BOOT;
|
||||||
fileSystems."/boot" = {
|
fsType = "vfat";
|
||||||
device = BOOT;
|
options = [
|
||||||
fsType = "vfat";
|
"fmask=0022"
|
||||||
options = [
|
"dmask=0022"
|
||||||
"fmask=0022"
|
];
|
||||||
"dmask=0022"
|
};
|
||||||
];
|
|
||||||
};
|
# PRIMARY
|
||||||
|
fileSystems."/" = {
|
||||||
|
device = PRIMARY;
|
||||||
|
fsType = "bcachefs";
|
||||||
|
options = [
|
||||||
|
"X-mount.subdir=@root"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
fileSystems."/.old_roots" = {
|
||||||
|
device = PRIMARY;
|
||||||
|
fsType = "bcachefs";
|
||||||
|
options = [
|
||||||
|
"nofail" # this may not exist yet just skip it
|
||||||
|
"X-mount.mkdir"
|
||||||
|
"X-mount.subdir=@old_roots"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
fileSystems."/nix" = {
|
||||||
|
device = PRIMARY;
|
||||||
|
fsType = "bcachefs";
|
||||||
|
options = [
|
||||||
|
"X-mount.mkdir"
|
||||||
|
"X-mount.subdir=@nix"
|
||||||
|
"relatime"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
fileSystems."/.snapshots" = {
|
||||||
|
device = PRIMARY;
|
||||||
|
fsType = "bcachefs";
|
||||||
|
options = [
|
||||||
|
"X-mount.mkdir"
|
||||||
|
"X-mount.subdir=@root"
|
||||||
|
"relatime"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
# (optional) for preservation/impermanence
|
||||||
|
fileSystems."/persist" = {
|
||||||
|
device = PRIMARY;
|
||||||
|
fsType = "bcachefs";
|
||||||
|
options = [
|
||||||
|
"X-mount.mkdir"
|
||||||
|
"X-mount.subdir=@persist"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
# PRIMARY
|
|
||||||
fileSystems."/" = {
|
|
||||||
device = PRIMARY;
|
|
||||||
fsType = "bcachefs";
|
|
||||||
options = [
|
|
||||||
"X-mount.subdir=@root"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
fileSystems."/.old_roots" = {
|
|
||||||
device = PRIMARY;
|
|
||||||
fsType = "bcachefs";
|
|
||||||
options = [
|
|
||||||
"nofail" # this may not exist yet just skip it
|
|
||||||
"X-mount.mkdir"
|
|
||||||
"X-mount.subdir=@old_roots"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
fileSystems."/nix" = {
|
|
||||||
device = PRIMARY;
|
|
||||||
fsType = "bcachefs";
|
|
||||||
options = [
|
|
||||||
"X-mount.mkdir"
|
|
||||||
"X-mount.subdir=@nix"
|
|
||||||
"relatime"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
fileSystems."/.snapshots" = {
|
|
||||||
device = PRIMARY;
|
|
||||||
fsType = "bcachefs";
|
|
||||||
options = [
|
|
||||||
"X-mount.mkdir"
|
|
||||||
"X-mount.subdir=@root"
|
|
||||||
"relatime"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
# (optional) for preservation/impermanence
|
|
||||||
fileSystems."/persist" = {
|
|
||||||
device = PRIMARY;
|
|
||||||
fsType = "bcachefs";
|
|
||||||
options = [
|
|
||||||
"X-mount.mkdir"
|
|
||||||
"X-mount.subdir=@persist"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
# SWAP
|
# SWAP
|
||||||
{
|
swapDevices = [
|
||||||
swapDevices = [
|
# {
|
||||||
# {
|
# device = "/.swap/swapfile";
|
||||||
# device = "/.swap/swapfile";
|
# size = 8 * 1024; # Creates an 8GB swap file
|
||||||
# size = 8 * 1024; # Creates an 8GB swap file
|
# }
|
||||||
# }
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
# Disable bcachefs built in password prompts for all mounts (which asks for every single subdir mount above
|
|
||||||
{
|
|
||||||
boot.initrd.systemd.enable = true;
|
|
||||||
|
|
||||||
# https://github.com/NixOS/nixpkgs/blob/6cdf2f456a57164282ede1c97fc5532d9dba1ee0/nixos/modules/tasks/filesystems/bcachefs.nix#L254-L259
|
# PRIMARY Bcache utilities
|
||||||
systemd.services =
|
boot.initrd.systemd.enable = true;
|
||||||
# let
|
boot.supportedFilesystems = [
|
||||||
# isSystemdNonBootBcache = v: (v.fsType == "bcachefs") && (!utils.fsNeededForBoot v);
|
"bcachefs"
|
||||||
# bcacheNonBoots = lib.filterAttrs (k: v: isSystemdNonBootBcache v) config.fileSystems;
|
"vfat"
|
||||||
# in
|
];
|
||||||
# (lib.mapAttrs (k: v: { enable = false; }) bcacheNonBoots);
|
|
||||||
{
|
|
||||||
# NOTE that neededForBoot fs's dont end up in this list
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/.old_roots"}".enable = false;
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/.snapshots"}".enable = false;
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/.swap"}".enable = false;
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/persist"}".enable = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
# https://github.com/NixOS/nixpkgs/blob/6cdf2f456a57164282ede1c97fc5532d9dba1ee0/nixos/modules/tasks/filesystems/bcachefs.nix#L291
|
systemd.services = {
|
||||||
boot.initrd.systemd.services =
|
# NOTE that neededForBoot fs's dont end up in this list
|
||||||
# let
|
"unlock-bcachefs-${escapeSystemdPath "/.old_roots"}".enable = false;
|
||||||
# isSystemdBootBcache = v: (v.fsType == "bcachefs") && (utils.fsNeededForBoot v);
|
"unlock-bcachefs-${escapeSystemdPath "/.snapshots"}".enable = false;
|
||||||
# bcacheBoots = lib.filterAttrs (k: v: isSystemdBootBcache v) config.fileSystems;
|
"unlock-bcachefs-${escapeSystemdPath "/.swap"}".enable = false;
|
||||||
# in
|
"unlock-bcachefs-${escapeSystemdPath "/persist"}".enable = false;
|
||||||
# (lib.mapAttrs (k: v: { enable = false; }) bcacheBoots);
|
};
|
||||||
{
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/sysroot"}".enable = false;
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/"}".enable = false;
|
|
||||||
"unlock-bcachefs-${escapeSystemdPath "/nix"}".enable = false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
# Bcachefs auto decryption
|
|
||||||
{
|
|
||||||
boot.supportedFilesystems = [
|
|
||||||
"bcachefs"
|
|
||||||
];
|
|
||||||
|
|
||||||
# boot.initrd.systemd.mounts = [
|
# 1. Disable the automatically generated unlock services
|
||||||
# {
|
boot.initrd.systemd.services = {
|
||||||
# what = USB_KEY;
|
"unlock-bcachefs-${escapeSystemdPath "/sysroot"}".enable = false; # special always on one
|
||||||
# type = "bcachefs";
|
"unlock-bcachefs-${escapeSystemdPath "/"}".enable = false;
|
||||||
# where = "/usb_key";
|
"unlock-bcachefs-${escapeSystemdPath "/nix"}".enable = false;
|
||||||
# options = "ro";
|
|
||||||
# description = "key";
|
# 2. Your single custom unlock unit
|
||||||
# wantedBy = [
|
unlock-bcachefs-custom = {
|
||||||
# "initrd.target"
|
|
||||||
# ];
|
|
||||||
# }
|
|
||||||
# ];
|
|
||||||
boot.initrd.systemd.services.unlock-bcachefs-custom = {
|
|
||||||
description = "Custom single bcachefs unlock for all subvolumes";
|
description = "Custom single bcachefs unlock for all subvolumes";
|
||||||
|
|
||||||
wantedBy = [ "initrd.target" ];
|
wantedBy = [ "initrd.target" ];
|
||||||
|
|
@ -141,79 +108,50 @@ lib.mkMerge [
|
||||||
|
|
||||||
requires = [ primaryDeviceUnit ];
|
requires = [ primaryDeviceUnit ];
|
||||||
after = [ primaryDeviceUnit ];
|
after = [ primaryDeviceUnit ];
|
||||||
|
|
||||||
|
# NOTE: put the real password here, or better: read it from USB_KEY
|
||||||
|
# ExecStart = ''
|
||||||
|
# /bin/sh -c 'echo "password" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock ${PRIMARY}'
|
||||||
|
# '';
|
||||||
|
# ExecStart = ''
|
||||||
|
# /bin/sh -c 'mount --mkdir -o ro ${USB_KEY} /key && \
|
||||||
|
# cat /key/bcachefs.key | ${pkgs.bcachefs-tools}/bin/bcachefs unlock ${PRIMARY}'
|
||||||
|
# '';
|
||||||
|
|
||||||
|
# We inline a script that roughly mimics tryUnlock + openCommand behavior,
|
||||||
|
# but uses a key file from the USB stick instead of systemd-ask-password.
|
||||||
script = ''
|
script = ''
|
||||||
echo "Using test password..."
|
echo "Using USB key for bcachefs unlock: ${USB_KEY}"
|
||||||
echo "test" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock "${PRIMARY}"
|
mount -t bcachefs --mkdir "${USB_KEY}" /usb_key
|
||||||
|
${pkgs.bcachefs-tools}/bin/bcachefs unlock -f /usb_key/key "${PRIMARY}"
|
||||||
echo "bcachefs unlock successful for ${PRIMARY}"
|
echo "bcachefs unlock successful for ${PRIMARY}"
|
||||||
'';
|
'';
|
||||||
# script = ''
|
# Hard code password (useless in real env)
|
||||||
# echo "Using USB key for bcachefs unlock: ${USB_KEY}"
|
# echo "test" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock "${PRIMARY}"
|
||||||
#
|
|
||||||
# echo "test" | ${pkgs.bcachefs-tools}/bin/bcachefs unlock "${PRIMARY}"
|
|
||||||
# echo "done...."
|
|
||||||
# exit 0
|
|
||||||
#
|
|
||||||
# # only try mount if the node exists
|
|
||||||
# if [ ! -e "${USB_KEY}" ]; then
|
|
||||||
# echo "USB key device ${USB_KEY} not present in initrd"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
# ${pkgs.bcachefs-tools}/bin/bcachefs unlock -f /usb_key/key "${PRIMARY}"
|
|
||||||
# echo "bcachefs unlock successful for ${PRIMARY}"
|
|
||||||
# '';
|
|
||||||
};
|
|
||||||
|
|
||||||
# TODO rotate root
|
};
|
||||||
}
|
};
|
||||||
# Reset root for erase your darlings/impermanence/preservation
|
|
||||||
{
|
# TODO this works for resetting root!
|
||||||
# boot.initrd.systemd.services.bcachefs-reset-root = {
|
# boot.initrd.postResumeCommands = lib.mkAfter ''
|
||||||
# description = "Reset bcachefs root subvolume before pivot";
|
# echo "test" | bcachefs unlock ${PRIMARY}
|
||||||
# wantedBy = [ "initrd.target" ];
|
#
|
||||||
#
|
# mkdir /primary_tmp
|
||||||
# after = [
|
# mount ${PRIMARY} primary_tmp/
|
||||||
# "initrd-root-device.target"
|
# if [[ -e /primary_tmp/@root ]]; then
|
||||||
# "cryptsetup.target"
|
# mkdir -p /primary_tmp/@old_roots
|
||||||
# "unlock-bcachefs-custom"
|
# bcachefs set-file-option /primary_tmp/@old_roots --compression=zstd
|
||||||
# ];
|
#
|
||||||
# requires = [ primaryDeviceUnit ];
|
# timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S")
|
||||||
#
|
# bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@old_roots/$timestamp"
|
||||||
# serviceConfig = {
|
# bcachefs subvolume delete /primary_tmp/@root
|
||||||
# Type = "oneshot";
|
# fi
|
||||||
# # initrd has a minimal PATH; set one explicitly
|
#
|
||||||
# Environment = "PATH=/bin:/sbin:/usr/bin:/usr/sbin";
|
# for i in $(find /primary_tmp/old_roots/ -maxdepth 1 -mtime +30); do
|
||||||
# # If tools are in /usr, this helps ensure it's in the initrd
|
# bcachefs subvolume delete "$i"
|
||||||
# # (you may also need environment.systemPackages + boot.initrd.includeDefaultModules)
|
# done
|
||||||
# ExecStart = pkgs.writeShellScript "bcachefs-reset-root" ''
|
#
|
||||||
# set -euo pipefail
|
# bcachefs subvolume create /primary_tmp/@root
|
||||||
#
|
# umount /primary_tmp
|
||||||
# PRIMARY=${PRIMARY}
|
# '';
|
||||||
#
|
}
|
||||||
# echo "Unlocking bcachefs volume ${PRIMARY}..."
|
|
||||||
# echo "test" | bcachefs unlock "''${PRIMARY}"
|
|
||||||
#
|
|
||||||
# mkdir -p /primary_tmp
|
|
||||||
# mount "''${PRIMARY}" /primary_tmp
|
|
||||||
#
|
|
||||||
# if [[ -e /primary_tmp/@root ]]; then
|
|
||||||
# mkdir -p /primary_tmp/@old_roots
|
|
||||||
# bcachefs set-file-option /primary_tmp/@old_roots --compression=zstd
|
|
||||||
#
|
|
||||||
# timestamp=$(date --date="@$(stat -c %Y /primary_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S")
|
|
||||||
# bcachefs subvolume snapshot /primary_tmp/@root "/primary_tmp/@old_roots/$timestamp"
|
|
||||||
# bcachefs subvolume delete /primary_tmp/@root
|
|
||||||
#
|
|
||||||
# # Cleanup old snapshots (>30 days)
|
|
||||||
# # Note: path was /primary_tmp/old_roots in your snippet; using @old_roots for consistency
|
|
||||||
# for i in $(find /primary_tmp/@old_roots/ -maxdepth 1 -mtime +30); do
|
|
||||||
# bcachefs subvolume delete "$i"
|
|
||||||
# done
|
|
||||||
# fi
|
|
||||||
#
|
|
||||||
# bcachefs subvolume create /primary_tmp/@root
|
|
||||||
# umount /primary_tmp
|
|
||||||
# '';
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@
|
||||||
token = "20208198-87c2-4bd1-ab09-b97c3b9c6a6e";
|
token = "20208198-87c2-4bd1-ab09-b97c3b9c6a6e";
|
||||||
};
|
};
|
||||||
services.beszel.agent.environment = {
|
services.beszel.agent.environment = {
|
||||||
EXTRA_FILESYSTEMS = "nvme0n1p1__nvme1tb";
|
EXTRA_FILESYSTEMS = "nvme0n1__nvme1tb";
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ or from host machine? TODO haven't tried this fully
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
NIX_SSHOPTS="-i /run/agenix/nix2nix" sudo nixos-rebuild switch --flake "git+https://git.joshuabell.xyz/ringofstorms/dotfiles?dir=hosts/i001#i001" --target-host luser@10.12.14.157 --build-host localhost
|
NIX_SSHOPTS="-i /run/agenix/nix2nix" sudo nixos-rebuild switch --flake "git+https://git.joshuabell.xyz/ringofstorms/dotfiles?dir=hosts/i001#i001" --target-host luser@10.12.14.157 --build-host localhost
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## USB Key
|
## USB Key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue