问题
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."
'';
回答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.
来源:https://stackoverflow.com/questions/46116114/where-should-the-builder-script-be-located-for-a-stand-alone-nix-expression