How to make a new packaged binary work

Hello, first of all sorry for my bad english, it’s not my first language. Secondly im pretty new with nix and nixos, and i have been following a video on how to make your own packages, and i cant get it to work. It says to do this:


But then when i rebuild the system it gives me this error:

━ 1 Errors:
┃ error:
┃ … while calling the ‘head’ builtin

┃ at /nix/store/yqy82fn77fy3rv7lpwa9m11w3a2nnqg5-source/lib/attrsets.nix:1575:11:

┃ 1574| || pred here (elemAt values 1) (head values) then
┃ 1575| head values
┃ | ^
┃ 1576| else

┃ … while evaluating the attribute ‘value’

┃ at /nix/store/yqy82fn77fy3rv7lpwa9m11w3a2nnqg5-source/lib/modules.nix:809:9:

┃ 808| in warnDeprecation opt //
┃ 809| { value = builtins.addErrorContext “while evaluating the option `${showOption loc}':” value;
┃ | ^
┃ 810| inherit (res.defsFinal’) highestPrio;

┃ (stack trace truncated; use ‘–show-trace’ to show the full trace)

┃ error: access to absolute path ‘/home/ruby/nixos/packages/golings/default.nix’ is forbidden in pure eval mode (use ‘–impure’ to overri…
┣━━━
┗━ ∑ :warning: Exited with 1 errors reported by nix at 17:30:22 after 7s
Error:
0: Command exited with status Exited(1)

And i dont know what to do to get it to work. I’ve been searching through the forum, and i think i have to call it from the flake.nix. But im not really sure on how to do it. Sorry if is a silly question. And thanks for answering.

Flakes enable something called “pure eval” by default. In this mode, nix is only allowed to access files whose parent directories contain your flake.nix or other flakes.

This is so that if you copy your project to a different machine, it doesn’t suddenly lack your package definition (or any number of other files that might be lying around on one host but not the other). It also enables nix to do some caching that would be quite complex otherwise.

So you have two options:

  1. Move your package definition into the same directory as (or a subdirectory of) your configuration flake - and use a relative path to refer to it instead of an absolute one, in case it’s already like that
  2. Turn your package definition into a flake and depend on it using your flake inputs

You can also use the --impure flag as a last resort, but fixing this isn’t particularly hard, so I’d suggest you try to understand the issue before using that escape hatch :slight_smile:

1 Like

Thank you so much, i have made it into a relative path and now it works, i would like to know how to make it into a flake too, so i will look into it, thanks!