systemd: add enable option

This commit is contained in:
Pol Dellaiera 2024-04-15 19:57:48 +02:00
parent 1c43dcfac4
commit fa8c16e245
No known key found for this signature in database
GPG key ID: D476DFE9C67467CA

View file

@ -5,8 +5,8 @@ let
cfg = config.systemd.user; cfg = config.systemd.user;
inherit (lib) inherit (lib)
any attrValues getAttr hm isBool literalExpression mkIf mkMerge mkOption any attrValues getAttr hm isBool literalExpression mkIf mkMerge
types; mkEnableOption mkOption types;
settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; }; settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; };
@ -105,6 +105,11 @@ in {
options = { options = {
systemd.user = { systemd.user = {
enable = mkEnableOption "the user systemd service manager" // {
default = pkgs.stdenv.isLinux;
defaultText = literalExpression "pkgs.stdenv.isLinux";
};
systemctlPath = mkOption { systemctlPath = mkOption {
default = "${pkgs.systemd}/bin/systemctl"; default = "${pkgs.systemd}/bin/systemctl";
defaultText = literalExpression ''"''${pkgs.systemd}/bin/systemctl"''; defaultText = literalExpression ''"''${pkgs.systemd}/bin/systemctl"'';
@ -286,7 +291,12 @@ in {
# If we run under a Linux system we assume that systemd is # If we run under a Linux system we assume that systemd is
# available, in particular we assume that systemctl is in PATH. # available, in particular we assume that systemctl is in PATH.
# Do not install any user services if username is root. # Do not install any user services if username is root.
config = mkIf (pkgs.stdenv.isLinux && config.home.username != "root") { config = mkIf (cfg.enable && config.home.username != "root") {
assertions = [{
assertion = pkgs.stdenv.isLinux;
message = "This module is only available on Linux.";
}];
xdg.configFile = mkMerge [ xdg.configFile = mkMerge [
(lib.listToAttrs ((buildServices "service" cfg.services) (lib.listToAttrs ((buildServices "service" cfg.services)
++ (buildServices "slice" cfg.slices) ++ (buildServices "slice" cfg.slices)