purescript-native icon indicating copy to clipboard operation
purescript-native copied to clipboard

Add Nix flake support

Open jjthiessen opened this issue 2 years ago • 2 comments

This adds Nix flake support, and replaces the default non-Stack Nix build (default.nix) with one that produces the default package from the flake.

I've created a public binary cache on Cachix that I've pushed the flake's associated derivations to. For now, this only has x86_64-linux derivations, as I don't presently have access to a mac build host.

To hack on psgo itself, you can run nix develop github:jjthiessen/purescript-native/add-flakes#hacking-on-psgo (in this case, you'll have it checked out anyway, so you can use relative file system path references instead). To use psgo in a project, you can run nix develop github:jjthiessen/purescript-native/add-flakes#using-psgo (or reference it with a relative path if you're trying to use a non-released version).

I think that the two bundled development shells should be generally useful, but I'd be interested to know what people think should or shouldn't be included.

Apart from the shells, the flake provides both psgo and purescript/purs as packages/apps. Both psgo and purescript are included as I figured it could be important to use the same version of PureScript with psgo as the one that it was compiled against (and this ensures that it's the same commit).

You can directly execute binaries by doing something like nix run github:jjthiessen/purescript-native/add-flakes#psgo.

This still isn't perfect. I'd like to figure out whether I can reduce the closure size at all, and it'd be nice if the Nix-enabled Stack build (stack --nix build) could use the same derivations as the flake/haskell.nix's stackProject (I'm not sure if this can be done).

jjthiessen avatar Mar 10 '22 18:03 jjthiessen

For consuming the using-psgo shell from another flake, you can assign it directly, or extend via inputsFrom like this:

{
  description = "An example PureScript/Go project";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    go-1-18.url = "github:flyx/go-1.18-nix";
    nixpkgs.url = "nixpkgs/nixos-unstable";
    ps-native-go = {
      url = "github:jjthiessen/purescript-native/add-flakes";
    };
  };

  outputs = { self, flake-utils, go-1-18, nixpkgs, ps-native-go }:
    flake-utils.lib.eachSystem [ flake-utils.lib.system.x86_64-linux ] (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ go-1-18.overlay ];
        };
      in {
        devShell = pkgs.mkShell {
          buildInputs = with pkgs; [
            go_1_18
          ];

          inputsFrom = [
            ps-native-go.devShells.${system}.using-psgo
          ];
        };
      }
    );
}

jjthiessen avatar Mar 10 '22 22:03 jjthiessen

So, with one ephemeral change from this branch's current state:

diff --git a/app/Main.hs b/app/Main.hs
index 8eaa1022..75a6da5b 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -132,7 +132,7 @@ main = do
     project <- projectEnv
     case cmd of
       Build -> do
-        callProcess "go" ["build", T.unpack project </> modPrefix' </> "Main"]
+        callProcess "go" ["build", "-mod", "mod", T.unpack project </> modPrefix' </> "Main"]
       Run moduleName -> do
         callProcess "go" ["run", T.unpack project </> modPrefix' </> fromMaybe "Main" moduleName]
     return ()

I'm able to run the tests for the psgo version of things using recent versions of Go. From that, I get purescript-tests.out.txt (using psgo --tests).

@andyarvanitis, is there/do you have a nice process of generating analogous output using the node/JS backend, or should I just temporarily modify src/Tests.hs and rebuild to make it work/generate test output as needed?

jjthiessen avatar May 01 '22 20:05 jjthiessen