* Refactoring: moved some options out of system/options.nix (almost

empty now), do more of bashrc.sh declaratively, and moved nsswitch
  generation to modules/config/nsswitch.nix.

svn path=/nixos/branches/modular-nixos/; revision=15754
wip/yesman
Eelco Dolstra 15 years ago
parent 0109b7e44f
commit 3c6ae39a0d
  1. 6
      default.nix
  2. 6
      etc/bashrc.sh
  3. 5
      etc/default.nix
  4. 2
      maintainers/scripts/gen-module-list.sh
  5. 0
      modules/config/nsswitch-mdns.conf
  6. 0
      modules/config/nsswitch.conf
  7. 56
      modules/config/nsswitch.nix
  8. 25
      modules/config/timezone.nix
  9. 9
      modules/installer/grub/grub.nix
  10. 20
      modules/module-list.nix
  11. 13
      modules/services/hardware/udev.nix
  12. 16
      modules/services/networking/avahi-daemon.nix
  13. 10
      modules/system/boot/stage-1.nix
  14. 27
      modules/system/boot/stage-2.nix
  15. 8
      modules/system/upstart/upstart.nix
  16. 161
      system/options.nix
  17. 253
      upstart-jobs/filesystems.nix
  18. 95
      upstart-jobs/swap.nix

@ -23,11 +23,9 @@ in
config.environment.checkConfigurationOptions
optionDeclarations config;
nix = config.environment.nix;
# The following are used by nixos-rebuild.
nixFallback = pkgs.nixUnstable;
manifests = config.installer.manifests; # exported here because nixos-rebuild uses it
manifests = config.installer.manifests;
tests = config.tests;
}

@ -1,15 +1,10 @@
# Initialise a bunch of environment variables.
export PATH=/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
export LD_LIBRARY_PATH=/var/run/opengl-driver/lib
if test -n "@nssModulesPath@"; then
LD_LIBRARY_PATH=@nssModulesPath@:$LD_LIBRARY_PATH
fi
export MODULE_DIR=@modulesTree@/lib/modules
export NIXPKGS_CONFIG=/nix/etc/config.nix
export NIXPKGS_ALL=/etc/nixos/nixpkgs
export PAGER="less -R"
export TZ=@timeZone@
export TZDIR=@glibc@/share/zoneinfo
export FONTCONFIG_FILE=/etc/fonts/fonts.conf
export LANG=@defaultLocale@
export EDITOR=nano
@ -18,6 +13,7 @@ export LOCATE_PATH=/var/cache/locatedb
@shellInit@
export LOCALE_ARCHIVE=/var/run/current-system/sw/lib/locale/locale-archive
# Set up secure multi-user builds: non-root users build through the
# Nix daemon.
if test "$USER" != root; then

@ -38,7 +38,6 @@ let
shellInit = config.environment.shellInit;
nixEnvVars = config.nix.envVars;
modulesTree = config.system.modulesTree;
nssModulesPath = config.system.nssModules.path;
wrapperDir = config.security.wrapperDir;
systemPath = config.system.path;
binsh = config.system.build.binsh;
@ -121,9 +120,7 @@ let
{ # Script executed when the shell starts as a non-login shell (system-wide version).
source = pkgs.substituteAll {
src = ./bashrc.sh;
inherit systemPath wrapperDir modulesTree nssModulesPath;
inherit (pkgs) glibc;
timeZone = config.time.timeZone;
inherit systemPath wrapperDir modulesTree;
defaultLocale = config.i18n.defaultLocale;
inherit nixEnvVars shellInit;
};

@ -34,7 +34,7 @@ generate_index(){
local path="$1"
cd "$path"
echo -n "$path: " 1>&2
{ echo "[ # This file have been generated by $(basename $prog)";
{ echo "[ # This file has been generated by $(basename $prog)";
for file in : $(find ./ -wholename '*.impl[./]*' -or -wholename './module-list.nix' -or -type f -name '*.nix' -print | sort); do
[ "$file" = ':' ] && continue;
echo -n . 1>&2

@ -0,0 +1,56 @@
# Configuration for the Name Service Switch (/etc/nsswitch.conf).
{config, pkgs, ...}:
let
options = {
# NSS modules. Hacky!
system.nssModules = pkgs.lib.mkOption {
internal = true;
default = [];
description = "
Search path for NSS (Name Service Switch) modules. This allows
several DNS resolution methods to be specified via
<filename>/etc/nsswitch.conf</filename>.
";
merge = pkgs.lib.mergeListOption;
apply = list:
let
list2 =
list
# !!! this should be in the LDAP module
++ pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap;
in {
list = list2;
path = pkgs.lib.makeLibraryPath list2;
};
};
};
in
{
require = [options];
environment.etc =
[ # Name Service Switch configuration file. Required by the C library.
# !!! Factor out the mdns stuff. The avahi module should define
# an option used by this module.
{ source =
if config.services.avahi.nssmdns
then ./nsswitch-mdns.conf
else ./nsswitch.conf;
target = "nsswitch.conf";
}
];
environment.shellInit =
if config.system.nssModules.path != "" then
''
LD_LIBRARY_PATH=${config.system.nssModules.path}:$LD_LIBRARY_PATH
''
else "";
}

@ -0,0 +1,25 @@
{pkgs, config, ...}:
let
options = {
time.timeZone = pkgs.lib.mkOption {
default = "CET";
example = "America/New_York";
description = "The time zone used when displaying times and dates.";
};
};
in
{
require = [options];
environment.shellInit =
''
export TZ=${config.time.timeZone}
export TZDIR=${pkgs.glibc}/share/zoneinfo
'';
}

@ -77,6 +77,15 @@ let
";
};
copyKernels = mkOption {
default = false;
description = "
Whether the Grub menu builder should copy kernels and initial
ramdisks to /boot. This is necessary when /nix is on a
different file system than /boot.
";
};
};
};
in

@ -1,10 +1,13 @@
[ # This file have been generated by gen-module-list.sh
./config/fonts.nix
./config/i18n.nix
./config/nsswitch.nix
./config/system-path.nix
./config/timezone.nix
./config/unix-odbc-drivers.nix
./config/users-groups.nix
./config/system-path.nix
./installer/grub/grub.nix
./legacy.nix
./security/setuid-wrappers.nix
./security/sudo.nix
./services/audio/alsa.nix
@ -59,27 +62,27 @@
##### ./services/web-servers/apache-httpd/per-server-options.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/services/web-servers/apache-httpd/per-server-options.nix:6:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/services/web-servers/apache-httpd/per-server-options.nix:6:2':
# the argument named `forMainServer' required by the function is missing
##### ./services/web-servers/apache-httpd/subversion.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/services/web-servers/apache-httpd/subversion.nix:1:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/services/web-servers/apache-httpd/subversion.nix:1:2':
# the argument named `serverInfo' required by the function is missing
##### ./services/web-servers/apache-httpd/tomcat-connector.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/services/web-servers/apache-httpd/tomcat-connector.nix:1:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/services/web-servers/apache-httpd/tomcat-connector.nix:1:2':
# the argument named `serverInfo' required by the function is missing
##### ./services/web-servers/apache-httpd/twiki.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/services/web-servers/apache-httpd/twiki.nix:1:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/services/web-servers/apache-httpd/twiki.nix:1:2':
# the argument named `serverInfo' required by the function is missing
##### ./services/web-servers/apache-httpd/zabbix.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/services/web-servers/apache-httpd/zabbix.nix:1:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/services/web-servers/apache-httpd/zabbix.nix:1:2':
# the argument named `serverInfo' required by the function is missing
./services/web-servers/jboss.nix
./services/web-servers/tomcat.nix
@ -87,9 +90,9 @@
./services/x11/xserver/default.nix
./services/x11/xserver/desktop-managers/default.nix
./services/x11/xserver/desktop-managers/gnome.nix
./services/x11/xserver/desktop-managers/kde4.nix
./services/x11/xserver/desktop-managers/kde-environment.nix
./services/x11/xserver/desktop-managers/kde.nix
./services/x11/xserver/desktop-managers/kde4.nix
./services/x11/xserver/desktop-managers/none.nix
./services/x11/xserver/desktop-managers/xterm.nix
./services/x11/xserver/display-managers/default.nix
@ -114,9 +117,8 @@
##### ./system/upstart/make-job.nix
# error: while evaluating the attribute `<let-body>' at `(string):2:8':
# while evaluating the function at `(string):3:22':
# while evaluating the function at `/trace/nixos/modules/system/upstart/make-job.nix:1:2':
# while evaluating the function at `/home/eelco/Dev/modular-nixos/modules/system/upstart/make-job.nix:1:2':
# the argument named `runCommand' required by the function is missing
./system/upstart/tools.nix
./system/upstart/upstart.nix
./legacy.nix
]

@ -5,6 +5,19 @@ let
inherit (pkgs.lib) mkOption mkIf;
options = {
boot.hardwareScan = mkOption {
default = true;
description = "
Whether to try to load kernel modules for all detected hardware.
Usually this does a good job of providing you with the modules
you need, but sometimes it can crash the system or cause other
nasty effects. If the hardware scan is turned on, it can be
disabled at boot time by adding the <literal>safemode</literal>
parameter to the kernel command line.
";
};
services = {
udev = {

@ -136,22 +136,6 @@ mkIf cfg.enable {
environment = {
extraPackages = [avahi];
# Name Service Switch configuration file. Required by the C library.
# !!! This should be done in some other way, e.g., this module
# should define an option used by the hypothetical module that
# generates nsswitch.conf.
etc = mkIf cfg.nssmdns (mkThenElse {
thenPart = [{
source = ../../../etc/nsswitch-mdns.conf;
target = "nsswitch.conf";
}];
elsePart = [{
source = ../../../etc/nsswitch.conf;
target = "nsswitch.conf";
}];
});
};
users = {

@ -11,6 +11,16 @@ let
options = {
boot.isLiveCD = mkOption {
default = false;
description = "
If set to true, the root device will be mounted read-only and
a ramdisk will be mounted on top of it using unionfs to
provide a writable root. This is used for the NixOS
Live-CD/DVD.
";
};
boot.resumeDevice = mkOption {
default = "";
example = "0:0";

@ -1,10 +1,22 @@
{pkgs, config, ...}:
let
options = {
boot.localCommands = pkgs.lib.mkOption {
default = "";
example = "text=anything; echo You can put $text here.";
description = "
Shell commands to be executed just before Upstart is started.
";
};
};
inherit (pkgs) substituteAll writeText coreutils utillinux udev upstart;
kernel = config.boot.kernelPackages.kernel;
activateConfiguration = config.system.activationScripts.script;
inherit (config.boot) isLiveCD;
# Path for Upstart jobs. Should be quite minimal.
upstartPath = [
@ -20,7 +32,7 @@ let
bootStage2 = substituteAll {
src = ./stage-2-init.sh;
isExecutable = true;
inherit kernel upstart isLiveCD activateConfiguration upstartPath;
inherit kernel upstart activateConfiguration upstartPath;
path = [
coreutils
utillinux
@ -32,16 +44,7 @@ let
in
{
require = [
# config.boot.localCommands
# config.boot.kernelPackages
# config.system.activationScripts
# ../system/activate-configuration.nix
# config.system.build
# ../system/system-options.nix
];
require = [options];
system = {
build = {

@ -52,14 +52,6 @@ in
###### implementation
let
# should be moved to the corresponding jobs.
nix = config.environment.nix;
nixEnvVars = config.nix.envVars;
kernelPackages = config.boot.kernelPackages;
nssModulesPath = config.system.nssModules.path;
modprobe = config.system.sbin.modprobe;
mount = config.system.sbin.mount;
makeJob = import ./make-job.nix {
inherit (pkgs) runCommand;
};

@ -6,58 +6,8 @@ in
{
time = {
timeZone = mkOption {
default = "CET";
example = "America/New_York";
description = "The time zone used when displaying times and dates.";
};
};
boot = {
isLiveCD = mkOption {
default = false;
description = "
If set to true, the root device will be mounted read-only and
a ramdisk will be mounted on top of it using unionfs to
provide a writable root. This is used for the NixOS
Live-CD/DVD.
";
};
hardwareScan = mkOption {
default = true;
description = "
Whether to try to load kernel modules for all detected hardware.
Usually this does a good job of providing you with the modules
you need, but sometimes it can crash the system or cause other
nasty effects. If the hardware scan is turned on, it can be
disabled at boot time by adding the <literal>safemode</literal>
parameter to the kernel command line.
";
};
copyKernels = mkOption {
default = false;
description = "
Whether the Grub menu builder should copy kernels and initial
ramdisks to /boot. This is necessary when /nix is on a
different file system than /boot.
";
};
localCommands = mkOption {
default = "";
example = "text=anything; echo You can put $text here.";
description = "
Shell commands to be executed just before Upstart is started.
";
};
extraTTYs = mkOption {
default = [];
example = [8 9];
@ -73,53 +23,6 @@ in
};
system = {
# NSS modules. Hacky!
nssModules = mkOption {
internal = true;
default = [];
description = "
Search path for NSS (Name Service Switch) modules. This allows
several DNS resolution methods to be specified via
<filename>/etc/nsswitch.conf</filename>.
";
merge = pkgs.lib.mergeListOption;
apply = list:
let
list2 =
list
++ pkgs.lib.optional config.users.ldap.enable pkgs.nss_ldap;
in {
list = list2;
path = pkgs.lib.makeLibraryPath list2;
};
};
sbin = {
# !!! The mount option should not stay in /system/option.nix
mount = mkOption {
internal = true;
default = pkgs.utillinuxng.override {
buildMountOnly = true;
mountHelpers = pkgs.buildEnv {
name = "mount-helpers";
paths = [
pkgs.ntfs3g
pkgs.mount_cifs
pkgs.nfsUtils
];
pathsToLink = "/sbin";
} + "/sbin";
};
description = "
A patched `mount' command that looks in a directory in the Nix
store instead of in /sbin for mount helpers (like mount.ntfs-3g or
mount.cifs).
";
};
};
};
networking = {
@ -239,61 +142,6 @@ in
};
fileSystems = mkOption {
default = null;
example = [
{ mountPoint = "/";
device = "/dev/hda1";
}
{ mountPoint = "/data";
device = "/dev/hda2";
fsType = "ext3";
options = "data=journal";
}
{ mountPoint = "/bigdisk";
label = "bigdisk";
}
];
description = "
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = \"/\"</literal>). Each
entry in the list is an attribute set with the following fields:
<literal>mountPoint</literal>, <literal>device</literal>,
<literal>fsType</literal> (a file system type recognised by
<command>mount</command>; defaults to
<literal>\"auto\"</literal>), and <literal>options</literal>
(the mount options passed to <command>mount</command> using the
<option>-o</option> flag; defaults to <literal>\"defaults\"</literal>).
Instead of specifying <literal>device</literal>, you can also
specify a volume label (<literal>label</literal>) for file
systems that support it, such as ext2/ext3 (see <command>mke2fs
-L</command>).
<literal>autocreate</literal> forces <literal>mountPoint</literal> to be created with
<command>mkdir -p</command> .
";
};
swapDevices = mkOption {
default = [];
example = [
{ device = "/dev/hda7"; }
{ device = "/var/swapfile"; }
{ label = "bigswap"; }
];
description = "
The swap devices and swap files. These must have been
initialised using <command>mkswap</command>. Each element
should be an attribute set specifying either the path of the
swap device or file (<literal>device</literal>) or the label
of the swap device (<literal>label</literal>, see
<command>mkswap -L</command>). Using a label is
recommended.
";
};
nesting = {
children = mkOption {
default = [];
@ -304,14 +152,5 @@ in
};
passthru = mkOption {
default = {};
description = "
Additional parameters. Ignored. When you want to be sure that
/etc/nixos/nixos -A config.passthru.* is that same thing the
system rebuild will use.
";
};
require = import ../modules/module-list.nix;
}

@ -1,11 +1,75 @@
{pkgs, config, ...}:
let
###### interface
options = {
fileSystems = pkgs.lib.mkOption {
default = null;
example = [
{ mountPoint = "/";
device = "/dev/hda1";
}
{ mountPoint = "/data";
device = "/dev/hda2";
fsType = "ext3";
options = "data=journal";
}
{ mountPoint = "/bigdisk";
label = "bigdisk";
}
];
description = "
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = \"/\"</literal>). Each
entry in the list is an attribute set with the following fields:
<literal>mountPoint</literal>, <literal>device</literal>,
<literal>fsType</literal> (a file system type recognised by
<command>mount</command>; defaults to
<literal>\"auto\"</literal>), and <literal>options</literal>
(the mount options passed to <command>mount</command> using the
<option>-o</option> flag; defaults to <literal>\"defaults\"</literal>).
Instead of specifying <literal>device</literal>, you can also
specify a volume label (<literal>label</literal>) for file
systems that support it, such as ext2/ext3 (see <command>mke2fs
-L</command>).
<literal>autocreate</literal> forces <literal>mountPoint</literal> to be created with
<command>mkdir -p</command> .
";
};
system.sbin.mount = pkgs.lib.mkOption {
internal = true;
default = pkgs.utillinuxng.override {
buildMountOnly = true;
mountHelpers = pkgs.buildEnv {
name = "mount-helpers";
paths = [
pkgs.ntfs3g
pkgs.mount_cifs
pkgs.nfsUtils
];
pathsToLink = "/sbin";
} + "/sbin";
};
description = "
A patched `mount' command that looks in a directory in the Nix
store instead of in /sbin for mount helpers (like mount.ntfs-3g or
mount.cifs).
";
};
};
###### implementation
let
inherit (pkgs) e2fsprogs;
mountPoints = map (fs: fs.mountPoint) fileSystems;
fileSystems = config.fileSystems;
mountPoints = map (fs: fs.mountPoint) fileSystems;
devices = map (fs: if fs ? device then fs.device else "LABEL=" + fs.label) fileSystems;
fsTypes = map (fs: if fs ? fsType then fs.fsType else "auto") fileSystems;
optionss = map (fs: if fs ? options then fs.options else "defaults") fileSystems;
@ -13,110 +77,111 @@ let
mount = config.system.sbin.mount;
job = ''
start on startup
start on new-devices
start on ip-up
script
PATH=${e2fsprogs}/sbin:$PATH
mountPoints=(${toString mountPoints})
devices=(${toString devices})
fsTypes=(${toString fsTypes})
optionss=(${toString optionss})
autocreates=(${toString autocreates})
newDevices=1
# If we mount any file system, we repeat this loop, because new
# mount opportunities may have become available (such as images
# for loopback mounts).
while test -n "$newDevices"; do
newDevices=
for ((n = 0; n < ''${#mountPoints[*]}; n++)); do
mountPoint=''${mountPoints[$n]}
device=''${devices[$n]}
fsType=''${fsTypes[$n]}
options=''${optionss[$n]}
autocreate=''${autocreates[$n]}
isLabel=
if echo "$device" | grep -q '^LABEL='; then isLabel=1; fi
isPseudo=
if test "$fsType" = "nfs" || test "$fsType" = "tmpfs" ||
test "$fsType" = "ext3cow"; then isPseudo=1; fi
if ! test -n "$isLabel" -o -n "$isPseudo" -o -e "$device"; then
echo "skipping $device, doesn't exist (yet)"
continue
fi
# !!! quick hack: if mount point already exists, try a
# remount to change the options but nothing else.
if cat /proc/mounts | grep -F -q " $mountPoint "; then
echo "remounting $device on $mountPoint"
${mount}/bin/mount -t "$fsType" \
-o remount,"$options" \
"$device" "$mountPoint" || true
continue
fi
# If $device is already mounted somewhere else, unmount it first.
# !!! Note: we use /etc/mtab, not /proc/mounts, because mtab
# contains more accurate info when using loop devices.
# !!! not very smart about labels yet; should resolve the label somehow.
if test -z "$isLabel" -a -z "$isPseudo"; then
device=$(readlink -f "$device")
prevMountPoint=$(
cat /etc/mtab \
| grep "^$device " \
| sed 's|^[^ ]\+ \+\([^ ]\+\).*|\1|' \
)
if test "$prevMountPoint" = "$mountPoint"; then
start on startup
start on new-devices
start on ip-up
script
PATH=${e2fsprogs}/sbin:$PATH
mountPoints=(${toString mountPoints})
devices=(${toString devices})
fsTypes=(${toString fsTypes})
optionss=(${toString optionss})
autocreates=(${toString autocreates})
newDevices=1
# If we mount any file system, we repeat this loop, because new
# mount opportunities may have become available (such as images
# for loopback mounts).
while test -n "$newDevices"; do
newDevices=
for ((n = 0; n < ''${#mountPoints[*]}; n++)); do
mountPoint=''${mountPoints[$n]}
device=''${devices[$n]}
fsType=''${fsTypes[$n]}
options=''${optionss[$n]}
autocreate=''${autocreates[$n]}
isLabel=
if echo "$device" | grep -q '^LABEL='; then isLabel=1; fi
isPseudo=
if test "$fsType" = "nfs" || test "$fsType" = "tmpfs" ||
test "$fsType" = "ext3cow"; then isPseudo=1; fi
if ! test -n "$isLabel" -o -n "$isPseudo" -o -e "$device"; then
echo "skipping $device, doesn't exist (yet)"
continue
fi
# !!! quick hack: if mount point already exists, try a
# remount to change the options but nothing else.
if cat /proc/mounts | grep -F -q " $mountPoint "; then
echo "remounting $device on $mountPoint"
${mount}/bin/mount -t "$fsType" \
-o remount,"$options" \
"$device" "$mountPoint" || true
continue
fi
if test -n "$prevMountPoint"; then
echo "unmount $device from $prevMountPoint"
${mount}/bin/umount "$prevMountPoint" || true
# If $device is already mounted somewhere else, unmount it first.
# !!! Note: we use /etc/mtab, not /proc/mounts, because mtab
# contains more accurate info when using loop devices.
# !!! not very smart about labels yet; should resolve the label somehow.
if test -z "$isLabel" -a -z "$isPseudo"; then
device=$(readlink -f "$device")
prevMountPoint=$(
cat /etc/mtab \
| grep "^$device " \
| sed 's|^[^ ]\+ \+\([^ ]\+\).*|\1|' \
)
if test "$prevMountPoint" = "$mountPoint"; then
echo "remounting $device on $mountPoint"
${mount}/bin/mount -t "$fsType" \
-o remount,"$options" \
"$device" "$mountPoint" || true
continue
fi
if test -n "$prevMountPoint"; then
echo "unmount $device from $prevMountPoint"
${mount}/bin/umount "$prevMountPoint" || true
fi
fi
fi
echo "mounting $device on $mountPoint"
# !!! should do something with the result; also prevent repeated fscks.
if test -z "$isPseudo"; then
fsck -a "$device" || true
fi
if test "$autocreate" = 1; then mkdir -p "$mountPoint"; fi
if ${mount}/bin/mount -t "$fsType" -o "$options" "$device" "$mountPoint"; then
newDevices=1
fi
echo "mounting $device on $mountPoint"
# !!! should do something with the result; also prevent repeated fscks.
if test -z "$isPseudo"; then
fsck -a "$device" || true
fi
if test "$autocreate" = 1; then mkdir -p "$mountPoint"; fi
if ${mount}/bin/mount -t "$fsType" -o "$options" "$device" "$mountPoint"; then
newDevices=1
fi
done
done
done
end script
end script
'';
in
{
require = [options];
services = {
extraJobs = [{
name = "filesystems";

@ -1,9 +1,34 @@
{pkgs, config, ...}:
###### implementation
let
###### interface
options = {
swapDevices = pkgs.lib.mkOption {
default = [];
example = [
{ device = "/dev/hda7"; }
{ device = "/var/swapfile"; }
{ label = "bigswap"; }
];
description = "
The swap devices and swap files. These must have been
initialised using <command>mkswap</command>. Each element
should be an attribute set specifying either the path of the
swap device or file (<literal>device</literal>) or the label
of the swap device (<literal>label</literal>, see
<command>mkswap -L</command>). Using a label is
recommended.
";
};
};
###### implementation
inherit (pkgs) utillinux lib;
swapDevices = config.swapDevices;
@ -18,37 +43,37 @@ in
{
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
";
}];
};
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…
Cancel
Save