This deprecation is part of a bigger effort to deprecate activation scripts altogether, which will take place over several releases. There are no in-tree usages of the now-deprecated reload/restart functionality.
2.3 KiB
Activation script
The activation script is a bash script called to activate the new
configuration which resides in a NixOS system in $out/activate. Since its
contents depend on your system configuration, the contents may differ.
This chapter explains how the script works in general and some common NixOS
snippets. Please be aware that the script is executed on every boot and system
switch, so tasks that can be performed in other places should be performed
there (for example letting a directory of a service be created by systemd using
mechanisms like StateDirectory, CacheDirectory, ... or if that's not
possible using preStart of the service).
Activation scripts are defined as snippets using . They can either be a simple multiline string or an attribute set that can depend on other snippets. The builder for the activation script will take these dependencies into account and order the snippets accordingly. As a simple example:
{
system.activationScripts.my-activation-script = {
deps = [ "etc" ];
# supportsDryActivation = true;
text = ''
echo "Hallo i bims"
'';
};
}
This example creates an activation script snippet that is run after the etc
snippet. The special variable supportsDryActivation can be set so the snippet
is also run when nixos-rebuild dry-activate is run. To differentiate between
real and dry activation, the $NIXOS_ACTION environment variable can be
read which is set to dry-activate when a dry activation is done.
NixOS snippets
There are some snippets NixOS enables by default because disabling them would most likely break your system. This section lists a few of them and what they do:
binshcreates/bin/shwhich points to the runtime shelletcsets up the contents of/etc, this includes systemd units and excludes/etc/passwd,/etc/group, and/etc/shadow(which are managed by theuserssnippet)modprobesets the path to themodprobebinary for module auto-loadingspecialfsis responsible for mounting filesystems like/procandsysuserscreates and removes users and groups by managing/etc/passwd,/etc/groupand/etc/shadow. This also creates home directoriesusrbinenvcreates/usr/bin/env