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

Add Nix flake support #76

Open
wants to merge 1 commit into
base: golang
Choose a base branch
from

Conversation

jjthiessen
Copy link

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).

@@ -6,6 +6,7 @@ packages:
extra-deps:
- git: https://github.com/purescript/purescript
commit: 9cad73ed8ea7df3011032ddbd2f3de5a0c08629c
# nix-sha256: 0mlgww6j8nfdgy6x7l6z5in37r6qs11wnxf1cpgqaiyabadaik20
Copy link
Author

Choose a reason for hiding this comment

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

This is necessary because the commit isn't in the default branch (master).
Without this, Nix (haskell.nix) complains that it can't find the commit.

@jjthiessen
Copy link
Author

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
          ];
        };
      }
    );
}

];

overlay = final: prev: {
# This dummy package is required in building the project, but `hsc2hs` is actually provided by GHC.
Copy link
Author

Choose a reason for hiding this comment

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

It's part of the built GHC env, in any case. I'm not sure if this is the right way of fixing it, but it seems to work.

@jjthiessen jjthiessen mentioned this pull request Apr 20, 2022
@jjthiessen
Copy link
Author

jjthiessen commented May 1, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant