Nim dependency unable to be found

I am currently trying to create a flake for LibVFIO’s arcd tool which is written in Nim. I have a repo with a flake.nix added here. I originally manually packaged all the dependencies listed in libvfio.nimble, but after some trouble I switched to nimble2nix, which unfortunately didn’t help. With both methods, the build always fails with > /nix/store/cpydrynvv097qmldsn3wvp44n8ihmqx8-uuids-8cb8720/uuids.nim:2:8 Error: cannot open file: isaac.

Looking at the Nix store, I can see that isaac is building correctly, the same as the other modules. At the beginning of the build, the nix log outputs found nimble input /nix/store/kdh54arssp1cwi5ina26m01k5zp63vg5-isaac-45a5cbb.

I’m pretty unfamiliar with using Nim with NixOS, so if anybody can help I would greatly appreciate it.

nimble2nix use pkgs.nimPackages.buildNimPackage that use nim_builder to interpret the nimble file of dependencies and discover the srcDir (default to project root), but Isaac, with his 180 years old, uses and speaks an archaic nimble format (was somekind of ini).

It means buildNimPackage thinks its content is at . instead of ./src

  1. fork Isaac, update nimble file, and your nimble2nix.json
  2. override adding replace isaac-0.1.3 to isaac-0.1.3/src in config.nims in postConfigure
  3. ask nimble2nix to accept other arguments like postConfigure in buildNimblePackage
  4. ask @ehmry to make nim_builder, read the older format.

My tests, needs cleanup:

        packages.default = 
          let buildNimblePackage = {
              name ? "${pname}-${version}",
              deps ? src + "/nimble2nix.json",
              buildInputs ? [],
              nativeBuildInputs ? [],
              depsPkgs = 
                if builtins.pathExists deps then
                  pkgs.lib.mapAttrsToList (name: src:
                      buildNimblePackage {
                        inherit name;
                        pname   = null;
                        version = null;
                        src     = pkgs.fetchgit { inherit (src) url rev sha256 fetchSubmodules;};
                  ) (pkgs.lib.importJSON deps)
                  else [];
            in pkgs.nimPackages.buildNimPackage {
              inherit name src nativeBuildInputs;
              buildInputs   = buildInputs ++ depsPkgs;
              postConfigure = ''
                cat config.nims
                substituteInPlace config.nims \
                  --replace isaac-0.1.3 isaac-0.1.3/src
          in buildNimblePackage {
            pname   = "arcd";
            version = "0.1";
            src     = ./.;
1 Like

ask @ehmry to make nim_builder read the older format.

I don’t want to support old Nimble formats, I want to support as little of Nimble as possible. Nimble will wither away because we are going to replace it with Nix.

If it were me I would just patch the Nimble file in Isaac or drop in a fresh one.