0

I have a nix expression file (.nix) and a shell script builder, specified like:

stdenv.mkDerivation rec {
    name = "my-env";
    builder = './my-builder.sh';
    ...

./my-builder.sh: No such file or directory when I run nix-build ./my-env.nix; the nix expression file and builder scripts are sitting side-by-side in my home directory.

My intent is to use this nix expression file to prepare an environment using nix-build and then to actually quickly run the environment whenever I want to use it (using nix-shell).

EDIT: I just noticed that nix-shell ./ my-env.nix works fine; so far I'm not actually building anything, so I should probably just omit the builder.

EDIT#2: My concrete example is the following:

This line puts both the nix expression and the builder in the same directory. This other line uses nix-shell to prepare the environment, but I assume a similar nix-build command could be used (especially if one wanted to install a custom package as part of the environment, but maybe that is not very idiomatic in Nix)

Solution

Quotes around the builder's path were apparently a no-no. I ended up having other issues, and pieced this together to eventually get the thing to run:

builder = builtins.toFile "builder.sh" ''
  source $stdenv/setup
  mkdir -p $out
  echo "" > $out/Done
  echo "Done setting up Scala environment."
'';
bbarker
  • 11,636
  • 9
  • 38
  • 62

1 Answers1

1

Try putting a semicolon at the end of the line and removing the single quotes:

builder = ./my-builder.sh;

Then double-check to make sure my-builder.sh is in the same directory as the .nix file where you wrote that.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Oops, I will edit the question. This was in fact a transcript error - what I get for not copy/pasting. So, I had in fact already done this. They are definitely in the same directory. I will also edit with EDIT#2 momentarily to point to a full example. – bbarker Sep 08 '17 at 20:39
  • The symbolic link is fishy, because it looks like you might be counting on Nix to dereference that link for you so that it knows the real location of the file. I'm not sure though. If you could make an example that doesn't involve a symbolic link it might help. – David Grayson Sep 08 '17 at 23:20
  • Apparently my problem was that the surrounding quotes I had around the builder scripts relative path (not sure why that is an issue). I had other problems beyond that, so ended up using an inlined "dummy" script; I'll post the solution I ended up with – bbarker Sep 18 '17 at 21:13
  • To clarify, either double quotes or single quotes could be problematic. Initially I only noticed your semicolon suggestion, not the bit about quotes - sorry! – bbarker Sep 18 '17 at 21:28
  • 1
    When you write a filename like `./my-builder.sh` without quotes it is definitely not a string! It is a signal to the Nix language parser to look for a file named `./my-builder.sh` relative to the current Nix file and add it to the Nix store as a source file. But if you add quotes, it becomes a string, which is not what you want. – David Grayson Sep 18 '17 at 22:36