diff --git a/tidepool/src/builders/foundation/basic.nix b/tidepool/src/builders/foundation/basic.nix index e59a537..6738aff 100644 --- a/tidepool/src/builders/foundation/basic.nix +++ b/tidepool/src/builders/foundation/basic.nix @@ -71,64 +71,81 @@ in (lib.packages.build packages.foundation.bash.versions."5.2.15-stage1" "x86_64-linux" system).package }/bin/bash"; - built = builtins.derivation ( - package.env - // { - inherit (package) name; - inherit script system; + built = builtins.derivation ({ + inherit (package) name env; + inherit script system; - outputs = builtins.attrNames (lib.packages.getOutputs package); + __structuredAttrs = true; - passAsFile = [ "script" ]; + outputs = builtins.attrNames (lib.packages.getOutputs package); - SHELL = executable; + SHELL = executable; - PATH = - let - bins = lib.paths.bin ( - (lib.packages.dependencies.get dependencies.build) - ++ (lib.packages.dependencies.get dependencies.host) - ++ lib.lists.when (system == "i686-linux") [ - foundation.stage2-bash - foundation.stage2-coreutils - ] - ++ lib.lists.when (system == "x86_64-linux") [ - (lib.packages.build packages.foundation.bash.versions."5.2.15-stage1" "i686-linux" system).package - (lib.packages.build packages.foundation.coreutils.versions."9.4-stage1" "i686-linux" system).package - ] - ++ lib.lists.when (system != "i686-linux" && system != "x86_64-linux") [ - (lib.packages.build packages.foundation.bash.versions."5.2.15-stage1" "x86_64-linux" system).package - (lib.packages.build packages.foundation.coreutils.versions."9.4-stage1" "x86_64-linux" system) - .package - ] - ); - in - builtins.concatStringsSep ":" ( - [ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ]) + PATH = + let + bins = lib.paths.bin ( + (lib.packages.dependencies.get dependencies.build) + ++ (lib.packages.dependencies.get dependencies.host) + ++ lib.lists.when (system == "i686-linux") [ + foundation.stage2-bash + foundation.stage2-coreutils + ] + ++ lib.lists.when (system == "x86_64-linux") [ + (lib.packages.build packages.foundation.bash.versions."5.2.15-stage1" "i686-linux" system).package + (lib.packages.build packages.foundation.coreutils.versions."9.4-stage1" "i686-linux" system).package + ] + ++ lib.lists.when (system != "i686-linux" && system != "x86_64-linux") [ + (lib.packages.build packages.foundation.bash.versions."5.2.15-stage1" "x86_64-linux" system).package + (lib.packages.build packages.foundation.coreutils.versions."9.4-stage1" "x86_64-linux" system) + .package + ] ); + in + builtins.concatStringsSep ":" ( + [ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ]) + ); - builder = executable; + builder = executable; - args = [ - "-e" - (builtins.toFile "bash-builder.sh" '' - export CONFIG_SHELL=$SHELL + args = [ + "-e" + (builtins.toFile "bash-builder.sh" '' + set -eEuo pipefail - # Normalize the NIX_BUILD_CORES variable. The value might be 0, which - # means that we're supposed to try and auto-detect the number of - # available CPU cores at run-time. - NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" - if ((NIX_BUILD_CORES <= 0)); then - guess=$(nproc 2>/dev/null || true) - ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) - fi - export NIX_BUILD_CORES + if [[ -e $NIX_ATTRS_SH_FILE ]]; then + source "$NIX_ATTRS_SH_FILE"; + else + echo "Failed to find structuredAttrs" + exit 1 + fi - bash -eux $scriptPath - '') - ]; - } - ); + export CONFIG_SHELL=$SHELL + + # With structuredAttrs each output var must be exported manually + for outputName in "''${!outputs[@]}"; do + # Need to set $out=/nix/store... + export "$outputName=''${outputs[$outputName]}" + done + + # Also need to export vars + for envVar in "''${!env[@]}"; do + export "$envVar=''${env[$envVar]}" + done + + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if ((NIX_BUILD_CORES <= 0)); then + guess=$(nproc 2>/dev/null || true) + ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) + fi + export NIX_BUILD_CORES + + eval "$script" + '') + ]; + }); result = built // { inherit package;