2009-01-02 16:06:46 +00:00
|
|
|
# generate the script used to activate the configuration.
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-09-13 15:41:38 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2009-01-02 16:06:46 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-05-20 01:35:46 +00:00
|
|
|
addAttributeName = mapAttrs (a: v: v // {
|
2010-09-13 15:41:38 +00:00
|
|
|
text = ''
|
|
|
|
#### Activation script snippet ${a}:
|
2018-08-05 23:15:14 +00:00
|
|
|
_localstatus=0
|
2010-09-13 15:41:38 +00:00
|
|
|
${v.text}
|
2018-08-05 23:15:14 +00:00
|
|
|
|
|
|
|
if (( _localstatus > 0 )); then
|
|
|
|
printf "Activation script snippet '%s' failed (%s)\n" "${a}" "$_localstatus"
|
|
|
|
fi
|
2009-05-27 09:40:55 +00:00
|
|
|
'';
|
2010-09-13 15:41:38 +00:00
|
|
|
});
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2016-09-06 15:14:50 +00:00
|
|
|
path = with pkgs; map getBin
|
|
|
|
[ coreutils
|
|
|
|
gnugrep
|
|
|
|
findutils
|
2018-03-24 20:33:47 +00:00
|
|
|
getent
|
2018-10-31 12:00:04 +00:00
|
|
|
stdenv.cc.libc # nscd in update-users-groups.pl
|
2016-09-06 15:14:50 +00:00
|
|
|
shadow
|
|
|
|
nettools # needed for hostname
|
2016-09-17 10:53:12 +00:00
|
|
|
utillinux # needed for mount and mountpoint
|
2009-05-27 09:40:55 +00:00
|
|
|
];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
in
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
{
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
system.activationScripts = mkOption {
|
|
|
|
default = {};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2015-07-04 06:53:26 +00:00
|
|
|
example = literalExample ''
|
|
|
|
{ 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 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
description = ''
|
2013-10-23 14:59:15 +00:00
|
|
|
A set of shell script fragments that are executed when a NixOS
|
|
|
|
system configuration is activated. Examples are updating
|
|
|
|
/etc, creating accounts, and so on. Since these are executed
|
|
|
|
every time you boot the system or run
|
|
|
|
<command>nixos-rebuild</command>, it's important that they are
|
|
|
|
idempotent and fast.
|
2010-09-13 15:41:38 +00:00
|
|
|
'';
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2013-10-27 23:56:22 +00:00
|
|
|
type = types.attrsOf types.unspecified; # FIXME
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
apply = set: {
|
2010-09-13 18:19:15 +00:00
|
|
|
script =
|
2010-09-13 15:41:38 +00:00
|
|
|
''
|
2018-03-01 19:38:53 +00:00
|
|
|
#! ${pkgs.runtimeShell}
|
2010-09-13 15:41:38 +00:00
|
|
|
|
2010-09-13 18:19:15 +00:00
|
|
|
systemConfig=@out@
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
export PATH=/empty
|
|
|
|
for i in ${toString path}; do
|
2012-03-22 10:17:10 +00:00
|
|
|
PATH=$PATH:$i/bin:$i/sbin
|
2010-09-13 15:41:38 +00:00
|
|
|
done
|
2010-09-13 18:19:15 +00:00
|
|
|
|
2014-08-14 23:57:36 +00:00
|
|
|
_status=0
|
2018-08-05 23:15:14 +00:00
|
|
|
trap "_status=1 _localstatus=\$?" ERR
|
2014-08-14 23:57:36 +00:00
|
|
|
|
2012-03-22 10:17:10 +00:00
|
|
|
# Ensure a consistent umask.
|
|
|
|
umask 0022
|
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
${
|
|
|
|
let
|
2013-11-12 12:48:19 +00:00
|
|
|
set' = mapAttrs (n: v: if isString v then noDepEntry v else v) set;
|
2010-09-13 15:41:38 +00:00
|
|
|
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
|
2012-07-16 15:27:59 +00:00
|
|
|
# (which is a symlink to the store), /run/current-system is still
|
2010-09-13 15:41:38 +00:00
|
|
|
# used as a garbage collection root.
|
2012-07-16 15:27:59 +00:00
|
|
|
ln -sfn "$(readlink -f "$systemConfig")" /run/current-system
|
2010-09-13 15:41:38 +00:00
|
|
|
|
|
|
|
# Prevent the current configuration from being garbage-collected.
|
2012-07-16 15:27:59 +00:00
|
|
|
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
|
2014-08-14 23:57:36 +00:00
|
|
|
|
|
|
|
exit $_status
|
2010-09-13 15:41:38 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-10-04 03:57:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
system.userActivationScripts = mkOption {
|
|
|
|
default = {};
|
|
|
|
|
|
|
|
example = literalExample ''
|
|
|
|
{ plasmaSetup = {
|
|
|
|
text = '''
|
|
|
|
${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5"
|
|
|
|
''';
|
|
|
|
deps = [];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
A set of shell script fragments that are executed by a systemd user
|
|
|
|
service when a NixOS system configuration is activated. Examples are
|
|
|
|
rebuilding the .desktop file cache for showing applications in the menu.
|
|
|
|
Since these are executed every time you run
|
|
|
|
<command>nixos-rebuild</command>, it's important that they are
|
|
|
|
idempotent and fast.
|
|
|
|
'';
|
|
|
|
|
|
|
|
type = types.attrsOf types.unspecified;
|
|
|
|
|
|
|
|
apply = set: {
|
|
|
|
script = ''
|
|
|
|
unset PATH
|
|
|
|
for i in ${toString path}; do
|
|
|
|
PATH=$PATH:$i/bin:$i/sbin
|
|
|
|
done
|
|
|
|
|
|
|
|
_status=0
|
|
|
|
trap "_status=1 _localstatus=\$?" ERR
|
|
|
|
|
|
|
|
${
|
|
|
|
let
|
|
|
|
set' = mapAttrs (n: v: if isString v then noDepEntry v else v) set;
|
|
|
|
withHeadlines = addAttributeName set';
|
|
|
|
in textClosureMap id (withHeadlines) (attrNames withHeadlines)
|
|
|
|
}
|
|
|
|
|
|
|
|
exit $_status
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2016-01-19 17:11:36 +00:00
|
|
|
environment.usrbinenv = mkOption {
|
|
|
|
default = "${pkgs.coreutils}/bin/env";
|
|
|
|
example = literalExample ''
|
|
|
|
"''${pkgs.busybox}/bin/env"
|
|
|
|
'';
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
visible = false;
|
|
|
|
description = ''
|
|
|
|
The env(1) executable that is linked system-wide to
|
|
|
|
<literal>/usr/bin/env</literal>.
|
|
|
|
'';
|
|
|
|
};
|
2019-09-18 22:34:41 +00:00
|
|
|
|
|
|
|
environment.ld-linux = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
visible = false;
|
|
|
|
description = ''
|
|
|
|
Install symlink to ld-linux(8) system-wide to allow running unmodified ELF binaries.
|
|
|
|
It might be useful to run games or executables distributed inside jar files.
|
|
|
|
'';
|
|
|
|
};
|
2010-09-13 15:41:38 +00:00
|
|
|
};
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
###### implementation
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
config = {
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2018-02-07 16:58:21 +00:00
|
|
|
system.activationScripts.stdio = ""; # obsolete
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
system.activationScripts.var =
|
|
|
|
''
|
|
|
|
# Various log/runtime directories.
|
2009-05-27 09:40:55 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
mkdir -m 1777 -p /var/tmp
|
2009-09-26 10:27:47 +00:00
|
|
|
|
2016-09-07 08:41:56 +00:00
|
|
|
# Empty, immutable home directory of many system accounts.
|
|
|
|
mkdir -p /var/empty
|
2016-09-06 15:14:50 +00:00
|
|
|
# Make sure it's really empty
|
2016-09-21 08:29:04 +00:00
|
|
|
${pkgs.e2fsprogs}/bin/chattr -f -i /var/empty || true
|
2016-09-07 08:41:56 +00:00
|
|
|
find /var/empty -mindepth 1 -delete
|
|
|
|
chmod 0555 /var/empty
|
2016-10-09 10:01:47 +00:00
|
|
|
chown root:root /var/empty
|
2016-09-21 08:29:04 +00:00
|
|
|
${pkgs.e2fsprogs}/bin/chattr -f +i /var/empty || true
|
2010-09-13 15:41:38 +00:00
|
|
|
'';
|
|
|
|
|
2016-01-19 17:11:36 +00:00
|
|
|
system.activationScripts.usrbinenv = if config.environment.usrbinenv != null
|
|
|
|
then ''
|
2012-03-12 10:41:39 +00:00
|
|
|
mkdir -m 0755 -p /usr/bin
|
2016-01-19 17:11:36 +00:00
|
|
|
ln -sfn ${config.environment.usrbinenv} /usr/bin/.env.tmp
|
2012-03-12 10:41:39 +00:00
|
|
|
mv /usr/bin/.env.tmp /usr/bin/env # atomically replace /usr/bin/env
|
2016-01-19 17:11:36 +00:00
|
|
|
''
|
|
|
|
else ''
|
|
|
|
rm -f /usr/bin/env
|
2019-09-19 00:32:35 +00:00
|
|
|
rmdir -p /usr/bin || true
|
2010-09-13 15:41:38 +00:00
|
|
|
'';
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2019-09-18 22:34:41 +00:00
|
|
|
system.activationScripts.ld-linux =
|
|
|
|
concatStrings (
|
|
|
|
mapAttrsToList
|
|
|
|
(target: source:
|
|
|
|
if config.environment.ld-linux then ''
|
|
|
|
mkdir -m 0755 -p $(dirname ${target})
|
|
|
|
ln -sfn ${escapeShellArg source} ${target}.tmp
|
|
|
|
mv -f ${target}.tmp ${target} # atomically replace
|
|
|
|
'' else ''
|
|
|
|
rm -f ${target}
|
2019-09-19 00:32:35 +00:00
|
|
|
rmdir $(dirname ${target}) || true
|
2019-09-18 22:34:41 +00:00
|
|
|
'')
|
|
|
|
{
|
|
|
|
"i686-linux" ."/lib/ld-linux.so.2" = "${pkgs.glibc.out}/lib/ld-linux.so.2";
|
|
|
|
"x86_64-linux" ."/lib/ld-linux.so.2" = "${pkgs.pkgsi686Linux.glibc.out}/lib/ld-linux.so.2";
|
|
|
|
"x86_64-linux" ."/lib64/ld-linux-x86-64.so.2" = "${pkgs.glibc.out}/lib64/ld-linux-x86-64.so.2";
|
|
|
|
"aarch64-linux"."/lib/ld-linux-aarch64.so.1" = "${pkgs.glibc.out}/lib/ld-linux-aarch64.so.1";
|
|
|
|
"armv7l-linux" ."/lib/ld-linux-armhf.so.3" = "${pkgs.glibc.out}/lib/ld-linux-armhf.so.3";
|
|
|
|
}.${pkgs.stdenv.system} or {}
|
|
|
|
);
|
|
|
|
|
2016-09-26 00:00:41 +00:00
|
|
|
system.activationScripts.specialfs =
|
2012-05-17 19:33:55 +00:00
|
|
|
''
|
2016-08-27 10:29:38 +00:00
|
|
|
specialMount() {
|
|
|
|
local device="$1"
|
|
|
|
local mountPoint="$2"
|
|
|
|
local options="$3"
|
|
|
|
local fsType="$4"
|
|
|
|
|
2016-09-17 10:53:12 +00:00
|
|
|
if mountpoint -q "$mountPoint"; then
|
2016-09-25 23:54:45 +00:00
|
|
|
local options="remount,$options"
|
|
|
|
else
|
|
|
|
mkdir -m 0755 -p "$mountPoint"
|
|
|
|
fi
|
2016-09-17 10:53:12 +00:00
|
|
|
mount -t "$fsType" -o "$options" "$device" "$mountPoint"
|
2016-08-27 10:29:38 +00:00
|
|
|
}
|
|
|
|
source ${config.system.build.earlyMountScript}
|
2012-05-17 19:33:55 +00:00
|
|
|
'';
|
|
|
|
|
2018-10-04 03:57:18 +00:00
|
|
|
systemd.user = {
|
|
|
|
services.nixos-activation = {
|
2019-09-16 14:49:33 +00:00
|
|
|
description = "Run user-specific NixOS activation";
|
2018-10-04 03:57:18 +00:00
|
|
|
script = config.system.userActivationScripts.script;
|
|
|
|
unitConfig.ConditionUser = "!@system";
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
};
|
|
|
|
};
|
2009-05-27 09:40:55 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-01-02 16:06:46 +00:00
|
|
|
}
|