Installing a package for ghcjs which is not on hackage

Hello! I’m trying to add servant-ghcjs-client to my Haskell project. This package is not in Hackage, but it is within the servant git repo: https://github.com/haskell-servant/servant/tree/master/servant-client-ghcjs

Below, I’ve included the error output when running nix-build as well as both nix files and the cabal file.

Any tip you may have is very much appreciated!

The error:

$ nix-build
error: anonymous function at /nix/store/wdl7bmcnqfcw9jakpyii93z65wn0mgcr-cabal2nix-app/default.nix:1:1 called without required argument 'servant-client-ghcjs', at /nix/store/9r1vhvri4ba913g4vyg5jqrhg6pb9amn-source/pkgs/development/haskell-modules/make-package-set.nix:87:27

default.nix:

with import ./definitions.nix;

let
  server = pkgs.haskell.packages.ghc865.callCabal2nix "app" ./. {};
  client = pkgs.haskell.packages.ghcjs86.callCabal2nix "app" ./. {};
in
{
  inherit server client;
  app = pkgs.runCommand "app" { inherit client server; } ''
    mkdir -p $out/{bin,static}
    cp ${server}/bin/* $out/bin/
    ${pkgs.tree}/bin/tree -a ${client}
    cp ${client}/bin/client.jsexe/all.js $out/static/
  '';
}

definitions.nix:

with (import (builtins.fetchTarball {
  url = "https://github.com/dmjio/miso/archive/561ffad.tar.gz";
  sha256 = "1wwzckz2qxb873wdkwqmx9gmh0wshcdxi7gjwkba0q51jnkfdi41";
}) {});

let
  servant-src = pkgs.fetchFromGitHub { 
    owner = "haskell-servant";
    repo = "servant";
    rev = "5998429" ;
    sha256 = "1p21x6df0j6zsmjf4z9cahbi15mar80na8rx8hl9mkb9pfrj9dic";
  };
in

{
  inherit pkgs;

  ghcjs86 = pkgs.haskell.packages.ghcjs86.override {
    overrides = self: super: with pkgs.haskell.lib; {
      servant-client-ghcjs = pkgs.haskell.packages.ghcjs.callCabal2nix "${servant-src}/servant-client-ghcjs" {};
    };
  };
}

app.cabal:

name:               app
version:            0.1.0.0
build-type:         Simple
cabal-version:      >=1.10
license:            PublicDomain

executable server
  if impl(ghcjs)
    buildable: False
  hs-source-dirs:   common, server
  main-is:          Main.hs
  ghc-options:      -O2 -threaded -Wall -Werror -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns
  default-language: Haskell2010
  other-modules:    Common
  build-depends:    aeson,
                    base < 5,
                    bytestring,
                    containers,
                    cryptonite,
                    http-types,
                    lens,
                    lucid,
                    miso,
                    mtl,
                    network-uri,
                    persistent,
                    persistent-sqlite,
                    persistent-template,
                    servant,
                    servant-lucid,
                    servant-server,
                    text,
                    wai,
                    wai-extra,
                    wai-cors,
                    warp

executable client
  if !impl(ghcjs)
    buildable: False
  hs-source-dirs:   common, client
  ghc-options:      -O2 -threaded -Wall -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns
  other-modules:    Common
  main-is:          Main.hs
  ghcjs-options:    -dedupe
  default-language: Haskell2010
  build-depends:    aeson,
                    base < 5,
                    containers,
                    ghcjs-base,
                    lens,
                    miso,
                    network-uri,
                    servant,
                    servant-client-ghcjs, 
                    text

I haven’t actually tried this out, but it looks like you’re not actually using the ghcjs86 you’ve defined in definitions.nix.

Maybe in default.nix, you can change the following line:

client = pkgs.haskell.packages.ghcjs86.callCabal2nix "app" ./. {};

to

client = ghcjs86.callCabal2nix "app" ./. {};

If you’re new to nix, I highly recommend you don’t use with, since it can be difficult to see what derivations come from where. Also, not splitting things into separate files until you have everything working may help debugging a little.

Good catch, and thank you for the tips! I may very well need to use “with” in order to use Miso, but I might be wrong.

Anyway, now I’ve got an error, and I could use some help in figuring out what is attempting to be coerced to a string :slight_smile:

$ nix-build
error: cannot coerce a function to a string, at /nix/store/9r1vhvri4ba913g4vyg5jqrhg6pb9amn-source/pkgs/development/haskell-modules/generic-builder.nix:245:3
(use '--show-trace' to show detailed location information)

/nix/store/9r1vhvr…amn-source/pkgs/development/haskell-modules/generic-builder.nix

244 stdenv.mkDerivation ({
245   name = "${pname}-${version}";
246
247   outputs = [ "out" ]

If you upload this as a full example to GitHub, I (or someone else) may be able to easily clone it and help figure out your problem.

Thanks for being willing to help!

Hello,
In definitions.nix, I think line 20 should be:

servant-client-ghcjs = pkgs.haskell.packages.ghcjs.callCabal2nix "servant-client-ghcjs" "${servant-src}/servant-client-ghcjs"  {};

Oh, yeah! Thanks Julien!

Apologies for continuing to ask for help, but here it is…

Running nix-shell gave me a hash mismatch error, so I ran:

$ nix-prefetch-url https://github.com/haskell-servant/servant.git
[0.1 MiB DL]
path is '/nix/store/f7krnkrgj1c8wa5w5hhy8p3hcpvaygai-servant.git'
14vwimyq039pw0xz6daw2dglh9vr790alkbpl7dkgwap5dx9pvyj

I then changed the sha256 value in servant-src to that hash, but still get the same hash mismatch error (same hashes in wanted and got of previous and new error):

building '/nix/store/5wrjm63d6rmvf6dgq8qirfy2r2wa3nsh-source.drv'...

trying https://github.com/haskell-servant/servant/archive/5998429.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   165    0   165    0     0    774      0 --:--:-- --:--:-- --:--:--   774
100  308k    0  308k    0     0   560k      0 --:--:-- --:--:-- --:--:-- 13.3M
unpacking source archive /private/var/folders/wq/s8mfqyy57kz2m1zy2xzk6hjm0000gn/T/nix-build-source.drv-0/5998429.tar.gz
hash mismatch in fixed-output derivation '/nix/store/x877vinsvpdxv4mm5lf2r837mijxm1c7-source':
  wanted: sha256:14vwimyq039pw0xz6daw2dglh9vr790alkbpl7dkgwap5dx9pvyj
  got:    sha256:0yrg78f3lmzpcx4hyaaaf1yygxx9kijsvk499fih3adkbxgyx8wg
cannot build derivation '/nix/store/1vwmriqnyaw55vg3iic40wrgqcpj98kn-cabal2nix-servant-client-ghcjs.drv': 1 dependencies couldn't be built
error: build of '/nix/store/1vwmriqnyaw55vg3iic40wrgqcpj98kn-cabal2nix-servant-client-ghcjs.drv' failed
(use '--show-trace' to show detailed location information)```

This means the SHA256 for the servant package is incorrect in definitions.nix.
You can change the line to:

    sha256 = "0yrg78f3lmzpcx4hyaaaf1yygxx9kijsvk499fih3adkbxgyx8wg";
1 Like

Btw, the build failed on my machine but I managed to build servant-client-ghcjs in a test project: nix/nixpkgs.nix · servant-client-ghcjs · julien dehos / miso-bmxtricks · GitLab. Maybe it can help.

1 Like