From 12e0e05ea6505d47807eb7f08e12f9458b0c786a Mon Sep 17 00:00:00 2001 From: clover caruso Date: Wed, 28 Oct 2026 01:03:08 -0700 Subject: [PATCH] Move Knife Linux storage to the work SSD Keep the container store and home encrypted, and stop binding the retired shared workspace. Assisted-by: gpt-6.1-terra --- nixos/knife-linux.Containerfile | 2 +- nixos/knife-linux.nix | 32 +++++++++++++++--- nixos/tests/knife-linux-storage.nix | 50 +++++++++++++++++++++++++++++ tools/knife-linux.md | 16 +++------ 4 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 nixos/tests/knife-linux-storage.nix diff --git a/nixos/knife-linux.Containerfile b/nixos/knife-linux.Containerfile index 2546c21d1aedb4515ca0854e18a972615c918516..161879b1705893f9dea5d4aa7cc94cea4c499265 100644 --- a/nixos/knife-linux.Containerfile +++ b/nixos/knife-linux.Containerfile @@ -29,5 +29,5 @@ ARG GID RUN groupadd --gid "$GID" chloe && useradd --uid "$UID" --gid "$GID" --no-create-home --home-dir /home/clo clo USER clo ENV HOME=/home/clo LANG=C.UTF-8 PATH=/home/clo/.local/bin:/usr/local/bin:/usr/bin:/bin -WORKDIR /Volumes/Code/project +WORKDIR /work/knife ENTRYPOINT ["/home/clo/.local/bin/knife", "start", "--mode", "desktop", "--host", "127.0.0.1", "--port", "3773", "--no-browser"] diff --git a/nixos/knife-linux.nix b/nixos/knife-linux.nix index 73b7e5fe3f6ae6472b217c458c6d639589a05d34..d8736d1abf8010a9cc8e55730764c823dd7d987d 100644 --- a/nixos/knife-linux.nix +++ b/nixos/knife-linux.nix @@ -1,6 +1,5 @@ { config, lib, pkgs, ... }: let - sandbox = (builtins.fromJSON (builtins.readFile ../config/mac-studio-sandbox.json)).mountPoint; root = "/srv/knife-linux"; uid = toString config.users.users.clo.uid; gid = toString config.users.groups.chloe.gid; @@ -23,19 +22,43 @@ in { environment.systemPackages = [ podman ]; + systemd.services.knife-linux-storage = { + requires = [ "zfs-import-work.service" "dev-tpmrm0.device" ]; + after = [ "zfs-import-work.service" "zfs-mount.service" "dev-tpmrm0.device" ]; + before = [ "knife-linux.service" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + LoadCredentialEncrypted = "zfs-clover:/etc/credstore.encrypted/zfs-clover"; + }; + script = '' + test "$(${pkgs.zfs}/bin/zfs get -H -o value encryptionroot work/knife-linux)" = work/knife-linux + test "$(${pkgs.zfs}/bin/zfs get -H -o value mountpoint work/knife-linux)" = ${root} + if test "$(${pkgs.zfs}/bin/zfs get -H -o value keystatus work/knife-linux)" = unavailable; then + ${pkgs.zfs}/bin/zfs load-key -L "file://$CREDENTIALS_DIRECTORY/zfs-clover" work/knife-linux + fi + if test "$(${pkgs.zfs}/bin/zfs get -H -o value mounted work/knife-linux)" != yes; then + ${pkgs.zfs}/bin/zfs mount work/knife-linux + fi + test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${root})" = work/knife-linux + ''; + }; + systemd.services.knife-linux = { description = "The Knife Linux agent container"; wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; - after = [ "network-online.target" "mac-studio-sandbox.service" "zfs-import-work.service" "zfs-mount.service" ]; - requires = [ "mac-studio-sandbox.service" "zfs-import-work.service" ]; + after = [ "network-online.target" "knife-linux-storage.service" ]; + requires = [ "knife-linux-storage.service" ]; # Restarting stops every running agent, so changes wait for a manual restart. restartIfChanged = false; serviceConfig = { Type = "notify"; NotifyAccess = "all"; ExecStartPre = [ - "${pkgs.util-linux}/bin/mountpoint -q ${root}" + (pkgs.writeShellScript "check-knife-root" '' + test "$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint ${root})" = work/knife-linux + '') checkWork "${run} build --quiet --build-arg=UID=${uid} --build-arg=GID=${gid} --tag=localhost/knife-linux --file=${./knife-linux.Containerfile} /var/empty" ]; @@ -45,7 +68,6 @@ in "--user=${uid}:${gid} --umask=0077 --cap-drop=ALL --security-opt=no-new-privileges" "--memory=96g --pids-limit=32768 --shm-size=2g --network=podman" "--volume=${root}/home:/home/clo" - "--volume=${sandbox}:/Volumes/Code" "--volume=/srv/work:/work" "--volume=/opt/studio-project-store/current/bin/jj-real:/usr/local/bin/jj:ro" "--device=/dev/kvm" diff --git a/nixos/tests/knife-linux-storage.nix b/nixos/tests/knife-linux-storage.nix new file mode 100644 index 0000000000000000000000000000000000000000..7a6a91b1b64e168b5c0622560a465c9a03c973f0 --- /dev/null +++ b/nixos/tests/knife-linux-storage.nix @@ -0,0 +1,50 @@ +{ pkgs }: +pkgs.testers.runNixOSTest { + name = "knife-linux-storage"; + nodes.machine = { lib, ... }: { + imports = [ ../knife-linux.nix ]; + virtualisation = { memorySize = 2048; cores = 2; emptyDiskImages = [ 2048 2048 ]; }; + networking.hostId = "a1b2c3d4"; + boot.supportedFilesystems = [ "zfs" ]; + boot.zfs.forceImportRoot = false; + users.groups.chloe.gid = 3000; + users.users.clo = { isSystemUser = true; uid = 3000; group = "chloe"; }; + environment.systemPackages = [ pkgs.zfs pkgs.util-linux pkgs.rsync pkgs.acl pkgs.attr ]; + systemd.services.knife-linux.wantedBy = lib.mkForce [ ]; + systemd.services.knife-linux-storage = { + requires = lib.mkForce [ ]; + after = lib.mkForce [ ]; + serviceConfig = { + LoadCredentialEncrypted = lib.mkForce [ ]; + LoadCredential = "zfs-clover:/run/test-key"; + }; + }; + }; + testScript = '' + start_all() + machine.succeed("head -c 32 /dev/urandom | od -An -v -tx1 | tr -d ' \\n' > /run/test-key; chmod 600 /run/test-key") + machine.succeed("zpool create -O mountpoint=none globe /dev/vdb") + machine.succeed("zpool create -O mountpoint=none work /dev/vdc") + machine.succeed("zfs create -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///run/test-key -o mountpoint=/source globe/clover") + machine.succeed("zfs create -o mountpoint=/srv/knife-linux -o casesensitivity=sensitive -o acltype=posix -o xattr=sa globe/clover/knife-linux") + machine.succeed("mkdir -p /srv/knife-linux/home/.knife/userdata /srv/knife-linux/home/.local/bin; echo initial > /srv/knife-linux/home/.knife/userdata/state; echo launcher > /srv/knife-linux/home/.local/bin/knife; echo excluded > /srv/knife-linux/home/excluded") + machine.succeed("chown 3000:3000 /srv/knife-linux/home/.knife/userdata/state; setfacl -m u:3000:rw /srv/knife-linux/home/.knife/userdata/state; setfattr -n user.fixture -v retained /srv/knife-linux/home/.knife/userdata/state") + machine.succeed("zfs create -o encryption=aes-256-gcm -o keyformat=hex -o keylocation=file:///run/test-key -o mountpoint=/target -o casesensitivity=sensitive -o acltype=posix -o xattr=sa work/knife-linux") + machine.succeed("mkdir -p /target/home/.local/bin; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.knife /target/home/; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.local/bin/knife /target/home/.local/bin/") + machine.succeed("echo final > /srv/knife-linux/home/.knife/userdata/state; rsync -aAX --numeric-ids --no-specials /srv/knife-linux/home/.knife /target/home/") + machine.succeed("zfs unmount globe/clover/knife-linux; zfs set mountpoint=none globe/clover/knife-linux; zfs unmount work/knife-linux; zfs unload-key work/knife-linux; zfs set mountpoint=/srv/knife-linux work/knife-linux") + assert machine.succeed("zfs get -H -o value encryptionroot work/knife-linux").strip() == "work/knife-linux" + machine.succeed("systemctl start knife-linux-storage.service") + assert machine.succeed("cat /srv/knife-linux/home/.knife/userdata/state").strip() == "final" + assert machine.succeed("stat -c '%u:%g' /srv/knife-linux/home/.knife/userdata/state").strip() == "3000:3000" + assert machine.succeed("getfattr -n user.fixture --only-values /srv/knife-linux/home/.knife/userdata/state").strip() == "retained" + assert "user:clo:rw-" in machine.succeed("getfacl /srv/knife-linux/home/.knife/userdata/state") + machine.fail("test -e /srv/knife-linux/home/excluded") + assert machine.succeed("findmnt -n -o SOURCE --mountpoint /srv/knife-linux").strip() == "work/knife-linux" + machine.succeed("systemctl stop knife-linux-storage.service; zfs unmount work/knife-linux; zfs unload-key work/knife-linux") + machine.succeed("systemctl start knife-linux-storage.service") + assert machine.succeed("cat /srv/knife-linux/home/.knife/userdata/state").strip() == "final" + machine.succeed("systemctl stop knife-linux-storage.service; zfs unmount work/knife-linux; zfs set mountpoint=/wrong work/knife-linux") + machine.fail("systemctl start knife-linux-storage.service") + ''; +} diff --git a/tools/knife-linux.md b/tools/knife-linux.md index 00a0cddfbb3dea6184b695c0bfa66d6ff92e379d..3fc588603b8c8d744df4cf5b02bc115d75f4911f 100644 --- a/tools/knife-linux.md +++ b/tools/knife-linux.md @@ -23,21 +23,15 @@ added to the running container. | Container path | Host source | | --- | --- | -| `/Volumes/Code` | the Mac VM's NFS export, `/srv/mac-studio-vm/sandbox` | | `/work` | the unencrypted, uncompressed `work` SSD pool, `/srv/work` | -| `/home/clo` | `/srv/knife-linux/home` on `globe/clover/knife-linux` | +| `/home/clo` | `/srv/knife-linux/home` on encrypted `work/knife-linux` | | `/usr/local/bin/jj` | the storage host's `jj-real`, read-only | -Projects keep the Mac VM's paths, so jj workspaces, Knife project paths, and -Claude memory keys match on both. A workspace's `node_modules` serves one OS at -a time; run `vp i` after moving a workspace between them. pnpm's global config -uses the storage host's `/Volumes/Code/cache/pnpm12` store and `files` index -format. jj per-repo configs in `~/.config/jj/repos` are copies of the Mac VM's, -keyed by each repository's `config-id`. +jj per-repo configs in `~/.config/jj/repos` are copies of the Mac VM's, keyed +by each repository's `config-id`. -`globe/clover/knife-linux` must stay case-sensitive. Its parent is not, and -Fedora packages and overlay layers fail under case folding. Podman's store lives -on this dataset because the root NVMe is nearly full. `knife-linux-podman` is the +`work/knife-linux` must stay case-sensitive for Fedora packages and overlay +layers. `knife-linux-podman` is the only entry point to that store: it pins a separate temp directory and file locks, because a second rootful store sharing Nomad's lock segment would free the other store's locks during its post-reboot refresh. -- 2.54.1