Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules
/output
/output-es
/scratch
/.vscode

Expand Down
22 changes: 16 additions & 6 deletions app/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
makeWrapper,
lib,
stdenv,
purix,
purs-backend-es,
purs-backend-es-unstable,
esbuild,
writeText,
nodejs,
Expand Down Expand Up @@ -32,16 +31,27 @@ let
"buildPhase"
"installPhase"
];
nativeBuildInputs = [ purs-backend-es ];
nativeBuildInputs = [ purs-backend-es-unstable ];
buildPhase = ''
ln -s ${package-lock}/js/node_modules .
cp -r ${spago-lock.registry-app}/output .
cp -r ${spago-lock}/output .
echo "Optimizing with purs-backend-es..."
purs-backend-es build
'';
installPhase = ''
mkdir $out
mv output-es $out/output
mkdir $out;
cp -r output-es $out/output;
# This for loop exists because purs-backend-es finds the corefn.json files
# just fine, but doesn't find the foreign.js files.
# I suspect this is because of a quirky interaction between Nix and `copyFile`,
# but I'm not sure how to fix it so we work around it by copying the foreign
# modules by hand.
for dir in output/*/; do
Copy link
Contributor

@toastal toastal Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not something like find output -type d -maxdepth 1 -print0 | xargs -0 -P$NIX_BUILD_CORES -I{} …? Could be a bit quicker to run this in parallel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't parse that command - do you have a more precise suggestion? I'm happy with the for loop because it's very readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you did edit in a runnable command, I must have seen an outdated version. That works just as well, but I'd still prefer the for loop

subdir=$(basename "$dir")
if [ -f "output/$subdir/foreign.js" ]; then
cp "output/$subdir/foreign.js" "$out/output/$subdir/" || true;
fi
done
'';
};
in
Expand Down
1 change: 1 addition & 0 deletions app/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ package:
test:
main: Test.Registry.Main
dependencies:
- registry-test-utils
- spec
90 changes: 74 additions & 16 deletions flake.lock

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

34 changes: 23 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "The PureScript Registry";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-24.05";
nixpkgs.url = "github:nixos/nixpkgs/release-25.05";
flake-utils.url = "github:numtide/flake-utils";

flake-compat.url = "github:edolstra/flake-compat";
Expand All @@ -11,6 +11,10 @@
purescript-overlay.url = "github:thomashoneyman/purescript-overlay";
purescript-overlay.inputs.nixpkgs.follows = "nixpkgs";

mkSpagoDerivation.url = "github:jeslie0/mkSpagoDerivation";
mkSpagoDerivation.inputs.nixpkgs.follows = "nixpkgs";
mkSpagoDerivation.inputs.ps-overlay.follows = "purescript-overlay";

slimlock.url = "github:thomashoneyman/slimlock";
slimlock.inputs.nixpkgs.follows = "nixpkgs";
};
Expand All @@ -21,6 +25,7 @@
nixpkgs,
flake-utils,
purescript-overlay,
mkSpagoDerivation,
slimlock,
...
}:
Expand All @@ -44,6 +49,7 @@
./foreign
./lib
./scripts
./test-utils
./spago.lock
./spago.yaml
]
Expand Down Expand Up @@ -76,7 +82,7 @@
# We don't want to force everyone to update their configs if they aren't
# normally on flakes.
nixFlakes = prev.writeShellScriptBin "nixFlakes" ''
exec ${prev.nixFlakes}/bin/nix --experimental-features "nix-command flakes" "$@"
exec ${prev.nixVersions.stable}/bin/nix --experimental-features "nix-command flakes" "$@"
'';

# Detects arguments to 'git' containing a URL and replaces them with a
Expand Down Expand Up @@ -144,12 +150,15 @@
# Packages associated with the registry, ie. in this repository.
registry =
let
spago-lock = prev.purix.buildSpagoLock {
src = fileset.toSource {
root = ./.;
fileset = pureScriptFileset;
};
corefn = true;
spago-lock = prev.mkSpagoDerivation {
name = "registry";
src = ./.;
nativeBuildInputs = [
prev.pkgs.spago-bin.spago-0_93_44
prev.pkgs.purescript
];
buildPhase = "spago build";
installPhase = "mkdir $out; cp -r * $out";
};

package-lock =
Expand Down Expand Up @@ -245,6 +254,7 @@
inherit system;
overlays = [
purescript-overlay.overlays.default
mkSpagoDerivation.overlays.default
slimlock.overlays.default
registryOverlay
];
Expand All @@ -265,12 +275,12 @@
set -euo pipefail
WORKDIR=$(mktemp -d)
cp spago.yaml spago.lock $WORKDIR
cp -a app foreign lib scripts types $WORKDIR
cp -a app foreign lib scripts test-utils types $WORKDIR
ln -s ${pkgs.registry.package-lock}/js/node_modules $WORKDIR/node_modules

pushd $WORKDIR
export HEALTHCHECKS_URL=${defaultEnv.HEALTHCHECKS_URL}
${pkgs.spago-bin.spago-0_93_19}/bin/spago test
${pkgs.spago-bin.spago-0_93_44}/bin/spago test

popd
'';
Expand Down Expand Up @@ -317,6 +327,7 @@
{
nixpkgs.overlays = [
purescript-overlay.overlays.default
mkSpagoDerivation.overlays.default
slimlock.overlays.default
registryOverlay
];
Expand Down Expand Up @@ -853,7 +864,7 @@

# Development tooling
purs
spago-bin.spago-0_93_19 # until new lockfile format supported by overlay
spago-bin.spago-0_93_44
purs-tidy-unstable
purs-backend-es-unstable
];
Expand All @@ -870,6 +881,7 @@
system = "x86_64-linux";
overlays = [
purescript-overlay.overlays.default
mkSpagoDerivation.overlays.default
slimlock.overlays.default
registryOverlay
];
Expand Down
1 change: 1 addition & 0 deletions foreign/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ package:
- node-execa
- node-fs
- node-process
- registry-test-utils
- spec
2 changes: 1 addition & 1 deletion lib/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ package:
- json
- node-child-process
- node-execa
- registry-test-utils
- spec
- unsafe-coerce
3 changes: 1 addition & 2 deletions scripts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
makeWrapper,
lib,
stdenv,
purix,
esbuild,
nodejs,
writeText,
Expand Down Expand Up @@ -37,7 +36,7 @@ let
'';
buildPhase = ''
ln -s ${package-lock}/js/node_modules .
cp -r ${spago-lock.registry-scripts}/output .
cp -r ${spago-lock}/output .
cp ${entrypoint} entrypoint.js
esbuild entrypoint.js --bundle --outfile=${name}.js --platform=node --packages=external
'';
Expand Down
Loading