Open Kmetran opened 8 months ago
This is off topic so sorry in advance :smile:, but how could I use an overlay that I added in overlays in a custom package in pkgs?
I just ran into this exact error message. The secret sauce for me was changing the function declaration in pkgs/default.nix
from
pkgs: {
To
{pkgs, ...}: {
Thanks @proglottis, I had the same issue and this fixed it.
Can anyone explain why this is the case? And if this will ever be added to the repository, because without it the overlay doesn't work.
Thank you, this helped me too.
I'm sure when @Misterio77 returns he'll give it a look.
@proglottis Thank you so much for this. I spent too much time trying to figure it out and I didn't make even a step in the right direction. Nix is so hard :cry:
That also solved it for me. But I would really like know why.
This is because in this line in overlays/default.nix
additions = final: _prev: import ../pkgs { pkgs = final; };
we call our function defined in pkgs/default.nix
with an attribute set as an argument in which the value pkgs
equals final
.
However, looking at our function definition
pkgs : {
...
}
our single argument will become pkgs = { pkgs = final; }
. So then pkgs.callPackage
would have to be pkgs.pkgs.callPackage
. And indeed this would work.
Changing this as @proglottis suggested works because we are changing the function definition to receive as an argument a set with a certain attribute requirement (pkgs
). We can then reference this attribute directly.
Another way to fix this is to keep pkgs/default.nix
the same and instead change the function call in overlays/default.nix
:
additions = final: _prev: import ../pkgs final;
or if we really only want to pass pkgs (which is probably what is intended here):
additions = final: _prev: import ../pkgs final.pkgs;
I wrote a simple shell script using
writeShellApplication
in a file calleddefault.nix
, inside a folder calledcustompackage
in thepkgs
folder, and then added it topkgs/default.nix
like this:custompackage = pkgs.callPackage ./custompackage {};
After that, I tried adding it to environment.systemPackages or home.packages, but either way, rebuilding fails with:
attribute 'callPackage' missing
I'm using the standard template, and it does build if
pkgs/default.nix
has no package.