Make unitConfig/serviceConfig attribute sets
So instead of: boot.systemd.services."foo".serviceConfig = '' StartLimitInterval=10 CPUShare=500 ''; you can say: boot.systemd.services."foo".serviceConfig.StartLimitInterval = 10; boot.systemd.services."foo".serviceConfig.CPUShare = 500; This way all unit options are available and users can set/override options in configuration.nix.
This commit is contained in:
parent
440b793a5b
commit
891be375b5
@ -194,15 +194,14 @@ in
|
||||
'';
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
# Shut down Postgres using SIGINT ("Fast Shutdown mode"). See
|
||||
{ # Shut down Postgres using SIGINT ("Fast Shutdown mode"). See
|
||||
# http://www.postgresql.org/docs/current/static/server-shutdown.html
|
||||
KillSignal=SIGINT
|
||||
KillSignal = "SIGINT";
|
||||
|
||||
# Give Postgres a decent amount of time to clean up after
|
||||
# receiving systemd's SIGINT.
|
||||
TimeoutSec=60
|
||||
'';
|
||||
TimeoutSec = 60;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ in
|
||||
|
||||
# FIXME: restarting syslog seems to break journal logging.
|
||||
boot.systemd.services.syslog =
|
||||
{ description = "Syslog daemon";
|
||||
{ description = "Syslog Daemon";
|
||||
|
||||
requires = [ "syslog.socket" ];
|
||||
|
||||
@ -115,11 +115,10 @@ in
|
||||
environment.TZ = config.time.timeZone;
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
ExecStart=${pkgs.sysklogd}/sbin/syslogd ${toString cfg.extraParams} -f ${syslogConf} -n
|
||||
{ ExecStart = "${pkgs.sysklogd}/sbin/syslogd ${toString cfg.extraParams} -f ${syslogConf} -n";
|
||||
# Prevent syslogd output looping back through journald.
|
||||
StandardOutput=null
|
||||
'';
|
||||
StandardOutput = "null";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -268,14 +268,12 @@ in
|
||||
environment = cfg.envVars;
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
ExecStart=${nix}/bin/nix-worker --daemon
|
||||
KillMode=process
|
||||
PIDFile=/run/sshd.pid
|
||||
Nice=${toString cfg.daemonNiceLevel}
|
||||
IOSchedulingPriority=${toString cfg.daemonIONiceLevel}
|
||||
LimitNOFILE=4096
|
||||
'';
|
||||
{ ExecStart = "${nix}/bin/nix-worker --daemon";
|
||||
KillMode = "process";
|
||||
Nice = cfg.daemonNiceLevel;
|
||||
IOSchedulingPriority = cfg.daemonIONiceLevel;
|
||||
LimitNOFILE = 4096;
|
||||
};
|
||||
};
|
||||
|
||||
nix.envVars =
|
||||
|
@ -91,7 +91,7 @@ in
|
||||
|
||||
config = mkIf config.networking.useDHCP {
|
||||
|
||||
jobs.dhcpcd =
|
||||
boot.systemd.services.dhcpcd =
|
||||
{ description = "DHCP Client";
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
@ -99,14 +99,12 @@ in
|
||||
|
||||
path = [ dhcpcd pkgs.nettools pkgs.openresolv ];
|
||||
|
||||
daemonType = "fork";
|
||||
|
||||
exec = "dhcpcd --config ${dhcpcdConf}";
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
ExecReload=${dhcpcd}/sbin/dhcpcd --rebind
|
||||
'';
|
||||
{ Type = "forking";
|
||||
PIDFile = "/run/dhcpcd.pid";
|
||||
ExecStart = "@${dhcpcd}/sbin/dhcpcd dhcpcd --config ${dhcpcdConf}";
|
||||
ExecReload = "${dhcpcd}/sbin/dhcpcd --rebind";
|
||||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = [ dhcpcd ];
|
||||
|
@ -321,11 +321,8 @@ in
|
||||
|
||||
script = mkAuthkeyScript;
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
Type=oneshot
|
||||
RemainAfterExit=true
|
||||
'';
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
};
|
||||
|
||||
boot.systemd.services.sshd =
|
||||
@ -349,15 +346,14 @@ in
|
||||
'';
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
ExecStart=\
|
||||
${pkgs.openssh}/sbin/sshd -D -h ${cfg.hostKeyPath} \
|
||||
-f ${pkgs.writeText "sshd_config" cfg.extraConfig}
|
||||
Restart=always
|
||||
Type=simple
|
||||
KillMode=process
|
||||
PIDFile=/run/sshd.pid
|
||||
'';
|
||||
{ ExecStart =
|
||||
"${pkgs.openssh}/sbin/sshd -D -h ${cfg.hostKeyPath} " +
|
||||
"-f ${pkgs.writeText "sshd_config" cfg.extraConfig}";
|
||||
Restart = "always";
|
||||
Type = "simple";
|
||||
KillMode = "process";
|
||||
PIDFile = "/run/sshd.pid";
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = cfg.ports;
|
||||
|
@ -53,15 +53,16 @@ in
|
||||
'';
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
ExecStart=@${pkgs.glibc}/sbin/nscd nscd -f ${./nscd.conf}
|
||||
Type=forking
|
||||
PIDFile=/run/nscd/nscd.pid
|
||||
Restart=always
|
||||
ExecReload=${pkgs.glibc}/sbin/nscd --invalidate passwd
|
||||
ExecReload=${pkgs.glibc}/sbin/nscd --invalidate group
|
||||
ExecReload=${pkgs.glibc}/sbin/nscd --invalidate hosts
|
||||
'';
|
||||
{ ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${./nscd.conf}";
|
||||
Type = "forking";
|
||||
PIDFile = "/run/nscd/nscd.pid";
|
||||
Restart = "always";
|
||||
ExecReload =
|
||||
[ "${pkgs.glibc}/sbin/nscd --invalidate passwd"
|
||||
"${pkgs.glibc}/sbin/nscd --invalidate group"
|
||||
"${pkgs.glibc}/sbin/nscd --invalidate hosts"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -81,21 +81,28 @@ with pkgs.lib;
|
||||
};
|
||||
|
||||
unitConfig = mkOption {
|
||||
default = "";
|
||||
type = types.string;
|
||||
default = {};
|
||||
example = { RequiresMountsFor = "/data"; };
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Contents of the <literal>[Unit]</literal> section of the unit.
|
||||
See <citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Unit]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
serviceConfig = mkOption {
|
||||
default = "";
|
||||
type = types.string;
|
||||
default = {};
|
||||
example =
|
||||
{ StartLimitInterval = 10;
|
||||
RestartSec = 5;
|
||||
};
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Contents of the <literal>[Service]</literal> section of the unit.
|
||||
See <citerefentry><refentrytitle>systemd.service</refentrytitle>
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Service]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.service</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
@ -177,24 +177,38 @@ let
|
||||
pkgs.gnused
|
||||
systemd
|
||||
];
|
||||
unitConfig =
|
||||
{ Requires = concatStringsSep " " config.requires;
|
||||
Wants = concatStringsSep " " config.wants;
|
||||
After = concatStringsSep " " config.after;
|
||||
Before = concatStringsSep " " config.before;
|
||||
PartOf = concatStringsSep " " config.partOf;
|
||||
} // optionalAttrs (config.description != "")
|
||||
{ Description = config.description;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
toOption = x:
|
||||
if x == true then "true"
|
||||
else if x == false then "false"
|
||||
else toString x;
|
||||
|
||||
attrsToSection = as:
|
||||
concatStrings (concatLists (mapAttrsToList (name: value:
|
||||
map (x: ''
|
||||
${name}=${toOption x}
|
||||
'')
|
||||
(if isList value then value else [value]))
|
||||
as));
|
||||
|
||||
serviceToUnit = name: def:
|
||||
{ inherit (def) wantedBy;
|
||||
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
${optionalString (def.description != "") ''
|
||||
Description=${def.description}
|
||||
''}
|
||||
Requires=${concatStringsSep " " def.requires}
|
||||
Wants=${concatStringsSep " " def.wants}
|
||||
After=${concatStringsSep " " def.after}
|
||||
Before=${concatStringsSep " " def.before}
|
||||
PartOf=${concatStringsSep " " def.partOf}
|
||||
${def.unitConfig}
|
||||
${attrsToSection def.unitConfig}
|
||||
|
||||
[Service]
|
||||
Environment=PATH=${def.path}
|
||||
@ -215,7 +229,7 @@ let
|
||||
''}
|
||||
''}
|
||||
|
||||
${def.serviceConfig}
|
||||
${attrsToSection def.serviceConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,7 @@ let
|
||||
'';
|
||||
in {
|
||||
|
||||
inherit (job) description requires wants before partOf environment path restartIfChanged;
|
||||
inherit (job) description requires wants before partOf environment path restartIfChanged unitConfig;
|
||||
|
||||
after =
|
||||
(if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else
|
||||
@ -72,40 +72,23 @@ let
|
||||
[ "multi-user.target" ]) ++ job.wantedBy;
|
||||
|
||||
serviceConfig =
|
||||
''
|
||||
${job.serviceConfig}
|
||||
|
||||
${optionalString (job.preStart != "" && (job.script != "" || job.exec != "")) ''
|
||||
ExecStartPre=${preStartScript}
|
||||
''}
|
||||
|
||||
${optionalString (job.preStart != "" && job.script == "" && job.exec == "") ''
|
||||
ExecStart=${preStartScript}
|
||||
''}
|
||||
|
||||
${optionalString (job.script != "" || job.exec != "") ''
|
||||
ExecStart=${startScript}
|
||||
''}
|
||||
|
||||
${optionalString (job.postStart != "") ''
|
||||
ExecStartPost=${postStartScript}
|
||||
''}
|
||||
|
||||
${optionalString (job.preStop != "") ''
|
||||
ExecStop=${preStopScript}
|
||||
''}
|
||||
|
||||
${optionalString (job.postStop != "") ''
|
||||
ExecStopPost=${postStopScript}
|
||||
''}
|
||||
|
||||
${if job.script == "" && job.exec == "" then "Type=oneshot\nRemainAfterExit=true" else
|
||||
if job.daemonType == "fork" then "Type=forking\nGuessMainPID=true" else
|
||||
if job.daemonType == "none" then "" else
|
||||
throw "invalid daemon type `${job.daemonType}'"}
|
||||
|
||||
${optionalString (!job.task && job.respawn) "Restart=always"}
|
||||
'';
|
||||
job.serviceConfig
|
||||
// optionalAttrs (job.preStart != "" && (job.script != "" || job.exec != ""))
|
||||
{ ExecStartPre = preStartScript; }
|
||||
// optionalAttrs (job.script != "" || job.exec != "")
|
||||
{ ExecStart = startScript; }
|
||||
// optionalAttrs (job.postStart != "")
|
||||
{ ExecStartPost = postStartScript; }
|
||||
// optionalAttrs (job.preStop != "")
|
||||
{ ExecStop = preStopScript; }
|
||||
// optionalAttrs (job.postStop != "")
|
||||
{ ExecStopPost = postStopScript; }
|
||||
// (if job.script == "" && job.exec == "" then { Type = "oneshot"; RemainAfterExit = true; } else
|
||||
if job.daemonType == "fork" then { Type = "forking"; GuessMainPID = true; } else
|
||||
if job.daemonType == "none" then { } else
|
||||
throw "invalid daemon type `${job.daemonType}'")
|
||||
// optionalAttrs (!job.task && job.respawn)
|
||||
{ Restart = "always"; };
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user