Share option definitions between the systemd and Upstart compatibility modules
This commit is contained in:
parent
f74ffe3550
commit
9f9ae7c7e9
@ -181,20 +181,19 @@ in
|
|||||||
postStart =
|
postStart =
|
||||||
''
|
''
|
||||||
while ! psql postgres -c ""; do
|
while ! psql postgres -c ""; do
|
||||||
stop_check
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
extraConfig =
|
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
|
# http://www.postgresql.org/docs/current/static/server-shutdown.html
|
||||||
kill signal INT
|
KillSignal=SIGINT
|
||||||
|
|
||||||
# Give Postgres a decent amount of time to clean up after
|
# Give Postgres a decent amount of time to clean up after
|
||||||
# receiving Upstart's SIGINT.
|
# receiving systemd's SIGINT.
|
||||||
kill timeout 60
|
TimeoutSec=60
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
101
modules/system/boot/systemd-unit-options.nix
Normal file
101
modules/system/boot/systemd-unit-options.nix
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
{ config, pkgs }:
|
||||||
|
|
||||||
|
with pkgs.lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
serviceOptions = {
|
||||||
|
|
||||||
|
description = mkOption {
|
||||||
|
default = "";
|
||||||
|
types = types.uniq types.string;
|
||||||
|
description = "Description of this unit used in systemd messages and progress indicators.";
|
||||||
|
};
|
||||||
|
|
||||||
|
requires = mkOption {
|
||||||
|
default = [];
|
||||||
|
types = types.listOf types.string;
|
||||||
|
description = ''
|
||||||
|
Start the specified units when this unit is started, and stop
|
||||||
|
this unit when the specified units are stopped or fail.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
wants = mkOption {
|
||||||
|
default = [];
|
||||||
|
types = types.listOf types.string;
|
||||||
|
description = ''
|
||||||
|
Start the specified units when this unit is started.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
after = mkOption {
|
||||||
|
default = [];
|
||||||
|
types = types.listOf types.string;
|
||||||
|
description = ''
|
||||||
|
If the specified units are started at the same time as
|
||||||
|
this unit, delay this unit until they have started.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
before = mkOption {
|
||||||
|
default = [];
|
||||||
|
types = types.listOf types.string;
|
||||||
|
description = ''
|
||||||
|
If the specified units are started at the same time as
|
||||||
|
this unit, delay them until this unit has started.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
wantedBy = mkOption {
|
||||||
|
default = [];
|
||||||
|
types = types.listOf types.string;
|
||||||
|
description = "Units that want (i.e. depend on) this unit.";
|
||||||
|
};
|
||||||
|
|
||||||
|
environment = mkOption {
|
||||||
|
default = {};
|
||||||
|
type = types.attrs;
|
||||||
|
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
||||||
|
description = "Environment variables passed to the services's processes.";
|
||||||
|
};
|
||||||
|
|
||||||
|
path = mkOption {
|
||||||
|
default = [];
|
||||||
|
apply = ps: "${makeSearchPath "bin" ps}:${makeSearchPath "sbin" ps}";
|
||||||
|
description = ''
|
||||||
|
Packages added to the service's <envar>PATH</envar>
|
||||||
|
environment variable. Both the <filename>bin</filename>
|
||||||
|
and <filename>sbin</filename> subdirectories of each
|
||||||
|
package are added.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
serviceConfig = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.string;
|
||||||
|
description = ''
|
||||||
|
Contents of the <literal>[Service]</literal> section of the unit.
|
||||||
|
See <citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
||||||
|
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
script = mkOption {
|
||||||
|
type = types.uniq types.string;
|
||||||
|
default = "";
|
||||||
|
description = "Shell commands executed as the service's main process.";
|
||||||
|
};
|
||||||
|
|
||||||
|
preStart = mkOption {
|
||||||
|
type = types.string;
|
||||||
|
default = "";
|
||||||
|
description = ''
|
||||||
|
Shell commands executed before the service's main process
|
||||||
|
is started.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,122 +1,10 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
servicesOptions = {
|
|
||||||
|
|
||||||
description = mkOption {
|
|
||||||
default = "";
|
|
||||||
types = types.uniq types.string;
|
|
||||||
description = "Description of this unit used in systemd messages and progress indicators.";
|
|
||||||
};
|
|
||||||
|
|
||||||
requires = mkOption {
|
|
||||||
default = [];
|
|
||||||
types = types.listOf types.string;
|
|
||||||
description = ''
|
|
||||||
Start the specified units when this unit is started, and stop
|
|
||||||
this unit when the specified units are stopped or fail.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
wants = mkOption {
|
|
||||||
default = [];
|
|
||||||
types = types.listOf types.string;
|
|
||||||
description = ''
|
|
||||||
Start the specified units when this unit is started.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
after = mkOption {
|
|
||||||
default = [];
|
|
||||||
types = types.listOf types.string;
|
|
||||||
description = ''
|
|
||||||
If the specified units are started at the same time as
|
|
||||||
this unit, delay this unit until they have started.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
before = mkOption {
|
|
||||||
default = [];
|
|
||||||
types = types.listOf types.string;
|
|
||||||
description = ''
|
|
||||||
If the specified units are started at the same time as
|
|
||||||
this unit, delay them until this unit has started.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
wantedBy = mkOption {
|
|
||||||
default = [];
|
|
||||||
types = types.listOf types.string;
|
|
||||||
description = "Start this unit when the specified units are started.";
|
|
||||||
};
|
|
||||||
|
|
||||||
environment = mkOption {
|
|
||||||
default = {};
|
|
||||||
type = types.attrs;
|
|
||||||
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
|
||||||
description = "Environment variables passed to the services's processes.";
|
|
||||||
};
|
|
||||||
|
|
||||||
path = mkOption {
|
|
||||||
default = [];
|
|
||||||
apply = ps: "${makeSearchPath "bin" ps}:${makeSearchPath "sbin" ps}";
|
|
||||||
description = ''
|
|
||||||
Packages added to the service's <envar>PATH</envar>
|
|
||||||
environment variable. Both the <filename>bin</filename>
|
|
||||||
and <filename>sbin</filename> subdirectories of each
|
|
||||||
package are added.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
serviceConfig = mkOption {
|
|
||||||
default = "";
|
|
||||||
type = types.string;
|
|
||||||
description = ''
|
|
||||||
Contents of the <literal>[Service]</literal> section of the unit.
|
|
||||||
See <citerefentry><refentrytitle>systemd.unit</refentrytitle>
|
|
||||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
script = mkOption {
|
|
||||||
type = types.uniq types.string;
|
|
||||||
default = "";
|
|
||||||
description = "Shell commands executed as the service's main process.";
|
|
||||||
};
|
|
||||||
|
|
||||||
preStart = mkOption {
|
|
||||||
type = types.string;
|
|
||||||
default = "";
|
|
||||||
description = ''
|
|
||||||
Shell commands executed before the service's main process
|
|
||||||
is started.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
servicesConfig = { name, config, ... }: {
|
|
||||||
|
|
||||||
config = {
|
|
||||||
|
|
||||||
# Default path for systemd services. Should be quite minimal.
|
|
||||||
path =
|
|
||||||
[ pkgs.coreutils
|
|
||||||
pkgs.findutils
|
|
||||||
pkgs.gnugrep
|
|
||||||
pkgs.gnused
|
|
||||||
systemd
|
|
||||||
];
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
cfg = config.boot.systemd;
|
cfg = config.boot.systemd;
|
||||||
|
|
||||||
systemd = pkgs.systemd;
|
systemd = pkgs.systemd;
|
||||||
@ -260,6 +148,19 @@ let
|
|||||||
|
|
||||||
makeJobScript = name: content: "${pkgs.writeScriptBin name content}/bin/${name}";
|
makeJobScript = name: content: "${pkgs.writeScriptBin name content}/bin/${name}";
|
||||||
|
|
||||||
|
serviceConfig = { name, config, ... }: {
|
||||||
|
config = {
|
||||||
|
# Default path for systemd services. Should be quite minimal.
|
||||||
|
path =
|
||||||
|
[ pkgs.coreutils
|
||||||
|
pkgs.findutils
|
||||||
|
pkgs.gnugrep
|
||||||
|
pkgs.gnused
|
||||||
|
systemd
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
serviceToUnit = name: def:
|
serviceToUnit = name: def:
|
||||||
{ inherit (def) wantedBy;
|
{ inherit (def) wantedBy;
|
||||||
|
|
||||||
@ -350,29 +251,24 @@ in
|
|||||||
description = "Definition of systemd units.";
|
description = "Definition of systemd units.";
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrsOf types.optionSet;
|
type = types.attrsOf types.optionSet;
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
text = mkOption {
|
text = mkOption {
|
||||||
types = types.uniq types.string;
|
types = types.uniq types.string;
|
||||||
description = "Text of this systemd unit.";
|
description = "Text of this systemd unit.";
|
||||||
};
|
};
|
||||||
|
|
||||||
wantedBy = mkOption {
|
wantedBy = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
types = types.listOf types.string;
|
types = types.listOf types.string;
|
||||||
description = "Units that want (i.e. depend on) this unit.";
|
description = "Units that want (i.e. depend on) this unit.";
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.systemd.services = mkOption {
|
boot.systemd.services = mkOption {
|
||||||
description = "Definition of systemd services.";
|
description = "Definition of systemd services.";
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrsOf types.optionSet;
|
type = types.attrsOf types.optionSet;
|
||||||
options = [ servicesOptions servicesConfig ];
|
options = [ serviceOptions serviceConfig ];
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.systemd.defaultUnit = mkOption {
|
boot.systemd.defaultUnit = mkOption {
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
with import ../boot/systemd-unit-options.nix { inherit config pkgs; };
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
upstart = pkgs.upstart;
|
|
||||||
|
|
||||||
userExists = u:
|
userExists = u:
|
||||||
(u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
|
(u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
|
||||||
|
|
||||||
@ -66,6 +65,8 @@ let
|
|||||||
|
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
''
|
''
|
||||||
|
${job.serviceConfig}
|
||||||
|
|
||||||
${optionalString (job.preStart != "" && (job.script != "" || job.exec != "")) ''
|
${optionalString (job.preStart != "" && (job.script != "" || job.exec != "")) ''
|
||||||
ExecStartPre=${preStartScript}
|
ExecStartPre=${preStartScript}
|
||||||
''}
|
''}
|
||||||
@ -100,7 +101,7 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
jobOptions = {
|
jobOptions = serviceOptions // {
|
||||||
|
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
# !!! The type should ensure that this could be a filename.
|
# !!! The type should ensure that this could be a filename.
|
||||||
@ -111,14 +112,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
description = mkOption {
|
|
||||||
type = types.string;
|
|
||||||
default = "";
|
|
||||||
description = ''
|
|
||||||
A short description of this job.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
startOn = mkOption {
|
startOn = mkOption {
|
||||||
# !!! Re-enable this once we're on Upstart >= 0.6.
|
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||||
#type = types.string;
|
#type = types.string;
|
||||||
@ -137,15 +130,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
preStart = mkOption {
|
|
||||||
type = types.string;
|
|
||||||
default = "";
|
|
||||||
description = ''
|
|
||||||
Shell commands executed before the job is started
|
|
||||||
(i.e. before the job's main process is started).
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
postStart = mkOption {
|
postStart = mkOption {
|
||||||
type = types.string;
|
type = types.string;
|
||||||
default = "";
|
default = "";
|
||||||
@ -186,15 +170,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
script = mkOption {
|
|
||||||
type = types.string;
|
|
||||||
default = "";
|
|
||||||
description = ''
|
|
||||||
Shell commands executed as the job's main process. Can be
|
|
||||||
specified instead of the <varname>exec</varname> attribute.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
respawn = mkOption {
|
respawn = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
@ -223,15 +198,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
environment = mkOption {
|
|
||||||
type = types.attrs;
|
|
||||||
default = {};
|
|
||||||
example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
|
|
||||||
description = ''
|
|
||||||
Environment variables passed to the job's processes.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
daemonType = mkOption {
|
daemonType = mkOption {
|
||||||
type = types.string;
|
type = types.string;
|
||||||
default = "none";
|
default = "none";
|
||||||
@ -264,15 +230,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
|
||||||
type = types.string;
|
|
||||||
default = "";
|
|
||||||
example = "limit nofile 4096 4096";
|
|
||||||
description = ''
|
|
||||||
Additional Upstart stanzas not otherwise supported.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
path = mkOption {
|
path = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
@ -282,22 +239,10 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
console = mkOption {
|
|
||||||
default = "";
|
|
||||||
example = "console";
|
|
||||||
description = ''
|
|
||||||
If set to <literal>output</literal>, job output is written to
|
|
||||||
the console. If it's <literal>owner</literal>, additionally
|
|
||||||
the job becomes owner of the console. It it's empty (the
|
|
||||||
default), output is written to
|
|
||||||
<filename>/var/log/upstart/<replaceable>jobname</replaceable></filename>
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
upstartJob = {name, config, ...}: {
|
upstartJob = { name, config, ... }: {
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
@ -313,15 +258,6 @@ let
|
|||||||
# The default name is the name extracted from the attribute path.
|
# The default name is the name extracted from the attribute path.
|
||||||
name = mkDefaultValue name;
|
name = mkDefaultValue name;
|
||||||
|
|
||||||
# Default path for Upstart jobs. Should be quite minimal.
|
|
||||||
path =
|
|
||||||
[ pkgs.coreutils
|
|
||||||
pkgs.findutils
|
|
||||||
pkgs.gnugrep
|
|
||||||
pkgs.gnused
|
|
||||||
upstart
|
|
||||||
];
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user