labs/tidepool/src/builders/basic.nix

77 lines
2.1 KiB
Nix
Raw Normal View History

2024-06-22 10:58:44 -07:00
{ lib, config }:
let
2024-06-14 07:01:18 -07:00
cfg = config.builders.basic;
lib' = config.lib;
inherit (config) foundation;
2024-06-22 10:58:44 -07:00
in
{
2024-06-14 07:01:18 -07:00
config.builders = {
basic = {
executable = "${foundation.stage2-bash}/bin/bash";
2024-06-22 10:58:44 -07:00
build =
package:
let
phases = package.phases;
sorted = lib.dag.sort.topographic phases;
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
script = lib.strings.concatMapSep "\n" (
entry: if builtins.isFunction entry.value then entry.value package else entry.value
) sorted.result;
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
system = package.platform.build.double;
2024-06-22 10:58:44 -07:00
built = builtins.derivation (
package.env
// {
inherit (package) name;
inherit script system;
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
passAsFile = [ "script" ];
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
SHELL = cfg.executable;
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
PATH =
let
bins = lib.paths.bin (
(lib'.packages.dependencies.getPackages package.deps.build.host)
++ [
foundation.stage2-bash
foundation.stage2-coreutils
]
);
in
builtins.concatStringsSep ":" (
[ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ])
);
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
builder = cfg.executable;
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
args = [
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
# 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
2024-06-14 07:01:18 -07:00
2024-06-22 10:58:44 -07:00
bash -eux $scriptPath
'')
];
}
);
in
built // { inherit (package) meta; };
2024-06-14 07:01:18 -07:00
};
};
}