From fc0e7c242a0d96006bc3e7ff6894886f2babf029 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Mon, 29 Jan 2024 01:45:59 +0300 Subject: [PATCH] feat: add spago derivation - set it as the default package - add to a devshell --- flake.lock | 11 ++++--- flake.nix | 23 ++++++++++++- spago.nix | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 spago.nix diff --git a/flake.lock b/flake.lock index 02b3b899d..f243bf615 100644 --- a/flake.lock +++ b/flake.lock @@ -41,15 +41,16 @@ "slimlock": "slimlock" }, "locked": { - "lastModified": 1703097182, - "narHash": "sha256-L7UeQMdZWKEOUpRveXhvq2aF18yF5KgyCUYZYxvCZPI=", - "owner": "thomashoneyman", + "lastModified": 1706481008, + "narHash": "sha256-kJM7DrlVMw7gE9OQrgnHwqqpvrqH96joxny7DFDW+s8=", + "owner": "deemp", "repo": "purescript-overlay", - "rev": "aa82efe06d9d32cee5bda7a44d9cf6cdc4c6fb60", + "rev": "a96030d11bd0990505c0748e39d23f2f9b46d074", "type": "github" }, "original": { - "owner": "thomashoneyman", + "owner": "deemp", + "ref": "main", "repo": "purescript-overlay", "type": "github" } diff --git a/flake.nix b/flake.nix index 38e19aba3..8e6818932 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,7 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; - purescript-overlay.url = "github:thomashoneyman/purescript-overlay"; + purescript-overlay.url = "github:deemp/purescript-overlay/main"; purescript-overlay.inputs.nixpkgs.follows = "nixpkgs"; }; @@ -19,8 +19,14 @@ { overlays = { purescript = inputs.purescript-overlay.overlays.default; + slimlock = inputs.purescript-overlay.inputs.slimlock.overlays.default; }; + packages = forAllSystems (system: + let pkgs = nixpkgsFor.${system}; in + { default = pkgs.callPackage ./spago.nix { }; } + ); + devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in { default = pkgs.mkShell { @@ -35,6 +41,21 @@ esbuild ]; }; + + dev = pkgs.mkShell { + shellHook = '' + source ${self.packages.${system}.default}/share/bash-completion/completions/spago + + spago --help + + printf "\nspago version:\n" + spago --version + ''; + buildInputs = with pkgs; [ + self.packages.${system}.default + purs-unstable + ]; + }; }); }; } diff --git a/spago.nix b/spago.nix new file mode 100644 index 000000000..0819fdee2 --- /dev/null +++ b/spago.nix @@ -0,0 +1,94 @@ +{ lib +, stdenv +, slimlock +, python3 +, purix +, purs +, esbuild +, writeText +, writeShellScriptBin +, nodejs +}: +let + fs = lib.fileset; + packageLock = (slimlock.buildPackageLock { + src = fs.toSource { + root = ./.; + fileset = fs.unions [ + ./package-lock.json + ./package.json + ]; + }; + }).overrideAttrs (x: { + nativeBuildInputs = (x.nativeBuildInputs or [ ]) ++ [ python3 ]; + }); + + spagoLock = purix.buildSpagoLock { + src = fs.toSource { + root = ./.; + fileset = fs.unions [ + ./bin + ./core + ./docs-search + ./src + ./spago.lock + ./spago.yaml + ]; + }; + }; + + spago-app = stdenv.mkDerivation { + name = "spago-app"; + + src = fs.toSource { + root = ./.; + fileset = fs.unions [ + ./bin/index.dev.js + ./package.json + ./package-lock.json + ]; + }; + + nativeBuildInputs = [ esbuild ]; + + buildPhase = '' + echo "Linking ..." + ln -s ${packageLock}/js/node_modules . + ln -s ${spagoLock.spago-bin}/output . + esbuild bin/index.dev.js \ + --bundle \ + --outfile=app.js \ + --platform=node \ + --format=esm \ + --packages=external + ''; + + installPhase = '' + mkdir $out + cp app.js $out + cp package.json package-lock.json $out + ln -s ${packageLock}/js/node_modules $out + ln -s $out/app.js $out/spago + ''; + }; + + spago-script = writeShellScriptBin "spago" '' + ${nodejs}/bin/node ${spago-app}/spago "$@" + ''; + + spago = stdenv.mkDerivation { + name = "spago"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out + + SPAGO="$out/bin/spago" + ln -s ${spago-script}/bin $out + + BASH_COMPLETIONS=$out/share/bash-completion/completions/ + mkdir -p $BASH_COMPLETIONS + $SPAGO --bash-completion-script $SPAGO > $BASH_COMPLETIONS/spago + ''; + }; +in +spago \ No newline at end of file