diff --git a/build.nix b/build.nix new file mode 100644 index 000000000..9c6c49e47 --- /dev/null +++ b/build.nix @@ -0,0 +1,84 @@ +{ system +, nixpkgs +, purescript-overlay +, slimlock +, nix-filter +}: +let + pkgs = import nixpkgs { + inherit system; + overlays = [ + purescript-overlay.overlays.default + (self: super: { purescript = self.purs-unstable; nodejs = super.nodejs_18; }) + slimlock.overlays.default + ]; + }; + spagoDependencies = pkgs.purix.buildSpagoLock { src = ./.; }; + nodeDependencies = pkgs.slimlock.buildPackageLock { src = ./.; }; +in +pkgs.stdenv.mkDerivation { + name = "spago"; + + phases = [ "buildPhase" "installPhase" ]; + + nativeBuildInputs = [ + pkgs.purs-unstable + pkgs.spago-unstable + pkgs.nodejs_18 + pkgs.python3 + pkgs.git + pkgs.installShellFiles + ]; + + src = nix-filter.lib { + root = ./.; + include = [ + "src" + "bin" + "core" + "test" + "test-fixtures" + "test-fixtures" + "LICENSE" + "package-lock.json" + "package.json" + "README.md" + "spago.lock" + "spago.yaml" + ]; + }; + + buildPhase = '' + cd $src + + chmod +w -R . + + cp -r ${nodeDependencies}/js/node_modules . + cp -r ${spagoDependencies.spago-bin}/output . + + spago bundle --offline -p spago-bin + + mkdir -p $out/package + cp bin/bundle.js package.json README.md LICENSE $out/package + ''; + + installPhase = '' + PACKAGE=$out/node_modules/spago + mkdir -p $PACKAGE + mv $out/package/* $PACKAGE/ + + BIN=$PACKAGE/bundle.js + chmod +x $BIN + patchShebangs $BIN + + SPAGO=$out/bin/spago + + mkdir -p $out/bin + ln -s $BIN $SPAGO + + BASH_COMPLETIONS=$out/share/bash-completion/completions/ + mkdir -p $BASH_COMPLETIONS + $SPAGO --bash-completion-script $SPAGO > $BASH_COMPLETIONS/spago + ''; +} + diff --git a/flake.lock b/flake.lock index 9395eeb99..088cac60b 100644 --- a/flake.lock +++ b/flake.lock @@ -16,13 +16,46 @@ "type": "github" } }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-filter": { + "locked": { + "lastModified": 1705332318, + "narHash": "sha256-kcw1yFeJe9N4PjQji9ZeX47jg0p9A0DuU4djKvg1a7I=", + "owner": "numtide", + "repo": "nix-filter", + "rev": "3449dc925982ad46246cfc36469baf66e1b64f17", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nix-filter", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1702759837, - "narHash": "sha256-u3XeJVRe/Q975nwFE+6ALEwypMKJEELMJKDAhSKyq3M=", + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b2566f4f897ac6224e094b167d9488d03e157f28", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", "type": "github" }, "original": { @@ -32,6 +65,22 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1688601033, + "narHash": "sha256-5CNmOffPU7aiTyZqLhXRFOwoAbZeFRM6Dk6au2q0uEs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "876975f68fd5527427243ef94db83cc934932833", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "purescript-overlay": { "inputs": { "flake-compat": "flake-compat", @@ -41,11 +90,11 @@ "slimlock": "slimlock" }, "locked": { - "lastModified": 1703097182, - "narHash": "sha256-L7UeQMdZWKEOUpRveXhvq2aF18yF5KgyCUYZYxvCZPI=", + "lastModified": 1705416298, + "narHash": "sha256-xJLRhG4VmDsyZ1QD087VKOapYwTV2R+7iV+HqAFKB98=", "owner": "thomashoneyman", "repo": "purescript-overlay", - "rev": "aa82efe06d9d32cee5bda7a44d9cf6cdc4c6fb60", + "rev": "4d9f42384efcfc934bbd818b05da3f3f50b5b991", "type": "github" }, "original": { @@ -56,8 +105,11 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", + "nix-filter": "nix-filter", "nixpkgs": "nixpkgs", - "purescript-overlay": "purescript-overlay" + "purescript-overlay": "purescript-overlay", + "slimlock": "slimlock_2" } }, "slimlock": { @@ -80,6 +132,39 @@ "repo": "slimlock", "type": "github" } + }, + "slimlock_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1702828829, + "narHash": "sha256-tL/ThLAk5JgYdKXy3MIZYnDavemjpemF17dVgbfbYM8=", + "owner": "thomashoneyman", + "repo": "slimlock", + "rev": "a7ce81f35d236a5e58bce30e34825013e19ffade", + "type": "github" + }, + "original": { + "owner": "thomashoneyman", + "repo": "slimlock", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 5a0cc3b3f..0f6ad4f76 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,9 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; purescript-overlay.url = "github:thomashoneyman/purescript-overlay"; purescript-overlay.inputs.nixpkgs.follows = "nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + slimlock.url = "github:thomashoneyman/slimlock"; + nix-filter.url = "github:numtide/nix-filter"; }; outputs = { self, nixpkgs, ... }@inputs: @@ -22,7 +25,8 @@ }; devShells = forAllSystems (system: - let pkgs = nixpkgsFor.${system}; in { + let pkgs = nixpkgsFor.${system}; in + { default = pkgs.mkShell { name = "spago"; buildInputs = with pkgs; [ @@ -36,5 +40,11 @@ ]; }; }); + + packages = forAllSystems (system: { + default = import ./build.nix { + inherit system nixpkgs; inherit (inputs) slimlock purescript-overlay nix-filter; + }; + }); }; }