Skip to content

Commit

Permalink
feat: add spago derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Jan 21, 2024
1 parent c38d76e commit 6e15324
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 8 deletions.
84 changes: 84 additions & 0 deletions build.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}

99 changes: 92 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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; [
Expand All @@ -36,5 +40,11 @@
];
};
});

packages = forAllSystems (system: {
default = import ./build.nix {
inherit system nixpkgs; inherit (inputs) slimlock purescript-overlay nix-filter;
};
});
};
}

0 comments on commit 6e15324

Please sign in to comment.