mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-11 15:27:20 +03:00
* Support tasks in the new Upstart formalism.
* Swap task: fixed removing disabled swap devices. * Swap task: specified the type of swapDevices. svn path=/nixos/branches/modular-nixos/; revision=16396
This commit is contained in:
parent
7cb4503ad6
commit
6119c399d8
@ -236,21 +236,18 @@ in
|
|||||||
target = "nix.machines";
|
target = "nix.machines";
|
||||||
};
|
};
|
||||||
|
|
||||||
services.extraJobs = [
|
jobs = pkgs.lib.singleton
|
||||||
{ name = "nix-daemon";
|
{ name = "nix-daemon";
|
||||||
|
|
||||||
job = ''
|
startOn = "startup";
|
||||||
start on startup
|
|
||||||
stop on shutdown
|
script =
|
||||||
respawn
|
''
|
||||||
script
|
|
||||||
export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
|
export PATH=${if config.nix.distributedBuilds then "${pkgs.openssh}/bin:" else ""}${pkgs.openssl}/bin:${nix}/bin:$PATH
|
||||||
${config.nix.envVars}
|
${config.nix.envVars}
|
||||||
exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
|
exec ${nix}/bin/nix-worker --daemon > /dev/null 2>&1
|
||||||
end script
|
'';
|
||||||
'';
|
};
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
environment.shellInit =
|
environment.shellInit =
|
||||||
''
|
''
|
||||||
|
@ -11,10 +11,19 @@ let
|
|||||||
|
|
||||||
jobText = if job.job != "" then job.job else
|
jobText = if job.job != "" then job.job else
|
||||||
''
|
''
|
||||||
|
# Upstart job `${job.name}'. This is a generated file. Do not edit.
|
||||||
|
|
||||||
description "${job.description}"
|
description "${job.description}"
|
||||||
|
|
||||||
${if job.startOn != "" then "start on ${job.startOn}" else ""}
|
${if isList job.startOn then
|
||||||
${if job.stopOn != "" then "start on ${job.stopOn}" else ""}
|
# This is a hack to support or-dependencies on Upstart 0.3.
|
||||||
|
concatMapStrings (x: "start on ${x}\n") job.startOn
|
||||||
|
else if job.startOn != "" then
|
||||||
|
"start on ${job.startOn}"
|
||||||
|
else ""
|
||||||
|
}
|
||||||
|
|
||||||
|
${if job.stopOn != "" then "stop on ${job.stopOn}" else ""}
|
||||||
|
|
||||||
${concatMapStrings (n: "env ${n}=${getAttr n job.environment}\n") (attrNames job.environment)}
|
${concatMapStrings (n: "env ${n}=${getAttr n job.environment}\n") (attrNames job.environment)}
|
||||||
|
|
||||||
@ -24,15 +33,27 @@ let
|
|||||||
end script
|
end script
|
||||||
'' else ""}
|
'' else ""}
|
||||||
|
|
||||||
${if true then
|
${if job.script != "" && job.exec != "" then
|
||||||
# Simulate jobs without a main process (which Upstart 0.3
|
abort "Job ${job.name} has both a `script' and `exec' attribute."
|
||||||
# doesn't support) using a semi-infinite sleep.
|
else if job.script != "" then
|
||||||
''
|
''
|
||||||
exec ${if job.exec != "" then job.exec else "sleep 1e100"}
|
script
|
||||||
''
|
${job.script}
|
||||||
else ""}
|
end script
|
||||||
|
''
|
||||||
|
else if job.exec != "" then
|
||||||
|
''
|
||||||
|
exec ${job.exec}
|
||||||
|
''
|
||||||
|
else
|
||||||
|
# Simulate jobs without a main process (which Upstart 0.3
|
||||||
|
# doesn't support) using a semi-infinite sleep.
|
||||||
|
''
|
||||||
|
exec sleep 1e100
|
||||||
|
''
|
||||||
|
}
|
||||||
|
|
||||||
${if job.respawn then "respawn" else ""}
|
${if job.respawn && !job.task then "respawn" else ""}
|
||||||
|
|
||||||
${if job.postStop != "" then ''
|
${if job.postStop != "" then ''
|
||||||
stop script
|
stop script
|
||||||
@ -134,7 +155,8 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
startOn = mkOption {
|
startOn = mkOption {
|
||||||
type = types.string;
|
# !!! Re-enable this once we're on Upstart >= 0.6.
|
||||||
|
#type = types.string;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
The Upstart event that triggers this job to be started.
|
The Upstart event that triggers this job to be started.
|
||||||
@ -179,6 +201,15 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
@ -188,6 +219,16 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
task = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether this job is a task rather than a service. Tasks
|
||||||
|
are executed only once, while services are restarted when
|
||||||
|
they exit.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
environment = mkOption {
|
environment = mkOption {
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -2,18 +2,27 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
###### interface
|
inherit (pkgs) utillinux;
|
||||||
|
inherit (pkgs.lib) mkOption filter types;
|
||||||
|
|
||||||
|
toPath = x: if x.device != null then x.device else "/dev/disk/by-label/${x.label}";
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
swapDevices = pkgs.lib.mkOption {
|
swapDevices = mkOption {
|
||||||
default = [];
|
default = [];
|
||||||
example = [
|
example = [
|
||||||
{ device = "/dev/hda7"; }
|
{ device = "/dev/hda7"; }
|
||||||
{ device = "/var/swapfile"; }
|
{ device = "/var/swapfile"; }
|
||||||
{ label = "bigswap"; }
|
{ label = "bigswap"; }
|
||||||
];
|
];
|
||||||
description = "
|
description = ''
|
||||||
The swap devices and swap files. These must have been
|
The swap devices and swap files. These must have been
|
||||||
initialised using <command>mkswap</command>. Each element
|
initialised using <command>mkswap</command>. Each element
|
||||||
should be an attribute set specifying either the path of the
|
should be an attribute set specifying either the path of the
|
||||||
@ -21,59 +30,70 @@ let
|
|||||||
of the swap device (<literal>label</literal>, see
|
of the swap device (<literal>label</literal>, see
|
||||||
<command>mkswap -L</command>). Using a label is
|
<command>mkswap -L</command>). Using a label is
|
||||||
recommended.
|
recommended.
|
||||||
";
|
'';
|
||||||
|
|
||||||
|
type = types.list types.optionSet;
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
device = mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "/dev/sda3";
|
||||||
|
type = types.nullOr types.string;
|
||||||
|
description = ''
|
||||||
|
Path of the device.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
label = mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "swap";
|
||||||
|
type = types.nullOr types.string;
|
||||||
|
description = "
|
||||||
|
Label of the device. Can be used instead of <varname>device</varname>.
|
||||||
|
";
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
###### implementation
|
config = {
|
||||||
|
|
||||||
inherit (pkgs) utillinux lib;
|
jobs = pkgs.lib.singleton
|
||||||
|
{ name = "swap";
|
||||||
|
|
||||||
swapDevices = config.swapDevices;
|
task = true;
|
||||||
|
|
||||||
|
startOn = ["startup" "new-devices"];
|
||||||
|
|
||||||
devicesByPath =
|
script =
|
||||||
map (x: x.device) (lib.filter (x: x ? device) swapDevices);
|
''
|
||||||
|
swapDevices=${toString (map toPath config.swapDevices)}
|
||||||
devicesByLabel =
|
|
||||||
map (x: x.label) (lib.filter (x: x ? label) swapDevices);
|
for device in $swapDevices; do
|
||||||
|
${utillinux}/sbin/swapon "$device" || true
|
||||||
|
done
|
||||||
|
|
||||||
in
|
# Remove swap devices not listed in swapDevices.
|
||||||
|
for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
|
||||||
|
found=
|
||||||
|
for device in $swapDevices; do
|
||||||
|
device=$(readlink -f $device)
|
||||||
|
if test "$used" = "$device"; then found=1; fi
|
||||||
|
done
|
||||||
|
if test -z "$found"; then
|
||||||
|
${utillinux}/sbin/swapoff "$used" || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
{
|
|
||||||
require = [options];
|
|
||||||
|
|
||||||
services.extraJobs = [{
|
|
||||||
name = "swap";
|
|
||||||
|
|
||||||
job = ''
|
|
||||||
start on startup
|
|
||||||
start on new-devices
|
|
||||||
|
|
||||||
script
|
|
||||||
for device in ${toString devicesByPath}; do
|
|
||||||
${utillinux}/sbin/swapon "$device" || true
|
|
||||||
done
|
|
||||||
|
|
||||||
for label in ${toString devicesByLabel}; do
|
|
||||||
${utillinux}/sbin/swapon -L "$label" || true
|
|
||||||
done
|
|
||||||
|
|
||||||
# Remove swap devices not listed in swapDevices.
|
|
||||||
# !!! disabled because it doesn't work with labels
|
|
||||||
#for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
|
|
||||||
# found=
|
|
||||||
# for device in $ {toString swapDevices}; do
|
|
||||||
# if test "$used" = "$device"; then found=1; fi
|
|
||||||
# done
|
|
||||||
# if test -z "$found"; then
|
|
||||||
# ${utillinux}/sbin/swapoff "$used" || true
|
|
||||||
# fi
|
|
||||||
#done
|
|
||||||
|
|
||||||
end script
|
|
||||||
'';
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user