feat: provide wrapped packages

This commit is contained in:
Kat Inskip 2024-10-25 13:35:27 -04:00
parent fb9e62db99
commit 845afbeaf5
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
12 changed files with 77 additions and 29 deletions

85
wrappers/actions-test.sh Normal file
View file

@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -eu
if [[ ${GITHUB_ACTIONS-} = true && ${RUNNER_NAME-} = "Github Actions"* ]]; then
# low disk space available on public runners...
echo "enabled GC between builds due to restricted disk space..." >&2
export NF_ACTIONS_TEST_GC=1
fi
NIX_BUILD_ARGS=(
--show-trace
)
NIX_BUILD_ARGS_ASYNC=()
init_nfargs() {
nflinksuffix="$1"
shift
nfargs=(
"${NIX_BUILD_ARGS[@]}"
)
if [[ -n "${NF_ACTIONS_TEST_OUTLINK-}" || -n "${NF_UPDATE_CACHIX_PUSH-}" ]]; then
nfargs+=(
-o "${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"
)
else
nfargs+=(
--no-link
)
fi
}
nfgc() {
if [[ -n ${NF_ACTIONS_TEST_GC-} ]]; then
if [[ -n ${NF_UPDATE_CACHIX_PUSH-} ]]; then
cachix push kittywitch "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*/
rm -f "./${NF_ACTIONS_TEST_OUTLINK-result}$nflinksuffix"*
fi
nix-collect-garbage -d
fi
}
for nfsystem in "${NF_NIX_SYSTEMS[@]}"; do
nfinstallable="${NF_CONFIG_ROOT}#nixosConfigurations.${nfsystem}.config.system.build.toplevel"
init_nfargs "-$nfsystem"
nfwarn=
if [[ " ${NF_NIX_SYSTEMS_WARN[*]} " = *" $nfsystem "* ]]; then
nfwarn=1
fi
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} && -z $nfwarn ]]; then
NIX_BUILD_ARGS_ASYNC+=("$nfinstallable")
continue
fi
echo "building ${nfsystem}..." >&2
echo >&2
nfbuildexit=0
nix build "$nfinstallable" \
"${nfargs[@]}" \
"$@" || nfbuildexit=$?
if [[ $nfbuildexit -ne 0 ]]; then
if [[ -n $nfwarn ]]; then
echo "build failure allowed for ${nfsystem}, ignoring..." >&2
continue
fi
exit $nfbuildexit
fi
nfgc
done
if [[ -n ${NF_ACTIONS_TEST_ASYNC-} ]]; then
init_nfargs ""
nix build \
"${nfargs[@]}" \
"${NIX_BUILD_ARGS_ASYNC[@]}" \
"$@"
nfgc
fi

9
wrappers/default.nix Normal file
View file

@ -0,0 +1,9 @@
{
inputs,
...
}@args: let
in
inputs.utils.lib.eachDefaultSystem (system: {
nf-actions-test = import ./nf-actions-test.nix args;
nf-generate = import ./nf-generate.nix args;
})

20
wrappers/exports.nix Normal file
View file

@ -0,0 +1,20 @@
{
system,
inputs,
...
}: let
inherit (inputs.std.lib) string list set;
systems = inputs.self.systems;
enabledNixosSystems = set.filter (_: system: system.config.ci.enable && system.config.type == "NixOS") systems;
in {
exports = ''
export NF_CONFIG_ROOT=''${NF_CONFIG_ROOT-${toString ../../.}}
'';
exportsSystems = let
warnSystems = set.filter (_: system: system.config.ci.allowFailure) enabledNixosSystems;
toSystems = systems: string.concatMapSep " " string.escapeShellArg (set.keys systems);
in ''
NF_NIX_SYSTEMS=(${toSystems enabledNixosSystems})
NF_NIX_SYSTEMS_WARN=(${toSystems warnSystems})
'';
}

7
wrappers/generate.sh Normal file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eu
for ciconfig in "${NF_CONFIG_FILES[@]}"; do
echo "processing ${ciconfig}..." >&2
nix run --argstr config "$NF_CONFIG_ROOT/ci/$ciconfig" -f "$NF_INPUT_CI" run.gh-actions-generate
done

View file

@ -0,0 +1,17 @@
{
system,
inputs,
...
}@args: let
lib = inputs.nixpkgs.lib;
exportFile = import ./exports.nix args;
inherit (exportFile) exports exportsSystems;
inherit (inputs.std.lib) string list set;
packages = inputs.self.packages.${system};
inherit (inputs.self.legacyPackages.${system}) pkgs;
nf-actions-test = pkgs.writeShellScriptBin "nf-actions-test" ''
${exports}
${exportsSystems}
source ${./actions-test.sh}
'';
in nf-actions-test

20
wrappers/nf-generate.nix Normal file
View file

@ -0,0 +1,20 @@
{
system,
inputs,
...
}@args: let
lib = inputs.nixpkgs.lib;
exportFile = import ./exports.nix args;
inherit (exportFile) exports exportsSystems;
inherit (lib.strings) makeBinPath;
inherit (inputs.std.lib) string list set;
packages = inputs.self.packages.${system};
inherit (inputs.self.legacyPackages.${system}) pkgs;
nf-generate = pkgs.writeShellScriptBin "nf-generate" ''
${exports}
export PATH="$PATH:${makeBinPath [pkgs.jq]}"
NF_INPUT_CI=${string.escapeShellArg inputs.ci}
NF_CONFIG_FILES=(${string.concatMapSep " " string.escapeShellArg ci.workflowConfigs})
source ${../ci/generate.sh}
'';
in nf-generate