Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build spago from source #981

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ package:
- refs
- registry-lib
- strings
- stringutils
- transformers
- tuples
19 changes: 10 additions & 9 deletions flake.lock

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

25 changes: 23 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
purescript-overlay.url = "github:thomashoneyman/purescript-overlay";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
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
];
};
});
};
}
2 changes: 2 additions & 0 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ workspace:
- refs
- registry-lib
- strings
- stringutils
- transformers
- tuples
test_dependencies: []
Expand Down Expand Up @@ -790,6 +791,7 @@ workspace:
- safe-coerce
- st
- strings
- stringutils
- tailrec
- transformers
- tuples
Expand Down
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
Loading