2009-01-02 17:06:46 +01:00
|
|
|
# generate the script used to activate the configuration.
|
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
let
|
2009-12-11 01:51:13 +01:00
|
|
|
inherit (pkgs.lib) mkOption mergeTypedOption mergeAttrs
|
2009-05-27 11:40:55 +02:00
|
|
|
mapAttrs addErrorContext fold id filter textClosureMap noDepEntry
|
|
|
|
fullDepEntry;
|
2009-05-20 03:35:46 +02:00
|
|
|
inherit (builtins) attrNames;
|
2009-01-02 17:06:46 +01:00
|
|
|
|
2009-05-20 03:35:46 +02:00
|
|
|
addAttributeName = mapAttrs (a: v: v // {
|
2009-01-02 17:07:24 +01:00
|
|
|
text = ''
|
2009-05-20 03:35:46 +02:00
|
|
|
#### actionScripts snippet ${a} :
|
|
|
|
# ========================================
|
2009-01-02 17:07:24 +01:00
|
|
|
${v.text}
|
|
|
|
'';
|
|
|
|
});
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
defaultScripts = {
|
|
|
|
|
|
|
|
systemConfig = noDepEntry ''
|
|
|
|
systemConfig="$1"
|
|
|
|
if test -z "$systemConfig"; then
|
|
|
|
systemConfig="/system" # for the installation CD
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
defaultPath =
|
|
|
|
let path = [
|
|
|
|
pkgs.coreutils pkgs.gnugrep pkgs.findutils
|
|
|
|
pkgs.glibc # needed for getent
|
2010-06-02 23:10:48 +02:00
|
|
|
pkgs.shadow
|
2009-05-27 11:40:55 +02:00
|
|
|
pkgs.nettools # needed for hostname
|
|
|
|
]; in noDepEntry ''
|
|
|
|
export PATH=/empty
|
|
|
|
for i in ${toString path}; do
|
|
|
|
PATH=$PATH:$i/bin:$i/sbin;
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
stdio = fullDepEntry ''
|
|
|
|
# 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
|
|
|
|
'' [
|
|
|
|
"defaultPath" # path to ln
|
|
|
|
];
|
|
|
|
|
|
|
|
binsh = fullDepEntry ''
|
|
|
|
# Create the required /bin/sh symlink; otherwise lots of things
|
|
|
|
# (notably the system() function) won't work.
|
|
|
|
mkdir -m 0755 -p $mountPoint/bin
|
|
|
|
ln -sfn ${config.system.build.binsh}/bin/sh $mountPoint/bin/sh
|
|
|
|
'' [
|
|
|
|
"defaultPath" # path to ln & mkdir
|
|
|
|
"stdio" # ?
|
|
|
|
];
|
|
|
|
|
|
|
|
modprobe = fullDepEntry ''
|
2009-08-03 14:17:23 +02:00
|
|
|
# Allow the kernel to find our wrapped modprobe (which searches
|
|
|
|
# in the right location in the Nix store for kernel modules).
|
|
|
|
# We need this when the kernel (or some module) auto-loads a
|
2010-07-18 22:19:27 +02:00
|
|
|
# module.
|
|
|
|
echo ${config.system.sbin.modprobe}/sbin/modprobe > /proc/sys/kernel/modprobe
|
2009-05-27 11:40:55 +02:00
|
|
|
'' [
|
|
|
|
# ?
|
|
|
|
];
|
|
|
|
|
|
|
|
var = fullDepEntry ''
|
|
|
|
# Various log/runtime directories.
|
|
|
|
|
|
|
|
touch /var/run/utmp # must exist
|
2010-04-22 16:54:09 +02:00
|
|
|
chgrp ${toString config.ids.gids.utmp} /var/run/utmp
|
2010-04-22 15:56:26 +02:00
|
|
|
chmod 664 /var/run/utmp
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
mkdir -m 0755 -p /var/run/nix/current-load # for distributed builds
|
|
|
|
mkdir -m 0700 -p /var/run/nix/remote-stores
|
|
|
|
|
|
|
|
mkdir -m 0755 -p /var/log
|
2010-06-01 21:44:23 +02:00
|
|
|
mkdir -m 0755 -p /var/log/upstart
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
touch /var/log/wtmp # must exist
|
|
|
|
chmod 644 /var/log/wtmp
|
|
|
|
|
|
|
|
touch /var/log/lastlog
|
|
|
|
chmod 644 /var/log/lastlog
|
|
|
|
|
|
|
|
mkdir -m 1777 -p /var/tmp
|
|
|
|
|
|
|
|
# Empty, read-only home directory of many system accounts.
|
|
|
|
mkdir -m 0555 -p /var/empty
|
|
|
|
'' [
|
|
|
|
"defaultPath" # path to mkdir & touch & chmod
|
|
|
|
];
|
|
|
|
|
|
|
|
rootPasswd = fullDepEntry ''
|
|
|
|
# If there is no password file yet, create a root account with an
|
|
|
|
# empty password.
|
|
|
|
if ! test -e /etc/passwd; then
|
|
|
|
rootHome=/root
|
|
|
|
touch /etc/passwd; chmod 0644 /etc/passwd
|
|
|
|
touch /etc/group; chmod 0644 /etc/group
|
|
|
|
touch /etc/shadow; chmod 0600 /etc/shadow
|
|
|
|
# Can't use useradd, since it complains that it doesn't know us
|
|
|
|
# (bootstrap problem!).
|
2009-05-28 14:24:56 +02:00
|
|
|
echo "root:x:0:0:System administrator:$rootHome:${config.users.defaultUserShell}" >> /etc/passwd
|
2009-05-27 11:40:55 +02:00
|
|
|
echo "root::::::::" >> /etc/shadow
|
|
|
|
fi
|
|
|
|
'' [
|
|
|
|
"defaultPath" # path to touch & passwd
|
|
|
|
"etc" # for /etc
|
|
|
|
# ?
|
|
|
|
];
|
|
|
|
|
|
|
|
nix = fullDepEntry ''
|
|
|
|
# Set up Nix.
|
|
|
|
mkdir -p /nix/etc/nix
|
|
|
|
ln -sfn /etc/nix.conf /nix/etc/nix/nix.conf
|
2009-10-30 09:37:08 +01:00
|
|
|
chown root.nixbld /nix/store
|
|
|
|
chmod 1775 /nix/store
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
# Nix initialisation.
|
|
|
|
mkdir -m 0755 -p \
|
|
|
|
/nix/var/nix/gcroots \
|
|
|
|
/nix/var/nix/temproots \
|
|
|
|
/nix/var/nix/manifests \
|
|
|
|
/nix/var/nix/userpool \
|
|
|
|
/nix/var/nix/profiles \
|
|
|
|
/nix/var/nix/db \
|
|
|
|
/nix/var/log/nix/drvs \
|
|
|
|
/nix/var/nix/channel-cache \
|
|
|
|
/nix/var/nix/chroots
|
|
|
|
mkdir -m 1777 -p /nix/var/nix/gcroots/per-user
|
|
|
|
mkdir -m 1777 -p /nix/var/nix/profiles/per-user
|
|
|
|
|
|
|
|
ln -sf /nix/var/nix/profiles /nix/var/nix/gcroots/
|
|
|
|
ln -sf /nix/var/nix/manifests /nix/var/nix/gcroots/
|
|
|
|
'' [
|
|
|
|
"defaultPath"
|
|
|
|
"etc" # /etc/nix.conf
|
|
|
|
"users" # nixbld group
|
|
|
|
];
|
|
|
|
|
|
|
|
hostname = fullDepEntry ''
|
|
|
|
# Set the host name. Don't clear it if it's not configured in the
|
|
|
|
# NixOS configuration, since it may have been set by dhclient in the
|
|
|
|
# meantime.
|
|
|
|
${if config.networking.hostName != "" then
|
|
|
|
''hostname "${config.networking.hostName}"''
|
|
|
|
else ''
|
|
|
|
# dhclient won't do anything if the hostname isn't empty.
|
|
|
|
if test "$(hostname)" = "(none)"; then
|
|
|
|
hostname ""
|
|
|
|
fi
|
|
|
|
''}
|
|
|
|
'' [ "defaultPath" ];
|
|
|
|
|
|
|
|
# The activation has to be done at the end. This is forced at the apply
|
|
|
|
# function of activationScripts option
|
|
|
|
activate = noDepEntry ''
|
|
|
|
# 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.
|
|
|
|
ln -sfn /var/run/current-system /nix/var/nix/gcroots/current-system
|
|
|
|
'';
|
2009-09-26 12:27:47 +02:00
|
|
|
|
|
|
|
media = noDepEntry ''
|
|
|
|
mkdir -p /media
|
|
|
|
'';
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-02 17:06:46 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2009-05-27 11:40:55 +02:00
|
|
|
require = {
|
|
|
|
system = {
|
|
|
|
activationScripts = mkOption {
|
|
|
|
default = [];
|
|
|
|
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 = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Activate the new configuration (i.e., update /etc, make accounts,
|
|
|
|
and so on).
|
|
|
|
'';
|
|
|
|
merge = mergeTypedOption "script" builtins.isAttrs (fold mergeAttrs {});
|
|
|
|
apply = set:
|
|
|
|
let withHeadlines = addAttributeName set;
|
|
|
|
activateLib = removeAttrs withHeadlines ["activate"];
|
|
|
|
activateLibNames = attrNames activateLib;
|
|
|
|
in {
|
|
|
|
script = pkgs.writeScript "nixos-activation-script"
|
2009-06-05 17:03:56 +02:00
|
|
|
("#! ${pkgs.stdenv.shell}\n"
|
2009-05-27 11:40:55 +02:00
|
|
|
+ textClosureMap id activateLib activateLibNames + "\n"
|
|
|
|
# make sure that the activate snippet is added last.
|
|
|
|
+ withHeadlines.activate.text);
|
2009-01-02 17:06:46 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2009-05-27 11:40:55 +02:00
|
|
|
|
|
|
|
system.activationScripts = defaultScripts;
|
2009-01-02 17:06:46 +01:00
|
|
|
}
|