1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-05 16:27:03 +00:00
nix-darwin/modules/system/activation-scripts.nix

99 lines
2.5 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
2016-12-07 23:06:18 +01:00
inherit (pkgs) stdenv;
cfg = config.system;
2017-01-02 08:21:27 +01:00
script = import ../lib/write-text.nix {
inherit lib;
mkTextDerivation = name: text: pkgs.writeScript "activate-${name}" text;
};
in
{
options = {
system.activationScripts = mkOption {
internal = true;
type = types.attrsOf (types.submodule script);
default = {};
description = ''
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.
'';
};
};
config = {
system.activationScripts.script.text = ''
2016-12-07 23:06:18 +01:00
#! ${stdenv.shell}
2016-12-12 17:34:43 +01:00
set -e
set -o pipefail
export PATH=${pkgs.coreutils}/bin:${config.environment.systemPath}:$PATH
systemConfig=@out@
_status=0
trap "_status=1" ERR
# Ensure a consistent umask.
umask 0022
# Make this configuration the current configuration.
# The readlink is there to ensure that when $systemConfig = /system
# (which is a symlink to the store), /run/current-system is still
# used as a garbage collection root.
ln -sfn "$(readlink -f "$systemConfig")" /run/current-system
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
${cfg.activationScripts.nix.text}
${cfg.activationScripts.etc.text}
${cfg.activationScripts.launchd.text}
2016-12-16 12:20:28 +01:00
${cfg.activationScripts.time.text}
2016-12-19 20:31:59 +01:00
${cfg.activationScripts.extraActivation.text}
exit $_status
'';
2016-12-14 12:32:20 +01:00
system.activationScripts.userScript.text = ''
#! ${stdenv.shell}
set -e
set -o pipefail
export PATH=${pkgs.coreutils}/bin:${config.environment.systemPath}:$PATH
systemConfig=@out@
_status=0
trap "_status=1" ERR
# Ensure a consistent umask.
umask 0022
${cfg.activationScripts.defaults.text}
2016-12-19 20:31:59 +01:00
${cfg.activationScripts.extraUserActivation.text}
2016-12-14 12:32:20 +01:00
exit $_status
'';
2016-12-19 20:31:59 +01:00
# Extra activation scripts, that can be customized by users
# don't use this unless you know what you are doing.
system.activationScripts.extraActivation.text = mkDefault "";
system.activationScripts.extraUserActivation.text = mkDefault "";
};
}