2009-01-02 16:06:46 +00:00
|
|
|
# generate the script used to activate the configuration.
|
2010-09-13 16:41:38 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-01-02 16:06:46 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-05-20 02:35:46 +01:00
|
|
|
addAttributeName = mapAttrs (a: v: v // {
|
2010-09-13 16:41:38 +01:00
|
|
|
text = ''
|
|
|
|
#### Activation script snippet ${a}:
|
|
|
|
${v.text}
|
2009-05-27 10:40:55 +01:00
|
|
|
'';
|
2010-09-13 16:41:38 +01:00
|
|
|
});
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
path =
|
|
|
|
[ pkgs.coreutils pkgs.gnugrep pkgs.findutils
|
|
|
|
pkgs.glibc # needed for getent
|
|
|
|
pkgs.shadow
|
|
|
|
pkgs.nettools # needed for hostname
|
2009-05-27 10:40:55 +01:00
|
|
|
];
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
in
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
{
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
system.activationScripts = mkOption {
|
|
|
|
default = {};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
example = {
|
|
|
|
stdio = {
|
|
|
|
text = ''
|
|
|
|
# Needed by some programs.
|
|
|
|
ln -sfn /proc/self/fd /dev/fd
|
|
|
|
ln -sfn /proc/self/fd/0 /dev/stdin
|
|
|
|
ln -sfn /proc/self/fd/1 /dev/stdout
|
|
|
|
ln -sfn /proc/self/fd/2 /dev/stderr
|
|
|
|
'';
|
|
|
|
deps = [];
|
|
|
|
};
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
description = ''
|
|
|
|
Activate the new configuration (i.e., update /etc, make accounts,
|
|
|
|
and so on).
|
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
merge = mergeTypedOption "script" builtins.isAttrs (fold mergeAttrs {});
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
apply = set: {
|
2010-09-13 19:19:15 +01:00
|
|
|
script =
|
2010-09-13 16:41:38 +01:00
|
|
|
''
|
|
|
|
#! ${pkgs.stdenv.shell}
|
|
|
|
|
2010-09-13 19:19:15 +01:00
|
|
|
systemConfig=@out@
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
export PATH=/empty
|
|
|
|
for i in ${toString path}; do
|
|
|
|
PATH=$PATH:$i/bin:$i/sbin;
|
|
|
|
done
|
2010-09-13 19:19:15 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
${
|
|
|
|
let
|
|
|
|
set' = mapAttrs (n: v: if builtins.isString v then noDepEntry v else v) set;
|
|
|
|
withHeadlines = addAttributeName set';
|
|
|
|
in textClosureMap id (withHeadlines) (attrNames withHeadlines)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make this configuration the current configuration.
|
|
|
|
# The readlink is there to ensure that when $systemConfig = /system
|
|
|
|
# (which is a symlink to the store), /var/run/current-system is still
|
|
|
|
# used as a garbage collection root.
|
|
|
|
ln -sfn "$(readlink -f "$systemConfig")" /var/run/current-system
|
|
|
|
|
|
|
|
# Prevent the current configuration from being garbage-collected.
|
2011-10-30 15:19:58 +00:00
|
|
|
ln -sfn /var/run/current-system /nix/var/nix/gcroots/current-system
|
2010-09-13 16:41:38 +01:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
};
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
###### implementation
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
config = {
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
system.activationScripts.stdio =
|
|
|
|
''
|
|
|
|
# Needed by some programs.
|
|
|
|
ln -sfn /proc/self/fd /dev/fd
|
|
|
|
ln -sfn /proc/self/fd/0 /dev/stdin
|
|
|
|
ln -sfn /proc/self/fd/1 /dev/stdout
|
|
|
|
ln -sfn /proc/self/fd/2 /dev/stderr
|
|
|
|
'';
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
system.activationScripts.var =
|
|
|
|
''
|
|
|
|
# Various log/runtime directories.
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
touch /var/run/utmp # must exist
|
|
|
|
chgrp ${toString config.ids.gids.utmp} /var/run/utmp
|
|
|
|
chmod 664 /var/run/utmp
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
mkdir -m 0755 -p /var/run/nix/current-load # for distributed builds
|
|
|
|
mkdir -m 0700 -p /var/run/nix/remote-stores
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
mkdir -m 0755 -p /var/log
|
|
|
|
mkdir -m 0755 -p /var/log/upstart
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
touch /var/log/wtmp # must exist
|
|
|
|
chmod 644 /var/log/wtmp
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
touch /var/log/lastlog
|
|
|
|
chmod 644 /var/log/lastlog
|
2009-05-27 10:40:55 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
mkdir -m 1777 -p /var/tmp
|
2009-09-26 11:27:47 +01:00
|
|
|
|
2010-09-13 16:41:38 +01:00
|
|
|
# Empty, read-only home directory of many system accounts.
|
|
|
|
mkdir -m 0555 -p /var/empty
|
|
|
|
'';
|
|
|
|
|
|
|
|
system.activationScripts.media =
|
|
|
|
''
|
|
|
|
mkdir -p /media
|
|
|
|
'';
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-05-27 10:40:55 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-01-02 16:06:46 +00:00
|
|
|
}
|