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

overrideAttrs and buildInputs doesn't include override inputs in environment #277

Closed
Skarlett opened this issue Mar 3, 2023 · 4 comments · Fixed by #307
Closed

overrideAttrs and buildInputs doesn't include override inputs in environment #277

Skarlett opened this issue Mar 3, 2023 · 4 comments · Fixed by #307

Comments

@Skarlett
Copy link

Skarlett commented Mar 3, 2023

{
  coggiebot = naerk-lib.buildPackage
    rec {
      name = "coggiebot";
      src = ../../.;
      COMMIT_REV=(self.rev or "canary");
    };
  
  # uses cmake during build.rs script 
  mockingbird = coggiebot.overrideAttrs(p: { nativeBuildInputs = p.nativeBuildInputs ++ [ pkgs.cmake ]; });
}

Building mockingbird fails with

error: builder for '/nix/store/wgx876njl4wj37hg06333w92ywc6s5r8-coggiebot-deps-1.3.8.drv' failed with exit code 101;
       last 10 log lines:
       >
       >   --- stderr
       >   thread 'main' panicked at '
       >   failed to execute command: No such file or directory (os error 2)
       >   is `cmake` not installed?
       >
       >   build script failed, must exit now', /sources/cmake-0.1.49/src/lib.rs:1104:5
       >   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       > warning: build failed, waiting for other jobs to finish...
       > [naersk] cargo returned with exit code 101, exiting
       For full logs, run 'nix log /nix/store/wgx876njl4wj37hg06333w92ywc6s5r8-coggiebot-deps-1.3.8.drv'.
error: 1 dependencies of derivation '/nix/store/ixjakb5pal9nnbkzh70pqp3v8qcaw5sz-coggiebot-1.3.8.drv' failed to build
nix-repl>:lf .
nix-repl> (outputs.packages.x86_64-linux.coggiebot-raw.overrideAttrs(p: {nativeBuildInputs = p.nativeBuildInputs ++ [pkgs.cmake];}) ).nativeBuildInputs
[ «derivation /nix/store/ka292dhy04diz66w1kjb8ifin1yz9c0c-cargo-1.65.0.drv» «derivation /nix/store/xr7jlh2cnlv1fk6ya661wy6hpb6vz2jx-jq-1.6.drv» «derivation /nix/store/abh3b8z5f5wzsm2abyirsdr6bxak1rfk-rsync-3.2.7.drv» «derivation /nix/store/slwfkzia7azhx5jjp51cqqsmanxyx2cs-cmake-3.22.3.drv» ]

Though, we can see it included

@Skarlett Skarlett changed the title overrideAttrs and buildInputs doesn't include overrode inputs in environment overrideAttrs and buildInputs doesn't include override inputs in environment May 10, 2023
@Skarlett
Copy link
Author

Skarlett commented May 10, 2023

I eventually solved this issue by applying overrides to the arguments, collecting the changes, then lowering the final result into naersk.buildPackage

@Patryk27
Copy link
Contributor

To be fair, I'm not sure what's happening in here 👀 -- would you mind showing the approach that worked?

@Skarlett
Copy link
Author

Skarlett commented Jun 25, 2023

Yeah absolutely. This was my first project I was using with naersk, so the code isn't super pretty. If theres any confusions, feel free to reach out. I only wrote this a couple months ago.

The solution I ended up walking away with was the following:

The overrides being applied are at this point,
https://github.com/Skarlett/coggie-bot/blob/master/iac/coggiebot/default.nix#L215-L233

and the definitions of those overrides are defined here. https://github.com/Skarlett/coggie-bot/blob/master/iac/coggiebot/default.nix#L33C1-L88

The original pattern I was attempting when I posted this issue was akin to

coggiebot = (naersk.buildPackage ./.);
mockingbird = coggiebot.overrideAttrs { buildInputs = [ ... ]; };
other-features = mockingbird.overrrideAttrs { ... };

Attempting the above resulted in the original error posted. This may be difficult to reproduce, as I was just learning nix at the time, and there may have been mistakes previously which lead to this incident.

there is a sliver of documentation on this portion of the project, which can be found here https://github.com/Skarlett/coggie-bot/blob/master/docs/hacking.md#finalizing-in-nix
but this is primarily for contributors, but it roughs out the process of adding features into the project, and finalizing those attributes in nix.

ps: if you need to build my project nix build .#coggiebot-stable will do it.

@Patryk27
Copy link
Contributor

Patryk27 commented Jul 2, 2023

Ah, I think I know what's going on - when you call naersk.buildPackage, it actually builds two derivations: first we build only the dependencies and then we build your code (so that if only your code changes, the dependencies don't have to get rebuilt, which could take a lot time).

So when you do stuff like:

let
  pkg = naersk.buildPackage { 
    # src etc. ...
  };

in
pkg.overrideAttrs {
  # whatever you need to override
}

... it overrides attributes only for that second derivation (i.e. your code), but it doesn't override stuff for the expression that builds the dependencies (since that expression is constructed separately inside buildPackage).

In general, this is what the override option is for, i.e.:

naersk.buildPackage {
  # src etc. ...
  
  override = old: {
    SOMETHING = "bar";
  };
}

... will apply this function to both derivations included in the build.

Although in this particular case, I think something like this should just do it:

naersk.buildPackage {
  # src etc. ...
    
  nativeBuildInputs = [ pkgs.cmake ];
}

Patryk27 added a commit that referenced this issue Sep 5, 2023
Patryk27 added a commit that referenced this issue Sep 6, 2023
Patryk27 added a commit that referenced this issue Sep 6, 2023
Patryk27 added a commit that referenced this issue Sep 7, 2023
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

Successfully merging a pull request may close this issue.

2 participants