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 support for cross-compilation with Nix #44

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
shell = { inherit crossPlatforms; };
Copy link
Owner Author

Choose a reason for hiding this comment

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

If we want to support nix build, rather than just *-cabal within nix develop (more on that elsewhere), we need to add configureArgs = "-frelease"; here if we don't want the built monpad to rely on finding the rsc folder. This is annoying because:

  • It's duplication between this file and the Shake build script.
  • It doesn't work! Presumably this is something to do with the asset files not being tracked by Nix. But I thought that Haskell.nix would handle that for us. I'm sure I even read somewhere about it having special support specifically for file-embed. nix build .#monpad:exe:monpad fails with:
    src/Embed.hs:32:27: error:
        • Exception when trying to run compile-time code:
            rsc/common.css: withBinaryFile: does not exist (No such file or direc>
          Code: (embedFile $ "rsc" </> "common.css")
        • In the untyped splice: $(embedFile $ "rsc" </> "common.css")
       |
    32 | commonCSS () = GET_FILE("rsc" </> "common.css")
       |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    

Copy link
Owner Author

@georgefst georgefst Aug 12, 2022

Choose a reason for hiding this comment

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

  • It doesn't work!

It does now! I think what changed is that I'm now working from a clean checkout. Somehow a dirty git working dir gets in the way. EDIT: got too excited - as stated above this currently builds a version with no embedded files

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hacked a solution in 814b4cc, but I should probably make those dependencies tracked by Nix, or something. I also have a no-symlinks stash for Build.hs modifications (although I'm not sure that's the best approach either, given assets need to be known to Git and I don't want duplicates).

Copy link
Owner Author

Choose a reason for hiding this comment

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

This crossPlatforms is only necessary for nix build, which we were hoping not to use (the other being for nix develop, which gives us access to the Shake build script).

But right now, that's working and the other isn't.

});
})

haskellNix.overlay
(final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isMusl {
libevdev = prev.libevdev.overrideAttrs (_: { dontDisableStatic = true; });
})
Copy link
Owner Author

Choose a reason for hiding this comment

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

I should upstream this patch somehow, as initially suggested on Reddit.

];
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
in
Expand Down