From 2acea86583ba10b67b36db135c94d6df1ae41d55 Mon Sep 17 00:00:00 2001 From: midchildan Date: Thu, 23 Mar 2023 01:52:18 +0900 Subject: [PATCH 1/2] launchd: make Launch Agents config a freeform setting Because there probably are options we don't know about. --- modules/launchd/launchd.nix | 2 ++ tests/modules/launchd/agents.nix | 1 + tests/modules/launchd/expected-agent.plist | 2 ++ 3 files changed, 5 insertions(+) diff --git a/modules/launchd/launchd.nix b/modules/launchd/launchd.nix index 2e0e6585..27ddbf42 100644 --- a/modules/launchd/launchd.nix +++ b/modules/launchd/launchd.nix @@ -28,6 +28,8 @@ with lib; { + freeformType = with types; attrsOf anything; # added by Home Manager + options = { Label = mkOption { type = types.str; diff --git a/tests/modules/launchd/agents.nix b/tests/modules/launchd/agents.nix index cbcff6b5..ccf4f6e2 100644 --- a/tests/modules/launchd/agents.nix +++ b/tests/modules/launchd/agents.nix @@ -13,6 +13,7 @@ with lib; SuccessfulExit = false; }; ProcessType = "Background"; + UnrecognizedByHomeManager = "should make it to the resulting plist"; }; }; diff --git a/tests/modules/launchd/expected-agent.plist b/tests/modules/launchd/expected-agent.plist index c56ad4da..890b9933 100644 --- a/tests/modules/launchd/expected-agent.plist +++ b/tests/modules/launchd/expected-agent.plist @@ -19,5 +19,7 @@ --with-arguments foo + UnrecognizedByHomeManager + should make it to the resulting plist \ No newline at end of file From da325265b72b338647720b33df23d775aa73825d Mon Sep 17 00:00:00 2001 From: midchildan Date: Thu, 23 Mar 2023 01:54:11 +0900 Subject: [PATCH 2/2] launchd: sync option definition with nix-darwin --- modules/launchd/launchd.nix | 68 ++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/modules/launchd/launchd.nix b/modules/launchd/launchd.nix index 27ddbf42..4ecdad4e 100644 --- a/modules/launchd/launchd.nix +++ b/modules/launchd/launchd.nix @@ -1,7 +1,7 @@ # launchd option type from nix-darwin # # Original Source: -# https://github.com/LnL7/nix-darwin/blob/a34dea2/modules/launchd/launchd.nix +# https://github.com/LnL7/nix-darwin/blob/14a12e9/modules/launchd/launchd.nix # Copyright 2017 Daiderd Jordan # @@ -103,8 +103,8 @@ with lib; type = types.nullOr (types.listOf types.str); default = null; description = '' - This configuration file only applies to the hosts listed with this key. Note: One should set kern.host-name kern.hostname - name in sysctl.conf(5) for this feature to work reliably. + This configuration file only applies to the hosts listed with this key. Note: One should set kern.hostname + in sysctl.conf(5) for this feature to work reliably. ''; }; @@ -112,8 +112,8 @@ with lib; type = types.nullOr (types.listOf types.str); default = null; description = '' - This configuration file only applies to hosts NOT listed with this key. Note: One should set kern.host-name kern.hostname - name in sysctl.conf(5) for this feature to work reliably. + This configuration file only applies to hosts NOT listed with this key. Note: One should set kern.hostname + in sysctl.conf(5) for this feature to work reliably. ''; }; @@ -220,17 +220,21 @@ with lib; ''; }; - # NOTE: this was missing in the original source at the time of writing Crashed = mkOption { type = types.nullOr types.bool; default = null; description = '' If true, the the job will be restarted as long as it exited due to a signal which is typically - associated with a crash (SIGILL, SIGSEGV, etc.). If false, the job will be restarted in the inverse - condition. + associated with a crash (SIGILL, SIGSEGV, etc.). If false, the job will be restarted in the + inverse condition. ''; }; + AfterInitialDemand = mkOption { + type = types.nullOr types.bool; + default = null; + }; + }; })); default = null; @@ -242,7 +246,7 @@ with lib; multiple keys are provided, launchd ORs them, thus providing maximum flexibility to the job to refine the logic and stall if necessary. If launchd finds no reason to restart the job, it falls back on demand based invocation. Jobs that exit quickly and frequently when configured to be kept alive will - be throttled to conserve system resources. + be throttled to converve system resources. ''; }; @@ -518,8 +522,8 @@ with lib; default = null; description = '' The maximum number of open files for this process. Setting this value in a system wide daemon - will set the sysctl(3) kern.maxfiles (SoftResourceLimits) or kern.maxfilesperproc (HardResource-Limits) (HardResourceLimits) - Limits) value in addition to the setrlimit(2) values. + will set the sysctl(3) kern.maxfiles (SoftResourceLimits) or kern.maxfilesperproc (HardResourceLimits) + value in addition to the setrlimit(2) values. ''; }; @@ -610,8 +614,8 @@ with lib; default = null; description = '' The maximum number of open files for this process. Setting this value in a system wide daemon - will set the sysctl(3) kern.maxfiles (SoftResourceLimits) or kern.maxfilesperproc (HardResource-Limits) (HardResourceLimits) - Limits) value in addition to the setrlimit(2) values. + will set the sysctl(3) kern.maxfiles (SoftResourceLimits) or kern.maxfilesperproc (HardResourceLimits) + value in addition to the setrlimit(2) values. ''; }; @@ -688,7 +692,7 @@ with lib; type = types.nullOr types.bool; default = null; description = '' - When a job dies, launchd kills any remaining processes with the same process group ID as the job. Setting + When a job dies, launchd kills any remaining processes with the same process group ID as the job. Setting this key to true disables that behavior. ''; }; @@ -730,8 +734,8 @@ with lib; description = '' If this boolean is false, the port is recycled, thus leaving clients to remain oblivious to the demand nature of job. If the value is set to true, clients receive port death notifications when - the job lets go of the receive right. The port will be recreated atomically with respect to boot-strap_look_up() bootstrap_look_up() - strap_look_up() calls, so that clients can trust that after receiving a port death notification, + the job lets go of the receive right. The port will be recreated atomically with respect to bootstrap_look_up() + calls, so that clients can trust that after receiving a port death notification, the new port will have already been recreated. Setting the value to true should be done with care. Not all clients may be able to handle this behavior. The default value is false. ''; @@ -749,6 +753,31 @@ with lib; }); }; + LaunchEvents = mkOption { + type = types.nullOr (types.attrs); + default = null; + description = '' + Specifies higher-level event types to be used as launch-on-demand event + sources. Each sub-dictionary defines events for a particular event + subsystem, such as "com.apple.iokit.matching", which can be used to + launch jobs based on the appearance of nodes in the IORegistry. Each + dictionary within the sub-dictionary specifies an event descriptor that + is specified to each event subsystem. With this key, the job promises to + use the xpc_set_event_stream_handler(3) API to consume events. See + xpc_events(3) for more details on event sources. + ''; + example = { + "com.apple.iokit.matching" = { + "com.apple.usb.device" = { + IOMatchLaunchStream = true; + IOProviderClass = "IOUSBDevice"; + idProduct = "*"; + idVendor = "*"; + }; + }; + }; + }; + Sockets = mkOption { default = null; description = '' @@ -850,8 +879,7 @@ with lib; default = null; description = '' This optional key can be used to request that the service be registered with the - mDNSResponder(8). If the value is boolean, the service name is inferred from the SockService-Name. SockServiceName. - Name. + mDNSResponder(8). If the value is boolean, the service name is inferred from the SockServiceName. ''; }; @@ -861,8 +889,8 @@ with lib; description = '' This optional key can be used to request that the datagram socket join a multicast group. If the value is a hostname, then getaddrinfo(3) will be used to join the correct multicast address for a - given socket family. If an explicit IPv4 or IPv6 address is given, it is required that the Sock-Family SockFamily - Family family also be set, otherwise the results are undefined. + given socket family. If an explicit IPv4 or IPv6 address is given, it is required that the SockFamily + family also be set, otherwise the results are undefined. ''; }; };