mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 11:36:05 +01:00
systemd: make unit definitions freeform modules
We add types for a few of the most common attributes.
This commit is contained in:
parent
12dfb0cff9
commit
5c14260fad
1 changed files with 115 additions and 15 deletions
|
|
@ -51,7 +51,11 @@ let
|
||||||
source =
|
source =
|
||||||
pkgs.writeTextFile {
|
pkgs.writeTextFile {
|
||||||
name = pathSafeName;
|
name = pathSafeName;
|
||||||
text = toSystemdIni serviceCfg;
|
text = toSystemdIni (
|
||||||
|
lib.filterAttrs (_: v: v != { }) (
|
||||||
|
lib.mapAttrs (_: lib.filterAttrs (_: v: v != null && v != [ ])) serviceCfg
|
||||||
|
)
|
||||||
|
);
|
||||||
destination = "/${filename}";
|
destination = "/${filename}";
|
||||||
}
|
}
|
||||||
+ "/${filename}";
|
+ "/${filename}";
|
||||||
|
|
@ -73,8 +77,10 @@ let
|
||||||
|
|
||||||
servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs;
|
servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs;
|
||||||
|
|
||||||
unitType =
|
unitBaseType =
|
||||||
unitKind:
|
unitKind: mod:
|
||||||
|
types.submodule {
|
||||||
|
freeformType =
|
||||||
with types;
|
with types;
|
||||||
let
|
let
|
||||||
primitive = oneOf [
|
primitive = oneOf [
|
||||||
|
|
@ -84,11 +90,105 @@ let
|
||||||
path
|
path
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
attrsOf (attrsOf (attrsOf (either primitive (listOf primitive))))
|
attrsOf (attrsOf (either primitive (listOf primitive)))
|
||||||
// {
|
// {
|
||||||
description = "systemd ${unitKind} unit configuration";
|
description = "systemd ${unitKind} unit configuration";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
{
|
||||||
|
options.Unit = {
|
||||||
|
Description = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "My daily database backup";
|
||||||
|
description = "A short human-readable label of the unit.";
|
||||||
|
};
|
||||||
|
|
||||||
|
Documentation = mkOption {
|
||||||
|
type = with types; coercedTo str lib.toList (listOf str);
|
||||||
|
example = [ "my-${unitKind}.${unitKind}" ];
|
||||||
|
default = [ ];
|
||||||
|
description = "List of URIs referencing documentation for the unit.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
mod
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
unitType = unitKind: types.attrsOf (unitBaseType unitKind { });
|
||||||
|
|
||||||
|
serviceType = types.attrsOf (
|
||||||
|
unitBaseType "service" {
|
||||||
|
options = {
|
||||||
|
Unit = {
|
||||||
|
X-Reload-Triggers = mkOption {
|
||||||
|
type = with types; listOf (either package str);
|
||||||
|
default = [ ];
|
||||||
|
example = literalExpression ''[ config.xdg.configFile."service.conf".source ]'';
|
||||||
|
description = ''
|
||||||
|
List of free form strings that can be used to trigger a service
|
||||||
|
reload during Home Manager activation.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
X-Restart-Triggers = mkOption {
|
||||||
|
type = with types; listOf (either package str);
|
||||||
|
default = [ ];
|
||||||
|
example = literalExpression ''[ config.xdg.configFile."service.conf".source ]'';
|
||||||
|
description = ''
|
||||||
|
List of free form strings that can be used to trigger a service
|
||||||
|
restart during Home Manager activation.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
X-SwitchMethod = mkOption {
|
||||||
|
type = types.enum [
|
||||||
|
null
|
||||||
|
"reload"
|
||||||
|
"restart"
|
||||||
|
"stop-start"
|
||||||
|
"keep-old"
|
||||||
|
];
|
||||||
|
default = null;
|
||||||
|
example = literalExpression ''[ "''${config.xdg.configFile."service.conf".source}" ]'';
|
||||||
|
description = ''
|
||||||
|
The preferred method to use when switching from an old to a new
|
||||||
|
version of this service.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
Environment = mkOption {
|
||||||
|
type = with types; coercedTo str lib.toList (listOf str);
|
||||||
|
default = [ ];
|
||||||
|
example = [
|
||||||
|
"VAR1=foo"
|
||||||
|
"VAR2=\"bar baz\""
|
||||||
|
];
|
||||||
|
description = "Environment variables available to executed processes.";
|
||||||
|
};
|
||||||
|
|
||||||
|
ExecStart = mkOption {
|
||||||
|
type =
|
||||||
|
with types;
|
||||||
|
let
|
||||||
|
primitive = either package str;
|
||||||
|
in
|
||||||
|
either primitive (listOf primitive);
|
||||||
|
apply = lib.toList;
|
||||||
|
default = [ ];
|
||||||
|
example = "/absolute/path/to/command arg1 arg2";
|
||||||
|
description = "Command that is executed when this service is started.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
unitDescription = type: ''
|
unitDescription = type: ''
|
||||||
Definition of systemd per-user ${type} units. Attributes are
|
Definition of systemd per-user ${type} units. Attributes are
|
||||||
merged recursively.
|
merged recursively.
|
||||||
|
|
@ -151,7 +251,7 @@ in
|
||||||
|
|
||||||
services = mkOption {
|
services = mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = unitType "service";
|
type = serviceType;
|
||||||
description = (unitDescription "service");
|
description = (unitDescription "service");
|
||||||
example = unitExample "Service";
|
example = unitExample "Service";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue