From 8d6ae0473354380d8bcb4044881bfa4b543ce7b7 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 | 24 ------------------ docker-compose.yaml | 14 ----------- packages/flake.lock | 41 +++++++++++++++++++++++++++++++ packages/flake.nix | 47 ++++++++++++++++++++++++++++++++++++ packages/node-javascript.nix | 17 +++++++++++++ 5 files changed, 105 insertions(+), 38 deletions(-) delete mode 100644 docker-compose.yaml 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 25d8fe6..e69de29 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -1,24 +0,0 @@ -version: '3.2' - -services: - api: - build: api - container_name: piston_api - cap_add: - - CAP_SYS_ADMIN - restart: always - ports: - - 2000:2000 - volumes: - - ./data/piston:/piston - environment: - - PISTON_REPO_URL=http://repo:8000/index - tmpfs: - - /piston/jobs:exec - - repo: # Local testing of packages - build: repo - container_name: piston_repo - command: ['--no-build'] # Don't build anything - volumes: - - .:/piston diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 8888f53..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,14 +0,0 @@ -version: '3.2' - -services: - api: - image: ghcr.io/engineer-man/piston - container_name: piston_api - restart: always - ports: - - 2000:2000 - volumes: - - ./data/piston:/piston - tmpfs: - - /piston/jobs:exec - - /tmp: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