diff --git a/modules/nixos/programs/sessiond/submodules/component-type.nix b/modules/nixos/programs/sessiond/submodules/component-type.nix index f8ab4f9f..f0574e54 100644 --- a/modules/nixos/programs/sessiond/submodules/component-type.nix +++ b/modules/nixos/programs/sessiond/submodules/component-type.nix @@ -1,4 +1,22 @@ -{ name, config, lib, session, utils, ... }: { +{ name, config, lib, session, utils, ... }: + +let + optionalSystemdUnitOption = type: systemdModuleAttribute: + lib.mkOption { + description = '' + An optional systemd ${type} configuration to be generated. + + :::{.note} + This has the same options as + {option}`systemd.user.${systemdModuleAttribute}.` but without + certain options from stage 2 counterparts such as `reloadTriggers` and + `restartTriggers`. + ::: + ''; + default = null; + }; +in +{ options = { description = lib.mkOption { type = lib.types.nonEmptyStr; @@ -31,14 +49,11 @@ `reloadTriggers` and `restartTriggers`. By default, this module sets the service unit as part of the respective - target unit (i.e., `PartOf=$COMPONENTID.target`). - - On a typical case, you shouldn't mess with much of the dependency - ordering with the service unit. You should configure `targetUnit` for - that instead. + target unit (i.e., `PartOf=$COMPONENTID.target`). On a typical case, + you shouldn't mess with much of the dependency ordering with the + service unit. You should configure `targetUnit` for that instead. ::: ''; - default = { }; }; targetUnit = lib.mkOption { @@ -52,22 +67,19 @@ unitConfig ]; description = '' - systemd target configuration to be generated. This should be - configured if the session is managed by systemd. + systemd target configuration to be generated. This is generated by + default alongside the service where it is configured to be a part of + the target unit. :::{.note} - This is generated by default alongside the service where it is - configured to be a part of the target unit. - This has the same options as {option}`systemd.user.targets.` but without certain options from stage 2 counterparts such as `reloadTriggers` and `restartTriggers`. ::: ''; - default = { }; }; - timerUnit = lib.mkOption { + timerUnit = optionalSystemdUnitOption "timer" "timers" // { type = let inherit (utils.systemdUtils.unitOptions) timerOptions commonUnitOptions; @@ -78,20 +90,9 @@ timerOptions unitConfig ]); - description = '' - An optional systemd timer configuration to be generated. This should - be configured if the session is managed by systemd. - - :::{.note} - This has the same options as {option}`systemd.user.timers.` - but without certain options from stage 2 counterparts such as - `reloadTriggers` and `restartTriggers`. - ::: - ''; - default = null; }; - socketUnit = lib.mkOption { + socketUnit = optionalSystemdUnitOption "socket" "sockets" // { type = let inherit (utils.systemdUtils.unitOptions) socketOptions commonUnitOptions; @@ -102,20 +103,9 @@ socketOptions unitConfig ]); - description = '' - An optional systemd socket configuration to be generated. This should - be configured if the session is managed by systemd. - - :::{.note} - This has the same options as {option}`systemd.user.sockets.` - but without certain options from stage 2 counterparts such as - `reloadTriggers` and `restartTriggers`. - ::: - ''; - default = null; }; - pathUnit = lib.mkOption { + pathUnit = optionalSystemdUnitOption "path" "paths" // { type = let inherit (utils.systemdUtils.unitOptions) pathOptions commonUnitOptions; @@ -126,17 +116,6 @@ pathOptions unitConfig ]); - description = '' - An optional systemd path configuration to be generated. This should - be configured if the session is managed by systemd. - - :::{.note} - This has the same options as {option}`systemd.user.paths.` - but without certain options from stage 2 counterparts such as - `reloadTriggers` and `restartTriggers`. - ::: - ''; - default = null; }; id = lib.mkOption { @@ -163,26 +142,12 @@ know how different desktop components interact with each other especially if one of them failed. - TODO: Is `Type=notify` a good default? - * `Service.Type=` is obviously not included since not all desktop - components are the same either. Some of them could a D-Bus service, - some of them are oneshots, etc. Not to mention, this is already implied - to be `Type=simple` by systemd anyways. - * `Service.OOMScoreAdjust=` have different values for different components so it isn't included. * Most sandboxing options. Aside from the fact we're dealing with a systemd user unit, much of them are unnecessary and rarely needed (if ever like `Service.PrivateTmp=`?) so we didn't set such defaults here. - - As you can tell, this module does not provide a framework for the user - to easily compose their own desktop environment. THIS MODULE ALREADY - DOES A LOT, ALRIGHT! CUT ME SOME SLACK! - - Take note that the default service configuration is leaning on the - desktop component being a simple type of service like how most NixOS - service modules are deployed. */ serviceUnit = { description = lib.mkDefault config.description; @@ -211,14 +176,8 @@ }; /* - Similarly, there are things that COULD make it here but didn't for a - variety of reasons. - - * `Unit.PartOf=`, `Unit.Requisite=`, and the like since some components - require starting up earlier than the others. We could include it here - if we make it clear in the documentation or if it proves to be a - painful experience to configure this by a first-timer. For now, this is - on the user to know. + Take note the session target unit already has `Wants=$COMPONENT.target` + so no need to set dependency ordering directives here. */ targetUnit = { wants = [ "${config.id}.service" ];