Skip to content

Commit

Permalink
feat: add spago derivation
Browse files Browse the repository at this point in the history
- set it as the default package
- add to a devshell
  • Loading branch information
deemp committed Jan 28, 2024
1 parent 67b457c commit fc0e7c2
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 6 deletions.
11 changes: 6 additions & 5 deletions flake.lock

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

23 changes: 22 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -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";
};

Expand All @@ -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 {
Expand All @@ -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
];
};
});
};
}
94 changes: 94 additions & 0 deletions spago.nix
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc0e7c2

Please sign in to comment.