feat: indexers: add build-all app

This commit is contained in:
DavHau 2022-09-07 14:02:24 +02:00
parent 12267818db
commit 05578072bf

View File

@ -80,6 +80,7 @@ in rec {
''; '';
in in
mkApp script; mkApp script;
mkTranslateApp = name: mkTranslateApp = name:
mkApp ( mkApp (
pkgs.writers.writeBash "translate-${name}" '' pkgs.writers.writeBash "translate-${name}" ''
@ -88,7 +89,8 @@ in rec {
${name}/index.json ${name}/locks ${name}/index.json ${name}/locks
'' ''
); );
mkCiJobApp = name: input:
mkCiAppWith = commands:
mkApp ( mkApp (
utils.writePureShellScript utils.writePureShellScript
(with pkgs; [ (with pkgs; [
@ -109,12 +111,19 @@ in rec {
rm -rf ./* rm -rf ./*
echo "$flake" > flake.nix echo "$flake" > flake.nix
echo "$flakeLock" > flake.lock echo "$flakeLock" > flake.lock
${(mkIndexApp name input).program} ${commands}
${(mkTranslateApp name).program}
git add . git add .
git commit -m "automatic update - $(date --rfc-3339=seconds)" git commit -m "automatic update - $(date --rfc-3339=seconds)"
'' ''
); );
mkCiJobApp = name: input:
mkCiAppWith
''
${(mkIndexApp name input).program}
${(mkTranslateApp name).program}
'';
translateApps = l.listToAttrs ( translateApps = l.listToAttrs (
l.map l.map
( (
@ -125,6 +134,7 @@ in rec {
) )
indexNames indexNames
); );
indexApps = l.listToAttrs ( indexApps = l.listToAttrs (
l.mapAttrsToList l.mapAttrsToList
( (
@ -135,6 +145,7 @@ in rec {
) )
indexes indexes
); );
ciJobApps = l.listToAttrs ( ciJobApps = l.listToAttrs (
l.mapAttrsToList l.mapAttrsToList
( (
@ -145,32 +156,65 @@ in rec {
) )
indexes indexes
); );
ciJobAllApp = mkApp (
utils.writePureShellScript ciJobAllApp =
(with pkgs; [ mkCiAppWith
coreutils
git
gnugrep
openssh
])
'' ''
flake=$(cat flake.nix)
flakeLock=$(cat flake.lock)
set -x
git fetch origin data || :
git checkout origin/data || :
git branch -D data || :
git checkout -b data
# the flake should always be the one from the current main branch
rm -rf ./*
echo "$flake" > flake.nix
echo "$flakeLock" > flake.lock
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)} ${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)}
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)} ${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)}
git add . '';
git commit -m "automatic update - $(date --rfc-3339=seconds)"
'' buildAllApp = let
); buildScript =
pkgs.writers.writePython3 "build-job" {}
''
import sys
import subprocess as sp
from pathlib import path
input = json.load(open(sys.argv[1]))
attr = input['attr']
attrPath = '.'.join(input['attrPath'])
if "error" in input:
print(
f"Evaluation failed. attr: {attr} attrPath: {attrPath}\nError:\n{error}",
file=sys.stderr
)
else:
name = input['name']
drvPath = input['drvPath']
print(
f"Building {name}. attr: {attr} attrPath: {attrPath}\nError:\n{error}",
file=sys.stderr
)
try:
proc = sp.run(
['nix', 'build', drvPath],
capture_output = true,
check=True,
)
except sp.CalledProcessError as error:
Path('errors').mkdir(exist_ok=True)
with open(f'errors/{name}') as f:
f.write(error.stderr)
'';
in
mkApp (
utils.writePureShellScript
(with pkgs; [
coreutils
git
parallel
nix
nix-eval-jobs
])
''
JOBS=''${JOBS:-$(nproc)}
parallel --halt now,fail=1 -j$JOBS --link \
-a <(nix-eval-jobs --gc-roots-dir $(pwd)/gcroot --flake $(realpath .)#packages.x86_64-linux --workers $JOBS) \
${buildScript}
''
);
mkIndexOutputs = name: let mkIndexOutputs = name: let
src = "${toString source}/${name}/locks"; src = "${toString source}/${name}/locks";
@ -200,6 +244,7 @@ in rec {
packages = allPackages; packages = allPackages;
apps = apps =
{ci-job-all = ciJobAllApp;} {ci-job-all = ciJobAllApp;}
// {build-all = buildAllApp;}
// indexApps // indexApps
// translateApps // translateApps
// ciJobApps; // ciJobApps;