Building nim2 package locally in nix-shell

I am trying to build GitHub - pcarrier/forms locally.
I am unable to find any Nim language setup related info on the wiki, and I am not able to use nimble2nix because i don’t understand Nim very well. I just want a local build to hack on non-nim portions of the repository.

I was told that the only packages required were

  • nim 2.0
  • emscripten
  • nimble

So I created a shell.nix as follows, so I can run nimble build in the resulting shell:

with import <nixpkgs> {};
let unstable = import <nixos-unstable> {}; in
stdenv.mkDerivation {
    name = "forms-build-env";
    buildInputs = [
      unstable.nim2
      emscripten
      unstable.nim2Packages.nimble
    ];
}

But I am getting the folowing error. How do I make this work correctly?

$ nix-shell
this derivation will be built:
  /nix/store/05vl97v9di8z233hk6gmz2am1yb3yfbi-nimble-0.14.2.drv
building '/nix/store/05vl97v9di8z233hk6gmz2am1yb3yfbi-nimble-0.14.2.drv'...
unpacking sources
unpacking source archive /nix/store/zygf3797sc4d7r4axhzkkc32q90r74y1-source
source root is source
patching sources
updateAutotoolsGnuConfigScriptsPhase
configuring
generating config.nims
building
build job 0: nim compile  --parallelBuild:16 --outdir:/nix/store/l0xqfcqlas93hlrgmzplyd6d76iq2ga0-nimble-0.14.2/bin src/nimble
Hint: used config file '/nix/store/ac60hq0pn6lrhn81ziymw1kv5iyqnfdm-x86_64-unknown-linux-gnu-nim-wrapper-2.0.0/etc/nim/nim.cfg' [Conf]
Hint: used config file '/nix/store/ac60hq0pn6lrhn81ziymw1kv5iyqnfdm-x86_64-unknown-linux-gnu-nim-wrapper-2.0.0/etc/nim/config.nims' [Conf]
Hint: used config file '/build/source/config.nims' [Conf]
Hint: used config file 'src/nimble.nim.cfg' [Conf]
...................................................................................................................................................
/build/source/src/nimblepkg/sha1hashes.nim(4, 38) Warning: use command `nimble install checksums` and import `checksums/sha1` instead; sha1 is deprecated [Deprecated]
.........................................
/build/source/src/nimblepkg/options.nim(255, 14) Warning: Couldn't determine GIT hash: /bin/sh: git: not found [User]
...........
/nix/store/wpqbx4vy29ln44i5y0hj2i0b1zk77jwb-nim-unwrapped-2.0.0/nim/compiler/nimblecmd.nim(18, 39) Error: cannot open file: ../dist/checksums/src/checksums/sha1
build phase failed
error: builder for '/nix/store/05vl97v9di8z233hk6gmz2am1yb3yfbi-nimble-0.14.2.drv' failed with exit code 1;
       last 10 log lines:
       > Hint: used config file '/nix/store/ac60hq0pn6lrhn81ziymw1kv5iyqnfdm-x86_64-unknown-linux-gnu-nim-wrapper-2.0.0/etc/nim/config.nims' [Conf]
       > Hint: used config file '/build/source/config.nims' [Conf]
       > Hint: used config file 'src/nimble.nim.cfg' [Conf]
       > ...................................................................................................................................................
       > /build/source/src/nimblepkg/sha1hashes.nim(4, 38) Warning: use command `nimble install checksums` and import `checksums/sha1` instead; sha1 is deprecated [Deprecated]
       > .........................................
       > /build/source/src/nimblepkg/options.nim(255, 14) Warning: Couldn't determine GIT hash: /bin/sh: git: not found [User]
       > ...........
       > /nix/store/wpqbx4vy29ln44i5y0hj2i0b1zk77jwb-nim-unwrapped-2.0.0/nim/compiler/nimblecmd.nim(18, 39) Error: cannot open file: ../dist/checksums/src/checksums/sha1
       > build phase failed
       For full logs, run 'nix log /nix/store/05vl97v9di8z233hk6gmz2am1yb3yfbi-nimble-0.14.2.drv'.

nim2Packages.nimble build fails: "git: not found" · Issue #264001 · NixOS/nixpkgs · GitHub is reported in nixpkgs for this issue.

The Nim 1.x counterpart does work for now, though that might not be helpful in your case.

BTW, if you’re creating a shell.nix use a template like this instead

let
  pkgs = import <nixpkgs> {};
in pkgs.mkShell {
  packages = [
    pkgs.nim2
    pkgs.emscripten
    pkgs.nim2Packages.nimble
  ];
}

i see, I’ll use the template, what do I do to work around this problem?

I use a tool to generate a Nix specific lockfile and then generate a nim.cfg from that.

https://git.sr.ht/~ehmry/nim_lk

3 Likes

Assuming I use the tool and the given script to make a nim.cfg file, would nimble build use that config, or do i need to do some additional steps? this isn’t my own project, so I’d like to change as few things in it as possible.

@ehmry I found a bug in it, to be honest I think is somewhere between nim_lk and nix-prefetch-url.

Futhark has a requirement of libclang-nim but using the following notation:

requires "https://github.com/PMunch/libclang-nim#head"

While this is ok for Nimble, fails with nix-prefetch-url