-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds systemd services configuration through hjem, under `users.<username>.systemd.services`.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
lib, | ||
config, | ||
... | ||
}: let | ||
inherit (builtins) toString; | ||
inherit (lib.attrsets) nameValuePair mapAttrs'; | ||
inherit (lib.modules) mkIf; | ||
inherit (lib.options) mkOption; | ||
inherit (lib.types) attrs attrsOf submodule; | ||
inherit (lib.trivial) isBool boolToString; | ||
inherit (lib.generators) toINI; | ||
|
||
cfg = config.systemd; | ||
|
||
toSystemdUnitFiles = services: let | ||
toSystemdUnit = arg: | ||
toINI { | ||
listsAsDuplicateKeys = true; | ||
mkKeyValue = key: value: let | ||
value' = | ||
if isBool value | ||
then boolToString value | ||
else toString value; | ||
in "${key}=${value'}"; | ||
} | ||
arg; | ||
in | ||
mapAttrs' (name: service: | ||
nameValuePair ".config/systemd/user/${name}.service" {text = toSystemdUnit service.settings;}) | ||
services; | ||
in { | ||
options.systemd = { | ||
services = mkOption { | ||
type = attrsOf (submodule { | ||
options = { | ||
settings = mkOption { | ||
type = attrs; | ||
default = {}; | ||
description = '' | ||
The configuration of this unit. Each attribute in this set specifies an option | ||
(documentation for available options can be found [here](https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html)). | ||
''; | ||
}; | ||
}; | ||
}); | ||
default = {}; | ||
description = '' | ||
Definition of systemd user service units. | ||
''; | ||
}; | ||
}; | ||
|
||
config = mkIf (cfg.services != {}) { | ||
files = toSystemdUnitFiles cfg.services; | ||
}; | ||
} |