nixos/activatable-system: Make system builder commands env independent

This way it will be easier to reuse in a different context, such as
a separate build of the activation script by itself (TBD).
This commit is contained in:
Robert Hensing 2023-06-21 15:51:11 +02:00
parent 193f4fea90
commit 990b72f6af
2 changed files with 15 additions and 10 deletions

View File

@ -13,6 +13,9 @@ let
inherit (lib)
optionalString
;
perlWrapped = pkgs.perl.withPackages (p: with p; [ ConfigIniFiles FileSlurp ]);
in
{
config = {
@ -35,21 +38,21 @@ in
mkdir $out/bin
substitute ${./switch-to-configuration.pl} $out/bin/switch-to-configuration \
--subst-var coreutils \
--subst-var distroId \
--subst-var installBootLoader \
--subst-var localeArchive \
--subst-var out \
--subst-var perl \
--subst-var shell \
--subst-var su \
--subst-var systemd \
--subst-var utillinux \
--subst-var-by coreutils "${pkgs.coreutils}" \
--subst-var-by distroId ${lib.escapeShellArg config.system.nixos.distroId} \
--subst-var-by installBootLoader ${lib.escapeShellArg config.system.build.installBootLoader} \
--subst-var-by localeArchive "${config.i18n.glibcLocales}/lib/locale/locale-archive" \
--subst-var-by perl "${perlWrapped}" \
--subst-var-by shell "${pkgs.bash}/bin/sh" \
--subst-var-by su "${pkgs.shadow.su}/bin/su" \
--subst-var-by systemd "${config.systemd.package}"\
--subst-var-by utillinux "${pkgs.util-linux}" \
;
chmod +x $out/bin/switch-to-configuration
${optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
if ! output=$($perl/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
if ! output=$(${perlWrapped}/bin/perl -c $out/bin/switch-to-configuration 2>&1); then
echo "switch-to-configuration syntax is not valid:"
echo "$output"
exit 1

View File

@ -81,6 +81,8 @@ let
passAsFile = [ "extraDependencies" ];
buildCommand = systemBuilder;
# Some of these variables may be unused, but without certainly, removing
# them runs a risk of breaking out of tree systemBuilderCommands
inherit (pkgs) coreutils;
systemd = config.systemd.package;
shell = "${pkgs.bash}/bin/sh";