-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Description
Describe the bug
I am trying to use addAttrsToDerivation to add some default compilation flags but I think this function is broken. The inline comment suggests the usage should be:
stdenvNoOptimise =
addAttrsToDerivation
{ env.NIX_CFLAGS_COMPILE = "-O0"; }
stdenv;
Although a quick search through Github, shows most people using it without the env before NIX_CFLAGS_COMPILE. In either case the following errors are reported:
With env:
error: attribute 'libc_bin' missing
Without env
error: The ‘env’ attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping:
NIX_CFLAGS_COMPILE
Steps To Reproduce
Use nix-build to try and compile GNU hello with an additional compilation flag via an overlay:
{
system ? builtins.currentSystem,
sources ? import ./nix/sources.nix,
}:
let
myOverlay = self: super: {
stdenv = super.addAttrsToDerivation { NIX_CFLAGS_COMPILE = "-O0"; } super.stdenv;
};
# 23.11
pkgs = import sources.nixpkgs {
overlays = [
myOverlay
];
};
in pkgs.helloExpected behavior
GNU hello builds with the compilation flag -O0.
Additional context
I think the changes in PR #225787 around how env is handled broke both withCFlags and addAttrsToDerivation. The issue with withCFlags was raised in #225740 and fixed in #225929, however, addAttrsToDerivation seems to have been overlooked and seems to have the same problem. In fact, both that issue and this issue mention the error message:
attribute 'libc_bin' missing
Notify maintainers
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
this path will be fetched (0.00 MiB download, 0.00 MiB unpacked):
/nix/store/mh3dkpww5py0fnrihk45pw7hvkj5fxxc-nix-info
copying path '/nix/store/mh3dkpww5py0fnrihk45pw7hvkj5fxxc-nix-info' from 'https://cache.nixos.org'...
- system: `"x86_64-linux"`
- host os: `Linux 6.8.7-zen1-1-zen, Debian GNU/Linux, 12 (bookworm), nobuild`
- multi-user?: `no`
- sandbox: `no`
- version: `nix-env (Nix) 2.16.1`
- nixpkgs: `/home/developer/.nix-defexpr/channels/nixpkgs`