From 064715d413bbc58a2fc3366b909f1bccd8e8e237 Mon Sep 17 00:00:00 2001 From: Thomas Hobson Date: Tue, 5 Oct 2021 14:57:40 +1300 Subject: [PATCH] create packages flake --- docker-compose.dev.yaml | 1 + packages/flake.lock | 41 +++++++++++++++++++++++++++++++ packages/flake.nix | 47 ++++++++++++++++++++++++++++++++++++ packages/node-javascript.nix | 17 +++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 packages/flake.lock create mode 100644 packages/flake.nix create mode 100644 packages/node-javascript.nix diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 5c3b61e..97f338c 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -13,6 +13,7 @@ services: - ./data/piston:/piston environment: - PISTON_REPO_URL=http://repo:8000/index + - PISTON_LOG_LEVEL=DEBUG tmpfs: - /piston/jobs:exec diff --git a/packages/flake.lock b/packages/flake.lock new file mode 100644 index 0000000..14753b7 --- /dev/null +++ b/packages/flake.lock @@ -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 +} diff --git a/packages/flake.nix b/packages/flake.nix new file mode 100644 index 0000000..17a60d3 --- /dev/null +++ b/packages/flake.nix @@ -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; + }; + }; +} diff --git a/packages/node-javascript.nix b/packages/node-javascript.nix new file mode 100644 index 0000000..911e3c6 --- /dev/null +++ b/packages/node-javascript.nix @@ -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 "$@" + ''; + +} \ No newline at end of file