From 95c23de0d7fa75ab6eda02ec197b851e36125fbd Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 18:53:00 +0000 Subject: xchg: mount on first access instead of at boot The socat-and-mount dance moves from a boot service into the mount helper mount.xchg, so /xchg can be an x-systemd.automount like before. No more modules-load of the vsock transport either: udev loads it for the device, and it's built in into the cut-down kernel. --- default.nix | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 20a26d2..445ddfd 100644 --- a/default.nix +++ b/default.nix @@ -38,22 +38,24 @@ let fsType = "erofs"; options = [ "ro" "nodev" "nosuid" ]; }; - # /xchg: the host's ./xchg via 9P over vsock, see the run script. - # The kernel's 9P client can't do vsock itself, but it can use the fds - # of a connected socket (trans=fd), which socat passes to mount as - # stdin and stdout (nofork). Separate -o options, as socat would take - # commas as its own option separators. - boot.kernelModules = [ "vmw_vsock_virtio_transport" ]; - systemd.services.xchg = { - wantedBy = [ "multi-user.target" ]; - serviceConfig.Type = "oneshot"; - serviceConfig.RemainAfterExit = true; - path = [ pkgs.socat pkgs.util-linux ]; - script = '' - mkdir -p /xchg - socat VSOCK-CONNECT:2:564 EXEC:"mount -t 9p -o trans=fd -o rfdno=0 -o wfdno=1 -o version=9p2000.L xchg /xchg",nofork - ''; + # /xchg: the host's ./xchg via 9P over vsock, see the run script, + # mounted on first access. The kernel's 9P client can't do vsock + # itself, but it can use the fds of a connected socket (trans=fd), so + # the mount goes through the helper mount.xchg: socat connects and + # passes the socket to mount as stdin and stdout (nofork). Separate + # -o options, as socat would take commas as its own option separators. + fileSystems."/xchg" = { + device = "xchg"; + fsType = "xchg"; + noCheck = true; + options = [ "x-systemd.automount" "nofail" ]; }; + system.fsPackages = [ + (pkgs.writeShellScriptBin "mount.xchg" '' + # usage: mount.xchg SPEC DIR [-o OPTIONS] + exec ${pkgs.socat}/bin/socat VSOCK-CONNECT:2:564 EXEC:"${pkgs.util-linux}/bin/mount -t 9p -o trans=fd -o rfdno=0 -o wfdno=1 -o version=9p2000.L xchg $2",nofork + '') + ]; services.getty.autologinUser = "root"; systemd.targets.getty.wants = lib.mkForce [ ]; # no getty on tty1 -- cgit v1.3.1