Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix installable packages #508

Draft
wants to merge 1 commit into
base: nix-packages
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion piston
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;

Expand Down
35 changes: 16 additions & 19 deletions runtimes/python3.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
{pkgs, piston, ...}:
let
pkg = pkgs.python3;
in piston.mkRuntime {
{ pkgs, piston, ... }:
let basePkg = pkgs.python3;
in piston.mkRuntime (libraries:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we possibly make this piston.mkRuntimePackages or similar, just so if packages aren't required we can use the old format?

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")
'';
};
})
];
}
})