hjem/collection: add systemd module
This adds a systemd module locally, allowing to define your own services at hjem level rather than systemd level.
This commit is contained in:
parent
174b6251e8
commit
d11fb3a0e2
2 changed files with 76 additions and 14 deletions
|
@ -270,23 +270,28 @@ in {
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.waybar.settings = {
|
||||||
|
Unit = {
|
||||||
|
Description = "Highly customizable Wayland bar for Sway and Wlroots based compositors.";
|
||||||
|
Documentation = ["https://github.com/Alexays/Waybar/wiki/"];
|
||||||
|
After = ["graphical-session.target"];
|
||||||
|
PartOf = ["graphical-session.target"];
|
||||||
|
Requisite = ["graphical-session.target"];
|
||||||
|
X-Reload-Triggers = ["${config.hjem.users.${username}.files.".config/waybar/config".text}"];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.user.services.waybar = {
|
Service = {
|
||||||
description = "Highly customizable Wayland bar for Sway and Wlroots based compositors.";
|
|
||||||
documentation = ["https://github.com/Alexays/Waybar/wiki/"];
|
|
||||||
after = ["graphical-session.target"];
|
|
||||||
partOf = ["graphical-session.target"];
|
|
||||||
requisite = ["graphical-session.target"];
|
|
||||||
wantedBy = ["graphical-session.target"];
|
|
||||||
|
|
||||||
reloadTriggers = ["${config.hjem.users.${username}.files.".config/waybar/config".text}"];
|
|
||||||
serviceConfig = {
|
|
||||||
ExecStart = "${pkgs.waybar}/bin/waybar";
|
ExecStart = "${pkgs.waybar}/bin/waybar";
|
||||||
ExecReload = "kill -SIGUSR2 $MAINPID";
|
ExecReload = "kill -SIGUSR2 $MAINPID";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
Slice = "app-graphical.slice";
|
Slice = "app-graphical.slice";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Install = {
|
||||||
|
WantedBy = ["graphical-session.target"];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
57
shared/modules/hjem/collection/systemd-services.nix
Normal file
57
shared/modules/hjem/collection/systemd-services.nix
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue