{ lib, ... }: let inherit (lib.my) net; inherit (lib.my.c.home) domain prefixes vips; in { nixos.systems.slop-cannon = { system = "x86_64-linux"; nixpkgs = "mine"; home-manager = "mine"; # The routers limit traffic from the untrusted VLAN to the Internet assignments.untrusted = { inherit domain; mtu = prefixes.untrusted.mtu; ipv4 = { address = net.cidr.host 5 prefixes.untrusted.v4; mask = 24; gateway = vips.untrusted.v4; }; ipv6 = { iid = "::5"; address = net.cidr.host 5 prefixes.untrusted.v6; }; }; configuration = { lib, modulesPath, config, pkgs, assignments, ... }: let inherit (builtins) toJSON; inherit (lib) mkMerge; inherit (lib.my) networkdAssignment; agentUser = "slop-cannon"; agentHome = "/home/${agentUser}"; giteaKey = config.age.secrets."slop-cannon/gitea-key".path; paseoPasswordFile = config.age.secrets."slop-cannon/paseo.env".path; # Steer agents to the approval broker; these match command text, so they aren't a boundary claudeDeny = [ "Bash(deploy:*)" "Bash(ssh-machine:*)" "Read(**/.keys/**)" "Edit(**/.keys/**)" ]; claudeAsk = [ "Bash(slop-deploy:*)" "Bash(slop-ssh:*)" ]; slopClone = pkgs.writeShellApplication { name = "slop-clone"; runtimeInputs = with pkgs; [ jujutsu openssh paseo ]; text = '' if [ $# -ne 1 ] || [[ "$1" != */* ]]; then echo "usage: slop-clone /" >&2 exit 1 fi repo="$1" dest="$HOME/src/''${repo##*/}" if ! jj git clone --colocate "git@git.nul.ie:$repo.git" "$dest"; then echo >&2 echo "Clone failed. If Gitea refused the key, add it as a write-enabled deploy key on $repo:" >&2 ssh-keygen -y -f ${giteaKey} >&2 exit 1 fi paseo workspace create --isolation local --path "$dest" ''; }; slopPair = pkgs.writeShellApplication { name = "slop-pair"; runtimeInputs = [ pkgs.paseo ]; text = '' if [ "$#" -ne 0 ]; then echo "usage: slop-pair" >&2 exit 2 fi paseo daemon pair printf '\n' exec doas ${pkgs.coreutils}/bin/cat ${paseoPasswordFile} ''; }; in { imports = [ "${modulesPath}/profiles/qemu-guest.nix" ]; config = { boot = { # Load the passed-through ConnectX VF even when PCI probing doesn't autoload it. kernelModules = [ "kvm-amd" "mlx5_core" ]; kernelParams = [ "console=ttyS0,115200n8" ]; initrd = { availableKernelModules = [ "virtio_pci" "ahci" "sr_mod" "virtio_blk" ]; kernelModules = [ "dm-snapshot" ]; }; # On disk rather than in the tmpfs root, so agents' scratch files don't use RAM tmp.cleanOnBoot = true; }; hardware = { enableRedistributableFirmware = true; }; fileSystems = { "/boot" = { device = "/dev/disk/by-partlabel/esp"; fsType = "vfat"; }; "/nix" = { device = "/dev/main/slop-cannon-nix"; fsType = "ext4"; }; "/persist" = { device = "/dev/main/slop-cannon-persist"; fsType = "ext4"; neededForBoot = true; }; "/tmp" = { device = "/dev/main/slop-cannon-tmp"; fsType = "ext4"; # Return deleted scratch space to the thin pool straight away options = [ "discard" ]; }; }; networking = { inherit domain; }; services = { # The LVs are thin, so space moves between them as needed lvm = { boot.thin.enable = true; dmeventd.enable = true; }; fstrim.enable = true; }; # Grow the pool into the VG's spare space before it fills environment.etc."lvm/lvm.conf".text = '' activation/thin_pool_autoextend_threshold = 80 activation/thin_pool_autoextend_percent = 10 ''; my = { server.enable = true; # Root inside this VM belongs to the agents, so it gets no shared secrets: in particular # not `user-passwd.txt` user = { passwordSecret = null; config = { password = null; hashedPassword = "!"; }; }; secrets = { key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBCkgBZh/YejY+gDnGa9r5SPo1+aHWPAAAIfENE7t0Om"; files = { "slop-cannon/gitea-key".owner = agentUser; # `PASEO_PASSWORD=...` "slop-cannon/paseo.env" = { }; }; }; tmproot.persistence.config.directories = [ { directory = agentHome; user = agentUser; group = agentUser; mode = "0700"; } ]; }; users = with lib.my.c.ids; { groups.${agentUser}.gid = gids.slop-cannon; users.${agentUser} = { isNormalUser = true; uid = uids.slop-cannon; group = agentUser; # Agents get root (passwordless `doas`) and can run nested VMs extraGroups = [ "wheel" "kvm" ]; hashedPassword = "!"; shell = pkgs.fish; openssh.authorizedKeys.keyFiles = [ lib.my.c.sshKeyFiles.me ]; }; }; home-manager.users.${agentUser} = { my.agents.enable = true; home.packages = [ slopClone slopPair ]; programs = { claude-code.settings.permissions = { deny = claudeDeny; ask = claudeAsk; }; codex.settings.cli_auth_credentials_store = "file"; # The shared config pins `IdentityFile` for every host ssh.settings."git.nul.ie" = { IdentityFile = [ giteaKey ]; }; }; }; # Not editable by the agent user without `doas`; a convenience, not a boundary environment.etc."claude-code/managed-settings.json".text = toJSON { permissions = { disableBypassPermissionsMode = "disable"; deny = claudeDeny; }; }; systemd = { network = { links = { "10-lan-untrusted" = { matchConfig = { Driver = "mlx5_core"; PermanentMACAddress = "52:54:00:71:22:ea"; }; linkConfig = { Name = "lan-untrusted"; MTUBytes = toString prefixes.untrusted.mtu; }; }; }; networks = { "80-lan-untrusted" = mkMerge [ (networkdAssignment "lan-untrusted" assignments.untrusted) { # As `untrusted`'s DHCP and RAs hand out; the routers' resolvers aren't reachable networkConfig.DNS = [ "1.1.1.1" "1.0.0.1" "2606:4700:4700::1111" "2606:4700:4700::1001" ]; } ]; }; }; services = { paseo = { unitConfig.RequiresMountsFor = agentHome; serviceConfig.EnvironmentFile = paseoPasswordFile; # Don't interrupt running agents on deploy; restart by hand when convenient restartIfChanged = false; }; }; }; services.paseo = { enable = true; package = pkgs.paseo; user = agentUser; group = agentUser; listenAddress = "127.0.0.1"; port = 6767; relay = { enable = true; mode = "remote"; host = "paseo-relay.${lib.my.c.pubDomain}"; port = 443; useTls = true; }; # Rewritten on every start, so changes made from the app don't survive a restart settings = { version = 1; # Pairing links open our copy of the web app (served by `middleman`) app.baseUrl = "https://paseo.${lib.my.c.pubDomain}"; daemon = { # Keep agents from changing modes, answering prompts or opening terminals mcp.injectIntoAgents = false; relay.requireProtectedSecurity = true; agentProfiles = [ { id = "claude-accept-edits"; name = "Claude, accept edits"; provider = "claude"; modeId = "acceptEdits"; } ]; }; # Avoids downloading the local speech model features = { dictation.enabled = false; voiceMode.enabled = false; }; agents.providers = lib.genAttrs [ "copilot" "opencode" "pi" "omp" "antigravity" "muse" ] (_: { enabled = false; }); log.file.level = "info"; }; }; }; }; }; }