Using a different GCC for a specific package and all its dependencies

731 views
Skip to first unread message

Ashley Gillman

unread,
Jan 11, 2018, 9:40:48 PM1/11/18
to nix-devel
Hi,

Can anyone provide a recommendation as to the best way to change the GCC version for a specific package? I.e., I was to use the channel default GCC for almost everything, but I have specific projects that require older GCC versions.

Previously I was doing it like this:

...
    stdenvGCC49
= pkgs.overrideCC mypkgs.stdenv mypkgs.gcc49;

    milxview
= callPackage ../imaging/libraries/milxview {
     
# Use gcc 4.9
      stdenv
= stdenvGCC49;
      boost
= mypkgs.boost.override { stdenv = stdenvGCC49; };
   
};
...



But I have recently moved from the 17.04 channel to 17.09, and it now seems that I am having to specify all of a package's C++ dependencies to use the modified stdenv.

I assume there should be a better way to do this?

Thanks for any help,
Ash

Peter Hoeg

unread,
Jan 12, 2018, 12:39:31 AM1/12/18
to Ashley Gillman, nix-devel
Hi Ash,

> Can anyone provide a recommendation as to the best way to change the GCC
> version for a specific package? I.e., I was to use the channel default GCC

I'm not sure if this is the right way, but this is how I do it:

wmi = callPackage ../tools/networking/wmi {
# it doesn't compile with gcc >= 4.8 due to a change in how functions are inlined
stdenv = overrideCC stdenv gcc45;
};

--
Regards,
Peter

Ashley Gillman

unread,
Jan 12, 2018, 12:58:01 AM1/12/18
to nix-devel
Thanks Peter,

This is essentially what I am doing. But the problem is that the dependencies weren't build with the right GCC, and I seem to be going down a rabbit hole:


    milxview = callPackage ../imaging/libraries/milxview {
      # Use gcc 4.9
      stdenv = stdenvGCC49;
      boost = mypkgs.boost.override { stdenv = stdenvGCC49; };
      wxGTK = mypkgs.wxGTK.override { stdenv = stdenvGCC49; };
      glew = mypkgs.glew.override {
        stdenv = stdenvGCC49;
        mesa_glu = mypkgs.mesa_glu.override {
          stdenv = stdenvGCC49;
        };
      };
      # libsigc++ >= 2.5 requires C++11
      libsigcxx = mypkgs.libsigcxx.override {
        stdenv = stdenvGCC49; majorVersion = "2.4"; minorVersion = "1";
        sha256 = "1v0rvkzglzmf67y9nkcppwjwi68j1cy5yhldvcq7xrv8594l612l";
      };
      # use VTK 5
      vtkWithQt4 = mypkgs.vtkWithQt4.override {
        majorVersion = "5.10"; minorVersion = "1";
        sha256 = "1fxxgsa7967gdphkl07lbfr6dcbq9a72z5kynlklxn7hyp0l18pi";
        stdenv = stdenvGCC49;
        pythonPackages = null;
        #extraCmakeFlags = ["-DVTK_USE_ANSI_STDLIB=ON"];
        #cmake = mypkgs.cmake_2_8;
      };
    };

Ashley Gillman

unread,
Jan 14, 2018, 8:38:25 PM1/14/18
to nix-devel
I thought maybe I could create a custom pkgs tree (pkgsGCC49) with a replaced stdenv, but my approach isn't doing what I intended.

  let
    stdenvGCC49 = pkgs.overrideCC pkgs.stdenv pkgs.gcc49;
    pkgsGCC49 = pkgs // { stdenv = stdenvGCC49; };
    callPackageGCC49 = pkgs.lib.callPackageWith pkgsGCC49;

  in
    callPackageGCC49 ../imaging/libraries/milxview {};


The dependencies are still all being built with GCC 6.4.0

zimbatm

unread,
Jan 16, 2018, 3:48:55 AM1/16/18
to Ashley Gillman, nix-devel

Hi Ashley,

It's because the pkgs.stdenv is replaced in the attribute set but the original one has already been passed to all the packages. Using an overlay will properly apply the change recursively (typing on mobile so no example for you :)

I think that your original method never really worked, you were lucky enough that both GCC versions were producing compatible results.


--
You received this message because you are subscribed to the Google Groups "nix-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nix-devel+...@googlegroups.com.
To post to this group, send email to nix-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nix-devel/fde1796c-27db-4df1-9598-2c92480a9acb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashley Gillman

unread,
Jan 16, 2018, 5:43:17 AM1/16/18
to nix-devel
Thank you. Yes, I have slowly begun a method with overlays, still with some issues but seems to fundamentally work.

A related question, can you apply an overlay to an already imported pkgs? My current technique re-imports <nixpks>.

Thanks, Ash

--

Sent from my mobile. Please excuse brevity and any spelling mistakes.

Ashley Gillman

zimbatm

unread,
Jan 16, 2018, 12:05:53 PM1/16/18
to Ashley Gillman, nix-devel
On Tue, 16 Jan 2018 at 10:43 Ashley Gillman <gillm...@gmail.com> wrote:
A related question, can you apply an overlay to an already imported pkgs? My current technique re-imports <nixpks>.

I don't think so, the issue is not the import but the function call happening afterwards.

    let
      nixpkgsFn = import <nixpkgs>;
      # first instance
      pkgs = nixpkgsFn { config = {}; overlays = []; };
      # second instance
      pkgsWithGCC49 = nixpkgsFn {
        config = {};
        overlays = [(self: super: with super; {
          stdenv = overrideCC stdenv gcc49;
        })];
      };
    in
      pkgsWithGCC49;
 
Reply all
Reply to author
Forward
0 new messages