Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Created September 13, 2019 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitometsu/18b8f98bb9d63f38324cd3da7e9c0b9b to your computer and use it in GitHub Desktop.
Save Pitometsu/18b8f98bb9d63f38324cd3da7e9c0b9b to your computer and use it in GitHub Desktop.
How to override CC by Nix overlay?
(self: super:
let
# gcc = super.pkgs.gcc8;
# gcc8 = super.pkgs.gcc8.override { stdenv = super.stdenv; };
stdenv = super.stdenvAdapters.overrideCC super.stdenv super.pkgs.gcc8;
in
{
inherit stdenv; # gcc8 gcc;
# stdenv = super.overrideCC super.stdenv self.pkgs.gcc;
# gcc8 = super.gcc8.override { stdenv = super.stdenv; };
} # // stdenv.overrides self super
)
@Pitometsu
Copy link
Author

Error:

$ nix-shell --pure --show-trace
trace: Use channel: /nix/store/fvsmig6qsr2dlkhsqw84fp6mmy8ydvv2-nixpkgs
error: while evaluating the attribute 'buildInputs' of the derivation 'nix-shell' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/build-support/mkshell/default.nix:28:3:
while evaluating the attribute 'buildInputs' of the derivation 'hbbft-0c6168c978df87d06075ce7d640c771b3a5bdbad' at /home/yuriypitomets/Projects/project/shell.nix:153:5:
while evaluating the attribute 'builder' of the derivation 'openssl-1.0.2s' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/development/libraries/openssl/default.nix:11:5:
while evaluating the attribute 'shell' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/generic/default.nix:103:14:
while evaluating the attribute 'gcc' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/linux/default.nix:290:7:
while evaluating 'makeOverridable' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/linux/default.nix:290:13:
while evaluating anonymous function at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:69:12:
while evaluating the attribute 'gcc-unwrapped' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/linux/default.nix:258:7:
while evaluating the attribute 'gcc-unwrapped.override' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7250:3:
while evaluating 'addMetaAttrs' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/meta.nix:15:28, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7398:10:
while evaluating 'wrapCC' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8207:12, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7398:19:
while evaluating 'wrapCCWith' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8186:5, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8207:16:
while evaluating 'callPackageWith' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:108:35, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8195:7:
while evaluating 'makeOverridable' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:112:8:
while evaluating anonymous function at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:69:12:
while evaluating the attribute 'cc.nativeTools' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/generic/default.nix:148:14:
while evaluating the attribute 'pkgs.gcc8' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7409:3:
while evaluating 'addMetaAttrs' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/meta.nix:15:28, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7409:10:
while evaluating 'wrapCC' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8207:12, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:7409:19:
while evaluating 'wrapCCWith' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8186:5, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8207:16:
while evaluating 'callPackageWith' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:108:35, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8195:7:
while evaluating 'makeOverridable' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:112:8:
while evaluating anonymous function at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/lib/customisation.nix:69:12:
while evaluating the attribute 'cc.nativeTools' at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/stdenv/generic/default.nix:148:14:
infinite recursion encountered, at /nix/store/ykrliwamzhvk1w446h4vry8wynzb9571-nixpkgs-19.09pre184803.d567c486ca5/nixpkgs/pkgs/top-level/all-packages.nix:8196:67

@Pitometsu
Copy link
Author

stdenv = super.buildPackages.gcc8Stdenv; didn't help =(

@Pitometsu
Copy link
Author

Looks like that work:

(self: super:
  let
    stdenv = let stdenv = super.overrideCC super.stdenv super.gcc8; in
             stdenv.override { cc = super.stdenv.cc; };
  in {
    inherit stdenv;
  })

@AleXoundOS
Copy link

AleXoundOS commented Nov 25, 2021

This awkward expression can be simplified to

self: super: {
  stdenv =
    (super.overrideCC super.stdenv super.gcc8).override
      { cc = super.stdenv.cc; };
}

Still, it's questionable whether it's the right way to override compiler.

@Pitometsu
Copy link
Author

@AleXoundOS nice, thank you for a reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment