mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-31 04:04:45 +00:00
I’m not *completely* certain that this handles user agents correctly. There is a deprecated command, `launchctl asuser`, that executes a command in the Mach bootstrap context of another user`. <https://scriptingosx.com/2020/08/running-a-command-as-another-user/> claims that this is required when loading and unloading user agents, but I haven’t tested this. Our current launchd agent logic is pretty weird and broken already anyway, so unless this actively regresses things I’d lean towards keeping it like this until we can move over entirely to `launchctl bootstrap`/`launchctl kickstart`, which aren’t deprecated and can address individual users directly. Someone should definitely test it more extensively than I have, though.
19 lines
831 B
Nix
19 lines
831 B
Nix
{ config, pkgs, ... }:
|
|
|
|
{
|
|
system.primaryUser = "test-launchd-user";
|
|
|
|
launchd.daemons.foo.command = "foo";
|
|
launchd.agents.bar.command = "bar";
|
|
launchd.user.agents.baz.command = "baz";
|
|
|
|
test = ''
|
|
echo "checking launchd load in /activate" >&2
|
|
grep "launchctl load .* '/Library/LaunchDaemons/org.nixos.foo.plist" ${config.out}/activate
|
|
grep "launchctl load .* '/Library/LaunchAgents/org.nixos.bar.plist" ${config.out}/activate
|
|
echo "checking launchd user agent load in /activate" >&2
|
|
grep "sudo --user=test-launchd-user -- launchctl load .* ~test-launchd-user/Library/LaunchAgents/org.nixos.baz.plist" ${config.out}/activate
|
|
echo "checking LaunchAgents creation /activate" >&2
|
|
grep "sudo --user=test-launchd-user -- mkdir -p ~test-launchd-user/Library/LaunchAgents" ${config.out}/activate
|
|
'';
|
|
}
|