From 8e230befced0625e670e50b31f229470383ba979 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Sun, 28 Aug 2022 15:00:28 +0200 Subject: [PATCH] Initial nix ad-hoc package installation --- flake.nix | 35 +++++++++++++++-------------------- piston | 2 +- runtimes/python3.nix | 35 ++++++++++++++++------------------- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/flake.nix b/flake.nix index 2b9c50d0..b705f522 100644 --- a/flake.nix +++ b/flake.nix @@ -10,32 +10,27 @@ args = { inherit pkgs; piston = { - mkRuntime = { - language, - version, - runtime? null, - run, - compile? null, - packages? null, - aliases? [], - limitOverrides? {}, - tests - }: let - compileFile = if compile != null then - pkgs.writeShellScript "compile" compile + mkRuntime = builderFn: let + languagePackagesFn = packages: with packages; [ ]; + buildRes = builderFn languagePackagesFn; + compileFile = if builtins.hasAttr "compile" buildRes then + pkgs.writeShellScript "compile" buildRes.compile else null; - runFile = pkgs.writeShellScript "run" run; + runFile = pkgs.writeShellScript "run" buildRes.run; metadata = { - inherit language version runtime aliases limitOverrides; + language = buildRes.language; + version = buildRes.version; + runtime = buildRes.runtime or null; + aliases = buildRes.aliases or []; + limitOverrides = buildRes.limitOverrides or {}; run = runFile; compile = compileFile; - packageSupport = packages != null; }; + tests = if (builtins.length buildRes.tests) > 0 then + buildRes.tests + else abort "Language ${buildRes.language} doesn't provide any tests"; in { - inherit packages metadata; - tests = if (builtins.length tests) > 0 then - tests - else abort "Language ${language} doesn't provide any tests"; + inherit metadata tests; }; mkTest = { files, diff --git a/piston b/piston index a5f85b13..4403a3e5 100755 --- a/piston +++ b/piston @@ -94,7 +94,7 @@ case "$SUBCOMMAND" in -e PISTON_RUNTIME_SET=$runtime_set \ -v "$SCRIPT_DIR":/piston/src \ -v $DEV_VOLUME_NAME:/nix \ - -d "$IMAGE_NAME_DEV:$IMAGE_TAG" \ + "$IMAGE_NAME_DEV:$IMAGE_TAG" \ bash -c "cd /piston/src/api && yarn run dev" ;; diff --git a/runtimes/python3.nix b/runtimes/python3.nix index 3831bcac..d9fe2a30 100644 --- a/runtimes/python3.nix +++ b/runtimes/python3.nix @@ -1,27 +1,24 @@ -{pkgs, piston, ...}: -let - pkg = pkgs.python3; -in piston.mkRuntime { +{ pkgs, piston, ... }: +let basePkg = pkgs.python3; +in piston.mkRuntime (libraries: + let pkg = basePkg.withPackages libraries; + in { language = "python3"; - version = pkg.version; + version = basePkg.version; - aliases = [ - "py3" - "py" - "python" - ]; + aliases = [ "py3" "py" "python" ]; run = '' - ${pkg}/bin/python3 "$@" + ${pkg}/bin/python3 "$@" ''; tests = [ - (piston.mkTest { - files = { - "test.py" = '' - print("OK") - ''; - }; - }) + (piston.mkTest { + files = { + "test.py" = '' + print("OK") + ''; + }; + }) ]; -} + })