nixos/programs/sessiond: refactor and update comments

This commit is contained in:
Gabriel Arazas 2024-01-25 18:55:57 +08:00
parent b81460db8f
commit 07510b2257
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -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}.<name>` but without
certain options from stage 2 counterparts such as `reloadTriggers` and
`restartTriggers`.
:::
'';
default = null;
};
in
{
options = { options = {
description = lib.mkOption { description = lib.mkOption {
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
@ -31,14 +49,11 @@
`reloadTriggers` and `restartTriggers`. `reloadTriggers` and `restartTriggers`.
By default, this module sets the service unit as part of the respective By default, this module sets the service unit as part of the respective
target unit (i.e., `PartOf=$COMPONENTID.target`). target unit (i.e., `PartOf=$COMPONENTID.target`). On a typical case,
you shouldn't mess with much of the dependency ordering with the
On a typical case, you shouldn't mess with much of the dependency service unit. You should configure `targetUnit` for that instead.
ordering with the service unit. You should configure `targetUnit` for
that instead.
::: :::
''; '';
default = { };
}; };
targetUnit = lib.mkOption { targetUnit = lib.mkOption {
@ -52,22 +67,19 @@
unitConfig unitConfig
]; ];
description = '' description = ''
systemd target configuration to be generated. This should be systemd target configuration to be generated. This is generated by
configured if the session is managed by systemd. default alongside the service where it is configured to be a part of
the target unit.
:::{.note} :::{.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.<name>` This has the same options as {option}`systemd.user.targets.<name>`
but without certain options from stage 2 counterparts such as but without certain options from stage 2 counterparts such as
`reloadTriggers` and `restartTriggers`. `reloadTriggers` and `restartTriggers`.
::: :::
''; '';
default = { };
}; };
timerUnit = lib.mkOption { timerUnit = optionalSystemdUnitOption "timer" "timers" // {
type = type =
let let
inherit (utils.systemdUtils.unitOptions) timerOptions commonUnitOptions; inherit (utils.systemdUtils.unitOptions) timerOptions commonUnitOptions;
@ -78,20 +90,9 @@
timerOptions timerOptions
unitConfig 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.<name>`
but without certain options from stage 2 counterparts such as
`reloadTriggers` and `restartTriggers`.
:::
'';
default = null;
}; };
socketUnit = lib.mkOption { socketUnit = optionalSystemdUnitOption "socket" "sockets" // {
type = type =
let let
inherit (utils.systemdUtils.unitOptions) socketOptions commonUnitOptions; inherit (utils.systemdUtils.unitOptions) socketOptions commonUnitOptions;
@ -102,20 +103,9 @@
socketOptions socketOptions
unitConfig 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.<name>`
but without certain options from stage 2 counterparts such as
`reloadTriggers` and `restartTriggers`.
:::
'';
default = null;
}; };
pathUnit = lib.mkOption { pathUnit = optionalSystemdUnitOption "path" "paths" // {
type = type =
let let
inherit (utils.systemdUtils.unitOptions) pathOptions commonUnitOptions; inherit (utils.systemdUtils.unitOptions) pathOptions commonUnitOptions;
@ -126,17 +116,6 @@
pathOptions pathOptions
unitConfig 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.<name>`
but without certain options from stage 2 counterparts such as
`reloadTriggers` and `restartTriggers`.
:::
'';
default = null;
}; };
id = lib.mkOption { id = lib.mkOption {
@ -163,26 +142,12 @@
know how different desktop components interact with each other know how different desktop components interact with each other
especially if one of them failed. 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 * `Service.OOMScoreAdjust=` have different values for different
components so it isn't included. components so it isn't included.
* Most sandboxing options. Aside from the fact we're dealing with a * Most sandboxing options. Aside from the fact we're dealing with a
systemd user unit, much of them are unnecessary and rarely needed (if systemd user unit, much of them are unnecessary and rarely needed (if
ever like `Service.PrivateTmp=`?) so we didn't set such defaults here. 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 = { serviceUnit = {
description = lib.mkDefault config.description; description = lib.mkDefault config.description;
@ -211,14 +176,8 @@
}; };
/* /*
Similarly, there are things that COULD make it here but didn't for a Take note the session target unit already has `Wants=$COMPONENT.target`
variety of reasons. so no need to set dependency ordering directives here.
* `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.
*/ */
targetUnit = { targetUnit = {
wants = [ "${config.id}.service" ]; wants = [ "${config.id}.service" ];