Skip to content

Commit

Permalink
Merge pull request #1303 from emilazy/push-ulxuwyrnkwpq
Browse files Browse the repository at this point in the history
{activation-scripts,activate-system}: purify environment
  • Loading branch information
emilazy authored Jan 27, 2025
2 parents 6715348 + 4bff4bc commit 5c12a6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 7 additions & 1 deletion modules/services/activate-system/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
script = ''
set -e
set -o pipefail
export PATH="${pkgs.gnugrep}/bin:${pkgs.coreutils}/bin:@out@/sw/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export USER=root
export LOGNAME=root
export HOME=~root
export SHELL=$BASH
export LANG=C
export LC_CTYPE=UTF-8
systemConfig=$(cat ${config.system.profile}/systemConfig)
Expand All @@ -28,7 +35,6 @@
${config.system.activationScripts.keyboard.text}
'';
serviceConfig.RunAtLoad = true;
serviceConfig.KeepAlive.SuccessfulExit = false;
};
};
}
24 changes: 18 additions & 6 deletions modules/system/activation-scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,33 @@ in
config = {

system.activationScripts.script.text = ''
#! ${stdenv.shell}
#!/usr/bin/env -i ${stdenv.shell}
# shellcheck shell=bash
# shellcheck disable=SC2096
set -e
set -o pipefail
export PATH="${pkgs.gnugrep}/bin:${pkgs.coreutils}/bin:@out@/sw/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export USER=root
export LOGNAME=root
export HOME=~root
export SHELL=$BASH
export LANG=C
export LC_CTYPE=UTF-8
systemConfig=@out@
_status=0
trap "_status=1" ERR
# Ensure a consistent umask.
umask 0022
cd /
if [[ $(id -u) -ne 0 ]]; then
printf >&2 '\e[1;31merror: `activate` must be run as root\e[0m\n'
exit 2
fi
${cfg.activationScripts.preActivation.text}
# We run `etcChecks` again just in case someone runs `activate`
Expand Down Expand Up @@ -82,8 +96,6 @@ in
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
exit $_status
'';

# FIXME: activationScripts.checks should be system level
Expand Down

0 comments on commit 5c12a6f

Please sign in to comment.