mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 22:20:51 +00:00
Share option definitions between the systemd and Upstart compatibility modules
This commit is contained in:
parent
f74ffe3550
commit
9f9ae7c7e9
|
@ -36,7 +36,7 @@ let
|
|||
'';
|
||||
|
||||
pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4";
|
||||
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -139,7 +139,7 @@ in
|
|||
host all all 127.0.0.1/32 md5
|
||||
host all all ::1/128 md5
|
||||
'';
|
||||
|
||||
|
||||
users.extraUsers = singleton
|
||||
{ name = "postgres";
|
||||
description = "PostgreSQL server user";
|
||||
|
@ -181,20 +181,19 @@ in
|
|||
postStart =
|
||||
''
|
||||
while ! psql postgres -c ""; do
|
||||
stop_check
|
||||
sleep 1
|
||||
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
|
||||
kill signal INT
|
||||
KillSignal=SIGINT
|
||||
|
||||
# Give Postgres a decent amount of time to clean up after
|
||||
# receiving Upstart's SIGINT.
|
||||
kill timeout 60
|
||||
# receiving systemd's SIGINT.
|
||||
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, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
||||
|
||||
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;
|
||||
|
||||
systemd = pkgs.systemd;
|
||||
|
@ -178,7 +66,7 @@ let
|
|||
# Utmp maintenance.
|
||||
"systemd-update-utmp-runlevel.service"
|
||||
"systemd-update-utmp-shutdown.service"
|
||||
|
||||
|
||||
# Filesystems.
|
||||
"systemd-fsck@.service"
|
||||
"systemd-fsck-root.service"
|
||||
|
@ -260,6 +148,19 @@ let
|
|||
|
||||
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:
|
||||
{ inherit (def) wantedBy;
|
||||
|
||||
|
@ -277,7 +178,7 @@ let
|
|||
[Service]
|
||||
Environment=PATH=${def.path}
|
||||
${concatMapStrings (n: "Environment=${n}=${getAttr n def.environment}\n") (attrNames def.environment)}
|
||||
|
||||
|
||||
${optionalString (def.preStart != "") ''
|
||||
ExecStartPre=${makeJobScript "${name}-prestart.sh" ''
|
||||
#! ${pkgs.stdenv.shell} -e
|
||||
|
@ -297,7 +198,7 @@ let
|
|||
};
|
||||
|
||||
nixosUnits = mapAttrsToList makeUnit cfg.units;
|
||||
|
||||
|
||||
units = pkgs.runCommand "units" { preferLocalBuild = true; }
|
||||
''
|
||||
mkdir -p $out
|
||||
|
@ -310,7 +211,7 @@ let
|
|||
ln -s $fn $out/
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
for i in ${toString upstreamWants}; do
|
||||
fn=${systemd}/example/systemd/system/$i
|
||||
[ -e $fn ]
|
||||
|
@ -322,7 +223,7 @@ let
|
|||
if ! [ -e $y ]; then rm -v $y; fi
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
for i in ${toString nixosUnits}; do
|
||||
ln -s $i/* $out/
|
||||
done
|
||||
|
@ -337,7 +238,7 @@ let
|
|||
|
||||
ln -s ../getty@tty1.service $out/multi-user.target.wants/
|
||||
''; # */
|
||||
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -350,29 +251,24 @@ in
|
|||
description = "Definition of systemd units.";
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
|
||||
options = {
|
||||
|
||||
text = mkOption {
|
||||
types = types.uniq types.string;
|
||||
description = "Text of this systemd unit.";
|
||||
};
|
||||
|
||||
wantedBy = mkOption {
|
||||
default = [];
|
||||
types = types.listOf types.string;
|
||||
description = "Units that want (i.e. depend on) this unit.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
boot.systemd.services = mkOption {
|
||||
description = "Definition of systemd services.";
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = [ servicesOptions servicesConfig ];
|
||||
options = [ serviceOptions serviceConfig ];
|
||||
};
|
||||
|
||||
boot.systemd.defaultUnit = mkOption {
|
||||
|
@ -386,16 +282,16 @@ in
|
|||
type = types.bool;
|
||||
description = "Whether to log kernel messages.";
|
||||
};
|
||||
|
||||
|
||||
services.journald.console = mkOption {
|
||||
default = "";
|
||||
type = types.uniq types.string;
|
||||
description = "If non-empty, write log messages to the specified TTY device. Defaults to /dev/console.";
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = {
|
||||
|
@ -405,7 +301,7 @@ in
|
|||
system.build.units = units;
|
||||
|
||||
environment.systemPackages = [ systemd ];
|
||||
|
||||
|
||||
environment.etc =
|
||||
[ { source = units;
|
||||
target = "systemd/system";
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
with pkgs.lib;
|
||||
with import ../boot/systemd-unit-options.nix { inherit config pkgs; };
|
||||
|
||||
let
|
||||
|
||||
upstart = pkgs.upstart;
|
||||
|
||||
userExists = u:
|
||||
(u == "") || any (uu: uu.name == u) (attrValues config.users.extraUsers);
|
||||
|
||||
|
@ -66,6 +65,8 @@ let
|
|||
|
||||
serviceConfig =
|
||||
''
|
||||
${job.serviceConfig}
|
||||
|
||||
${optionalString (job.preStart != "" && (job.script != "" || job.exec != "")) ''
|
||||
ExecStartPre=${preStartScript}
|
||||
''}
|
||||
|
@ -77,7 +78,7 @@ let
|
|||
${optionalString (job.script != "" || job.exec != "") ''
|
||||
ExecStart=${startScript}
|
||||
''}
|
||||
|
||||
|
||||
${optionalString (job.postStart != "") ''
|
||||
ExecStartPost=${postStartScript}
|
||||
''}
|
||||
|
@ -85,7 +86,7 @@ let
|
|||
${optionalString (job.preStop != "") ''
|
||||
ExecStop=${preStopScript}
|
||||
''}
|
||||
|
||||
|
||||
${optionalString (job.postStop != "") ''
|
||||
ExecStopPost=${postStopScript}
|
||||
''}
|
||||
|
@ -100,7 +101,7 @@ let
|
|||
};
|
||||
|
||||
|
||||
jobOptions = {
|
||||
jobOptions = serviceOptions // {
|
||||
|
||||
name = mkOption {
|
||||
# !!! 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 {
|
||||
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||
#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 {
|
||||
type = types.string;
|
||||
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 {
|
||||
type = types.bool;
|
||||
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 {
|
||||
type = types.string;
|
||||
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 {
|
||||
default = [];
|
||||
description = ''
|
||||
|
@ -282,46 +239,25 @@ 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 = {
|
||||
|
||||
|
||||
unit = mkOption {
|
||||
default = makeUnit config;
|
||||
description = "Generated definition of the systemd unit corresponding to this job.";
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
config = {
|
||||
|
||||
|
||||
# The default name is the name extracted from the attribute path.
|
||||
name = mkDefaultValue name;
|
||||
|
||||
# Default path for Upstart jobs. Should be quite minimal.
|
||||
path =
|
||||
[ pkgs.coreutils
|
||||
pkgs.findutils
|
||||
pkgs.gnugrep
|
||||
pkgs.gnused
|
||||
upstart
|
||||
];
|
||||
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -365,7 +301,7 @@ in
|
|||
boot.systemd.services =
|
||||
flip mapAttrs' config.jobs (name: job:
|
||||
nameValuePair "${job.name}.service" job.unit);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue