nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

How to reuse survey? #38

Closed mulderr closed 5 years ago

mulderr commented 5 years ago

It would be great to add an example somewhere of how to reuse survey from other projects. What would be the best way though?

Not a nix expert but I think it would be easier to provide such an example if we could:

There is an overlays argument in survey but it seems currently unused. Was it maybe supposed to be appended like so?

nh2 commented 5 years ago

Hey,

they static-stack2nix-builder` is an example of how to reuse survey/default.nix by simply importing it.

It shows the things you ask for, including pinning a nixpkgs version inside nix: https://github.com/nh2/static-haskell-nix/blob/71d3aaa533687c2b11091f04b8a2abddfe8b99af/static-stack2nix-builder/default.nix#L20

Does that help, or are you looking for some different examples / descriptins of a specific use case?

I think the overlays argument is a leftover and I should remove it. You can use the static-haskell-nix output with overlays as usual by just using .extend on the returned package set.

The fact that static-haskell-nix uses a nixpkgs submodule shouldn't be problematic here. I use it mainly so that I can quickly iterate on fixing things in nixpkgs as static-haskell-nix needs it. You can skip using it by simply not setting NIX_PATH=nixpkgs=nixpkgs. But the nixpkgs you use should have the fixes I have in my submodule. I have PRd most of those upstream already, but there may be things that aren't merged yet.

mulderr commented 5 years ago

Ah, I see. Thanks, that is what I was looking for. Should have checked the whole repo before asking.

That said, I guess I'm still a little confused which nixpkgs to use to get best results with cachix. Is it generally ok to copy the url from static-stack2nix-builder? Or would any recent enough version work all the same?

mulderr commented 5 years ago

Ended up with something like this:

let
  sources = {
    nixpkgs = fetchTarball {
      url = "https://github.com/nh2/nixpkgs/archive/a2d7e9b875e8ba7fd15b989cf2d80be4e183dc72.tar.gz";
      sha256 = "1hnmp637r99qd6g0sbx4w3za564gbzwl5c4z0x7fvn7kfi2jp1hx";
    };
    shn = fetchTarball {
      url = "https://github.com/nh2/static-haskell-nix/archive/8d004d7ced9da947c785b93b4011f39367442339.tar.gz";
      sha256 = "0nw4g23c5rs0cvaar2phpr60zim9r0qycznpifi8d8k85y4r3bdd";
    };
  };

in

{ nixpkgs ? import sources.nixpkgs {}
}:
let
  inherit (nixpkgs) lib;

  haskellOverlay = self: super: {
    haskell = super.haskell // {
      packages = super.haskell.packages // {
        ghc864 = super.haskell.packages.ghc864.override (old: {
          overrides = lib.composeExtensions (old.overrides or (_: _: {})) (hself: hsuper: {
            mypkg = hself.callPackage ./mypkg.nix {};
          });
        });
      };
    };
  };

  shn = import (builtins.toPath "${sources.shn}/survey") {
    normalPkgs = import nixpkgs.path { overlays = [ haskellOverlay ]; };
    compiler = "ghc864";
  };

in shn.haskellPackages.mypkg

My only nitpick is callCabal2nix fails in mysterious ways but that's not a big deal. Static executable successfully built. Thank you for making this available!