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

Update buildSpagoLock and refactor #71

Merged
merged 21 commits into from
Feb 9, 2024
Merged
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
20 changes: 12 additions & 8 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(import
(
import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
{src = ./.;}
)
.defaultNix
264 changes: 122 additions & 142 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,150 +17,130 @@
slimlock,
flake-compat,
}: let
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit (nixpkgs) lib;
eachDefaultSystem = perSystem:
lib.pipe ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"] [
(map (sys: builtins.mapAttrs (_: value: {${sys} = value;}) (perSystem sys)))
(builtins.foldl' nixpkgs.lib.recursiveUpdate {})
];
in
eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [self.overlays.default slimlock.overlays.default];
});
in {
overlays.default = import ./overlay.nix;

# A warning-free top-level flake output suitable for running unit tests via
# e.g. `nix eval .#lib`.
lib = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
tests = pkgs.callPackage ./nix/tests {};
in
tests);

packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};

purs = pkgs.purs;
purs-unstable = pkgs.purs-unstable;
purs-bin = pkgs.purs-bin;

spago = pkgs.spago;
spago-unstable = pkgs.spago-unstable;
spago-bin = pkgs.spago-bin;

purs-tidy = pkgs.purs-tidy;
purs-tidy-unstable = pkgs.purs-tidy-unstable;
purs-tidy-bin = pkgs.purs-tidy-bin;

purs-backend-es = pkgs.purs-backend-es;
purs-backend-es-unstable = pkgs.purs-backend-es-unstable;
purs-backend-es-bin = pkgs.purs-backend-es-bin;

purescript-language-server = pkgs.purescript-language-server;
purescript-language-server-unstable = pkgs.purescript-language-server-unstable;
purescript-language-server-bin = pkgs.purescript-language-server-bin;
in
{
inherit purs purs-unstable spago spago-unstable purs-tidy purs-tidy-unstable purs-backend-es purs-backend-es-unstable purescript-language-server purescript-language-server-unstable;
}
// purs-bin
// spago-bin
// purs-tidy-bin
// purs-backend-es-bin
// purescript-language-server-bin);

apps = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
mkApp = bin: {
type = "app";
program = "${bin}/bin/${bin.pname or bin.name}";
};
apps = pkgs.lib.mapAttrs (_: mkApp) self.packages.${system};
scripts = {generate = mkApp (pkgs.callPackage ./generate {});};
in
apps // scripts);

checks = forAllSystems (system: let
pkgs = nixpkgsFor.${system};

package-checks =
pkgs.lib.mapAttrs (key: bin: let
name = bin.pname or bin.name;
version = bin.version or "0.0.0";
in
pkgs.runCommand "test-${name}-${version}" {} ''
touch $out
set -e
set -x

# Some package versions are not supported on some systems, ie. the
# "stable" version of Spago is not supported on aarch64.
if [ ${builtins.toString (builtins.hasAttr "unsupported" bin)} ]; then
echo "Skipping ${bin.name} because it is not supported on ${system}"
exit 0
fi

# Different packages at different versions use different 'version'
# flags to print their version
if [ ${builtins.toString (name == "spago" && pkgs.lib.versionOlder version "0.90.0")} ]; then
VERSION="$(${bin}/bin/${name} version --global-cache skip)"
# spago@0.93.21 incorrecly reports its version
elif [ ${builtins.toString (name == "spago" && version == "0.93.21")} ]; then
VERSION="0.93.21"
else
# spago-next writes --version to stderr, oddly enough, so we need to
# capture both in the VERSION var.
VERSION="$(${bin}/bin/${name} --version 2>&1)"
fi

# purs-tidy includes a 'v' prefix in its output beginning with version 0.9.0
if [ ${builtins.toString (name == "purs-tidy" && !(pkgs.lib.versionOlder version "0.9.0"))} ]; then
EXPECTED_VERSION="v${version}"
# purs-backend-es always includes it
elif [ ${builtins.toString (name == "purs-backend-es")} ]; then
EXPECTED_VERSION="v${version}"
else
EXPECTED_VERSION="${version}"
fi

echo "$VERSION should match expected output $EXPECTED_VERSION"
test "$VERSION" = "$EXPECTED_VERSION"
'')
# TODO: Remove once the purescript build of spago is stable
(pkgs.lib.filterAttrs (k: v: !(k == "spago" && system == "aarch64-darwin")) self.packages.${system});

example-checks = pkgs.callPackages ./nix/examples {};

script-checks = {
generate = let
bin = pkgs.callPackage ./generate {};
manifests = ./manifests;
in
pkgs.runCommand "test-generate" {} ''
mkdir -p $out/bin
set -e
set -x
cp ${bin}/bin/${bin.name} $out/bin/test-generate
${bin}/bin/${bin.name} verify ${manifests}
'';
overlays = [
self.overlays.default
slimlock.overlays.default
];
};
in
package-checks // example-checks // script-checks);

devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
name = "purescript-overlay";
buildInputs = [
self.packages.${system}.spago-0_93_19
self.packages.${system}.purs-unstable
self.packages.${system}.purs-tidy-unstable
self.packages.${system}.purs-backend-es-unstable
self.packages.${system}.purescript-language-server-unstable

pkgs.nodejs_20
pkgs.prefetch-npm-deps
];
# A warning-free top-level flake output suitable for running unit tests via
# e.g. `nix eval .#lib`.
lib = pkgs.callPackage ./nix/tests {};

packages =
{
inherit (pkgs) purs purs-unstable spago spago-unstable purs-tidy purs-tidy-unstable purs-backend-es purs-backend-es-unstable purescript-language-server purescript-language-server-unstable;
}
// pkgs.purs-bin
// pkgs.spago-bin
// pkgs.purs-tidy-bin
// pkgs.purs-backend-es-bin
// pkgs.purescript-language-server-bin;

apps = let
mkApp = bin: {
type = "app";
program = "${bin}/bin/${bin.pname or bin.name}";
};
apps = pkgs.lib.mapAttrs (_: mkApp) self.packages.${system};
scripts = {generate = mkApp (pkgs.callPackage ./generate {});};
in
apps // scripts;

checks = let
package-checks =
lib.mapAttrs (key: bin: let
name = bin.pname or bin.name;
version = bin.version or "0.0.0";
in
pkgs.runCommand "test-${name}-${version}" {} ''
touch $out
set -e
set -x

# Some package versions are not supported on some systems, ie. the
# "stable" version of Spago is not supported on aarch64.
if [ ${builtins.toString (builtins.hasAttr "unsupported" bin)} ]; then
echo "Skipping ${bin.name} because it is not supported on ${system}"
exit 0
fi

# Different packages at different versions use different 'version'
# flags to print their version
if [ ${builtins.toString (name == "spago" && pkgs.lib.versionOlder version "0.90.0")} ]; then
VERSION="$(${lib.getExe bin} version --global-cache skip)"
# spago@0.93.21 incorrectly reports its version
elif [ ${builtins.toString (name == "spago" && version == "0.93.21")} ]; then
VERSION="0.93.21"
else
# spago-next writes --version to stderr, oddly enough, so we need to
# capture both in the VERSION var.
VERSION="$(${lib.getExe bin} --version 2>&1)"
fi

# purs-tidy includes a 'v' prefix in its output beginning with version 0.9.0
if [ ${builtins.toString (name == "purs-tidy" && !(pkgs.lib.versionOlder version "0.9.0"))} ]; then
EXPECTED_VERSION="v${version}"
# purs-backend-es always includes it
elif [ ${builtins.toString (name == "purs-backend-es")} ]; then
EXPECTED_VERSION="v${version}"
else
EXPECTED_VERSION="${version}"
fi

echo "$VERSION should match expected output $EXPECTED_VERSION"
test "$VERSION" = "$EXPECTED_VERSION"
'')
# TODO: Remove once the purescript build of spago is stable
(pkgs.lib.filterAttrs (k: v: !(k == "spago" && system == "aarch64-darwin")) self.packages.${system});

example-checks = pkgs.callPackages ./nix/examples {};

script-checks = {
generate = let
bin = pkgs.callPackage ./generate {};
manifests = ./manifests;
in
pkgs.runCommand "test-generate" {} ''
mkdir -p $out/bin
set -e
set -x
cp ${bin}/bin/${bin.name} $out/bin/test-generate
${bin}/bin/${bin.name} verify ${manifests}
'';
};
in
package-checks // example-checks // script-checks;

devShells = {
default = pkgs.mkShell {
name = "purescript-overlay";
buildInputs = [
self.packages.${system}.spago-unstable
self.packages.${system}.purs-unstable
self.packages.${system}.purs-tidy-unstable
self.packages.${system}.purs-backend-es-unstable
self.packages.${system}.purescript-language-server-unstable

pkgs.nodejs
pkgs.prefetch-npm-deps
];
};
};
});
};

formatter = pkgs.alejandra;
})
// {
overlays.default = import ./overlay.nix;
};
}
4 changes: 2 additions & 2 deletions generate/bin/src/CLI.purs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ run = do
Console.log (Arg.printArgError error)
case error of
Arg.ArgError _ Arg.ShowHelp -> do
liftEffect (Process.exit 0)
liftEffect (Process.exit' 0)
_ ->
liftEffect (Process.exit 1)
liftEffect (Process.exit' 1)
Right command ->
pure command
14 changes: 5 additions & 9 deletions generate/bin/src/Env.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Dotenv as Dotenv
import Effect.Aff (Aff)
import Effect.Aff as Aff
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Class.Console as Console
import Lib.Foreign.Octokit (GitHubToken(..))
import Lib.Utils (die)
import Node.Encoding (Encoding(..))
import Node.FS.Aff as FS.Aff
import Node.Path (FilePath)
Expand Down Expand Up @@ -38,24 +38,20 @@ lookupOptional (EnvKey { key, decode }) = liftEffect $ Process.lookupEnv key >>=
Just "" -> pure Nothing
Just value -> case decode value of
Left error -> do
Console.log $ "Found " <> key <> " in the environment with value " <> value <> ", but it could not be decoded: " <> error
liftEffect (Process.exit 1)
die $ "Found " <> key <> " in the environment with value " <> value <> ", but it could not be decoded: " <> error
Right decoded -> pure $ Just decoded

-- | Look up a required environment variable, throwing an exception if it is
-- | missing, an empty string, or present but cannot be decoded.
lookupRequired :: forall m a. MonadEffect m => EnvKey a -> m a
lookupRequired (EnvKey { key, decode }) = liftEffect $ Process.lookupEnv key >>= case _ of
Nothing -> do
Console.log $ key <> " is not present in the environment."
liftEffect (Process.exit 1)
die $ key <> " is not present in the environment."
Just "" -> do
Console.log $ "Found " <> key <> " in the environment, but its value was an empty string."
liftEffect (Process.exit 1)
die $ "Found " <> key <> " in the environment, but its value was an empty string."
Just value -> case decode value of
Left error -> do
Console.log $ "Found " <> key <> " in the environment with value " <> value <> ", but it could not be decoded: " <> error
liftEffect (Process.exit 1)
die $ "Found " <> key <> " in the environment with value " <> value <> ", but it could not be decoded: " <> error
Right decoded -> pure decoded

-- | A user GitHub token at the REPO_TOKEN key.
Expand Down
Loading
Loading