0

There is something that is not completely clear to me on hydra. The following jobset:

{ nixpkgs ? import <nixpkgs>
          { config.allowUnfree = true;
            config.allowBroken = true;
          }
, my_package  ? path/to/package/default.nix ## working expr
}:
let
  jobs = {
    jobA = import ../path/to/jobA/default.nix {inherit my_package;};
  };
in
  jobs

with 2 build inputs:

  1. ciSrc
  2. nixpkgs

evaluates without errors, and then is built.

BUT, when I change the working expr to:

my_package  ? import <my_package> ## problematic expr

and add a third build input:

  1. my_package, Local Path, path/to/package/default.nix

I get the following error:

hydra-eval-jobs returned exit code 1:
error: undefined variable 'foo' at /nix/store/somehash-my_package/.../default.nix:61:11
(use '--show-trace' to show detailed location information)

Why do I get it? what am I missing here?

My NIX_PATH contains both <nixpkgs> that works, and <my_package>, which isn't. This is the only change i did that produces the error.

btw both versions are built by nix-build, as recommended by the hydra-manual on the same machine and by the same user that the hydra uses.

can anyone please shed light on it?

toraritte
  • 6,300
  • 3
  • 46
  • 67

1 Answers1

0

I doubt that the undefined variable error message is directly caused by swapping the build inputs. It's more likely that the problem has been lurking for a while but never triggered, and swapping the inputs like this has caused it to surface. If that's the case, it's impossible to say what's causing the problem since you've stripped out all of the relevant information. To get better help in the future, I suggest that you post a minimal, complete example of code which encounters this problem. What you've posted is indeed minimal, but it's incomplete (the problem seems to be with package/default.nix, which you haven't included), and also doesn't look like code which encounters this problem (based on things like somehash, path/to/package, etc. I imagine that running this code would hit a syntax error first).

All we know is that a variable has been used without an accompanying binding. Your error message says that the variable is called foo, but I assume that's not the real name. Given this scant information, I would guess that the problem is in your package/default.nix file.

There are a few gotchas to keep in mind with paths in Nix:

  • Path values used by a derivation (like /tmp/project/foo.nix) will be copied to the Nix store and those values (e.g. /nix/store/...-foo.nix) will be used instead of the original path. This can break relative paths, e.g. if foo.nix references ./bar.nix, then the latter will resolve to /nix/store/bar.nix which doesn't exist. This can be managed by getting the directory added to the store, e.g. "${/tmp/project}/foo.nix".
  • String values, like "/tmp/project/foo.nix", do not cause things to be copied into the store.
  • It's easy for calculations to turn paths into strings, but hard to keep them as paths. One useful trick is to use + with a path as the first argument, e.g. /tmp + "/project" will produce the path /tmp/project. We can use this with "/.." to go up a level. As an extreme case, we can convert a string containing an absolute path to a path value by doing e.g. with { myString = "/foo/bar"; }; /tmp + "/..${myString}", which will give the path /tmp/../foo/bar which resolves to /foo/bar.
  • When a mutable local path gets inserted into the Nix store, it's only an immutable "snapshot". If the contents are changed later, it can be a little unpredictable whether the old, cached snapshot will be used or whether a new snapshot will be made. For this reason, it's important to look at the paths given in error messages, e.g. take a look at /nix/store/...-project/foo.nix rather than /tmp/foo.nix, since they may not contain the same thing.
Warbo
  • 2,611
  • 1
  • 29
  • 23