create packages flake

This commit is contained in:
Thomas Hobson 2021-10-05 14:57:40 +13:00
parent 6a8dc48233
commit 064715d413
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
4 changed files with 106 additions and 0 deletions

View File

@ -13,6 +13,7 @@ services:
- ./data/piston:/piston - ./data/piston:/piston
environment: environment:
- PISTON_REPO_URL=http://repo:8000/index - PISTON_REPO_URL=http://repo:8000/index
- PISTON_LOG_LEVEL=DEBUG
tmpfs: tmpfs:
- /piston/jobs:exec - /piston/jobs:exec

41
packages/flake.lock Normal file
View File

@ -0,0 +1,41 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1631561581,
"narHash": "sha256-3VQMV5zvxaVLvqqUrNz3iJelLw30mIVSfZmAaauM3dA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "7e5bf3925f6fbdfaf50a2a7ca0be2879c4261d19",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1633356775,
"narHash": "sha256-UBhRo1qy8xpOGTrjf7r2SFcULkFM+Wn4kchxN1ToDxs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "38501bec61c1e9447aa4ffc01ba07c40f4515327",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

47
packages/flake.nix Normal file
View File

@ -0,0 +1,47 @@
{
description = "Piston packages repo";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
args = {
inherit pkgs;
piston = {
mkRuntime = {
language,
version,
runtime,
run,
compile? null,
aliases? []
}: let
packageName = "${runtime}-${language}";
compileFile = if compile != null then
pkgs.writeShellScript "compile" compile
else null;
runFile = pkgs.writeShellScript "run" run;
metadataFile = pkgs.writeText "metadata.json" (builtins.toJSON {
inherit language version runtime aliases;
});
in pkgs.runCommandNoCC packageName {}
(
''
mkdir -p $out/piston
ln -s ${runFile} $out/piston/run
ln -s ${metadataFile} $out/piston/metadata.json
'' + (
if compileFile != null then
''
ln -s ${compileFile} $out/piston/compile
'' else "")
);
};
};
in {
piston = {
"node-javascript" = import ./node-javascript.nix args;
};
};
}

View File

@ -0,0 +1,17 @@
{pkgs, piston}:
piston.mkRuntime {
language = "javascript";
version = pkgs.nodejs.version;
runtime = "node";
aliases = [
"node-js"
"node-javascript"
"js"
];
run = ''
${pkgs.nodejs}/bin/node "$@"
'';
}