launchd: fix user domain agents

User-domain agents need the Background session type to bootstrap into user/501, and activation should fail rather than silently unloading services when launchctl bootstrap fails.
This commit is contained in:
Austin Horstman 2026-06-30 23:17:56 -05:00
parent 2a37d71bbe
commit 2f3da3d45f
30 changed files with 208 additions and 28 deletions

View file

@ -11,6 +11,8 @@
nmt.script = ''
serviceFile=LaunchAgents/org.nix-community.home.user-service.plist
assertFileExists $serviceFile
assertFileContains $serviceFile '<key>LimitLoadToSessionType</key>'
assertFileContains $serviceFile '<string>Background</string>'
domainFile=LaunchAgentDomains/org.nix-community.home.user-service.domain
assertFileExists $domainFile

View file

@ -30,8 +30,19 @@
assertFileExists activate
assertFileContains activate 'readAgentDomain'
assertFileContains activate 'resolveDomain'
assertFileContains activate 'agentIsLoaded'
assertFileContains activate 'if agentIsLoaded "$newDomain" "$agentName"; then'
assertFileContains activate 'is up-to-date but not loaded'
assertFileContains activate "printf 'gui/%s"
assertFileContains activate "printf 'user/%s"
assertFileContains activate 'restoreAgent "$oldSrcPath" "$dstPath" "$oldDomain" "$agentName"'
assertFileContains activate 'bootoutAgent "$newDomain" "$agentName"'
assertFileContains activate 'processAgent "$srcPath" "$dstDir" "$oldDir" "$oldDomainsDir" "$newDomainsDir" \'
assertFileContains activate '|| launchdStatus=1'
assertFileContains activate 'done < <(find -L "$newDir" -maxdepth 1 -name'
assertFileContains activate 'done < <(find -L "$oldDir" -maxdepth 1 -name'
assertFileContains activate 'if [[ "$launchdStatus" -ne 0 ]]; then'
assertFileContains activate 'exit "$launchdStatus"'
'';
};
}

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.git-maintenance-daily</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.git-maintenance-hourly</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.git-maintenance-weekly</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.nh-clean</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.opencode-web</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.opencode-web</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.borgmatic</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -22,6 +22,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.colima-default</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -18,6 +18,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.colima-default</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.emacs</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.git-sync-test</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -18,6 +18,8 @@
serviceFile=$(normalizeStorePaths $serviceFile)
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./glance.plist}
assertFileContains "$serviceFile" '<key>LimitLoadToSessionType</key>'
assertFileContains "$serviceFile" '<string>Background</string>'
domainFile=LaunchAgentDomains/org.nix-community.home.glance.domain
assertFileContent "$domainFile" ${builtins.toFile "expected-domain" "user\n"}

View file

@ -6,6 +6,8 @@
<true/>
<key>Label</key>
<string>org.nix-community.home.glance</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -16,6 +16,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.gpg-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.home-manager-auto-expire</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -13,6 +13,8 @@
<true/>
<key>Label</key>
<string>org.nix-community.home.imapnotify-hm-example.com</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -4,6 +4,8 @@
<dict>
<key>Label</key>
<string>org.nix-community.home.nix-gc</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>

View file

@ -20,6 +20,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.ollama</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.podman-machine-podman-machine-default</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.podman-machine-dev-machine</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -6,6 +6,8 @@
<true/>
<key>Label</key>
<string>org.nix-community.home.proton-pass-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -6,6 +6,8 @@
<true/>
<key>Label</key>
<string>org.nix-community.home.proton-pass-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.ssh-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.ssh-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.ssh-agent</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -11,6 +11,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.syncthing</string>
<key>LimitLoadToSessionType</key>
<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>

View file

@ -23,6 +23,8 @@
</dict>
<key>Label</key>
<string>org.nix-community.home.yubikey-agent</string>
${"\t"}<key>LimitLoadToSessionType</key>
${"\t"}<string>Background</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>