Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuilding with custom packages fails #54

Open
Kmetran opened this issue Nov 12, 2023 · 8 comments
Open

Rebuilding with custom packages fails #54

Kmetran opened this issue Nov 12, 2023 · 8 comments

Comments

@Kmetran
Copy link

Kmetran commented Nov 12, 2023

I wrote a simple shell script using writeShellApplication in a file called default.nix, inside a folder called custompackage in the pkgs folder, and then added it to pkgs/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.

@Kmetran Kmetran changed the title Trying to rebuild after adding a package fails Rebuilding with custom packages fails Nov 13, 2023
@Kmetran
Copy link
Author

Kmetran commented Nov 15, 2023

This is off topic so sorry in advance 😄, but how could I use an overlay that I added in overlays in a custom package in pkgs?

@proglottis
Copy link

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, ...}: {

@vakili
Copy link

vakili commented Nov 26, 2023

Thanks @proglottis, I had the same issue and this fixed it.

@arthsmn
Copy link

arthsmn commented Jan 4, 2024

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.

@voidzero
Copy link

Thank you, this helped me too.

I'm sure when @Misterio77 returns he'll give it a look.

@bcyran
Copy link

bcyran commented Mar 9, 2024

@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 😢

@m3tam3re
Copy link

That also solved it for me. But I would really like know why.

@LateNightIceCream
Copy link
Contributor

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants