Making sources mutable

I want to use nix to build my project, as it has a pretty nasty dependency. I used it on that one and it worked fine, but now I also want to make nix fetch another repo, which is needed to build.

I think my problem is that the make script wants to write to immutable directories in /nix. I think I’m doing something wrong, as makefiles often do that kind of thing.

The code is https://github.com/joonazan/nina-fast-bluetooth/blob/2d8af685c083e225339225830caf7814395c82af/default.nix.

If I change IDF_PATH to a local esp-idf checkout, everything works.

I think my problem is that the make script wants to write to immutable directories in /nix. I think I’m doing something wrong, as makefiles often do that kind of thing.

If I change IDF_PATH to a local esp-idf checkout, everything works.

I think normally they only write to their main source, which is copied to the build directory and made writeable byt default.

Maybe just manually copy the dependency source into the build directory, chmod, and set the IDF_PATH accordingly?

Maybe the problem is not what I think it is. I added

  IDF = esp-idf;
 
   buildPhase = ''
     cp -r $IDF esp-idf
     export IDF_PATH=$(pwd)/esp-idf
     make
   '';

I’m still getting


builder for '/nix/store/mnbdrn6l6qwrjxlanmsj86n9hf24vm2f-esp-idf-env.drv' failed with exit code 2; last 10 log lines:
  make: which: Command not found
  make[1]: Entering directory '/tmp/nix-build-esp-idf-env.drv-1/src/esp-idf/tools/kconfig'
  gcc -c  -DCURSES_LOC="<ncurses.h>" -DLOCALE -MMD -MP  /tmp/nix-build-esp-idf-env.drv-1/src/esp-idf/tools/kconfig/mconf.c -o mconf.o
  /tmp/nix-build-esp-idf-env.drv-1/src/esp-idf/tools/kconfig/mconf.c:1053:1: fatal error: opening dependency file mconf.d: Permission denied
   1053 | }
        | ^
  compilation terminated.
  make[1]: *** [Makefile:171: mconf.o] Error 1
  make[1]: Leaving directory '/tmp/nix-build-esp-idf-env.drv-1/src/esp-idf/tools/kconfig'
  make: *** No rule to make target '/tmp/nix-build-esp-idf-env.drv-1/src/esp-idf/tools/kconfig/conf-idf', needed by '/tmp/nix-build-esp-idf-env.drv-1/src/build/include/config/auto.conf'.  Stop.

EDIT: I forgot the chmod part. What’s the best way to do that?

Works now. I was not able to make fetchFromGithub produce the same result as manually cloning, so I made this abomination https://github.com/joonazan/nina-fast-bluetooth/blob/841fc18aa53112bd0f88921cd18d96cf2bb460f5/default.nix#L19

If you have any tips to make the build more incremental, please tell.

I found a less pure solution that works well in this case. I just added test -e esp-idf || git clone -b v3.3.1 --recursive https://github.com/espressif/esp-idf.git to shellHook.

if you have the sources local, you can also just use a path

  src = ../path/to/source;

nix will automatically add it to the store and treat it as if you fetched it.

fetchFromGitHub does not clone submodules because it downloads the tarball and GitHub doesn’t include submodules in it. You are looking for fetchgit with the argument fetchSubmodules = true.

fetchFromGitHub supports fetchSubmodules.

if fetchSubmodules is set to true, it will use fetchgit under the covers:

# pkgs/build-support/fetchgithub/default.nix
...
  fetcher = if fetchSubmodules then fetchgit else fetchzip;
...
  fetcherArgs = (if fetchSubmodules
    then { inherit rev fetchSubmodules; url = "${baseUrl}.git"; }
    else ({ url = "${baseUrl}/archive/${rev}.tar.gz"; } // privateAttrs)
  ) // passthruAttrs // { inherit name; };
in fetcher fetcherArgs // { meta.homepage = baseUrl; inherit rev; }

Thanks for the heads up, I wasn’t aware of this.