Hello all,
I need to build a project using GCC9.3 which I would like to build from source (as a learning exercise).
Following is the closest I was able to get to a solution, but the build fails.
Would anyone be willing to take a look and show me the Nix way to do this?
{
description = "";
inputs.nixpkgs.url = github:NixOS/nixpkgs?ref=ddb3455e152edb633e171d51a5c1f12ae8d22641;
outputs = {self, nixpkgs, ...}:
{
packages."x86_64-linux" = with nixpkgs.legacyPackages."x86_64-linux"; {
default = stdenv.mkDerivation {
pname = "foo";
version = "0.1.0";
src = ./src;
nativeBuildInputs = [
(gcc.cc.overrideAttrs (old: {
version = "9.3.0";
src = builtins.fetchTarball {
url = "https://github.com/gcc-mirror/gcc/archive/refs/tags/releases/gcc-9.3.0.tar.gz";
sha256 = "0ahcsg4ymfxar9g8i3r5akmhpnswfdxfd9cpr4bar0zdza08xdym";
};
}))
];
buildPhase = ''
echo $(g++ --version)
g++ -o foo foo.cpp
'';
installPhase = ''
mkdir -p $out/bin
cp foo $out/bin
'';
};
};
};
}
Following is the error I get when building Gcc
$CPATH is `/nix/store/5604wq5idbgniqchzal2pjmjgv9ns1kb-zlib-1.2.13-dev/include'
$LIBRARY_PATH is `/nix/store/37a5krk4a1a8vhl93q2bm9nbv8hymyii-zlib-1.2.13/lib'
/nix/store/qr60k7sz61hvv2baadlfv5qjr8q7vlg6-builder.sh: line 40: /nix/store/9sz03jz5kjgsvwkws2vzb0qq23dfgjhl-binutils-patchelfed-ld-wrapper-2.40/nix-support/libc-ldflags-before: No such file or directory
/nix/store/qr60k7sz61hvv2baadlfv5qjr8q7vlg6-builder.sh: line 40: /nix/store/9sz03jz5kjgsvwkws2vzb0qq23dfgjhl-binutils-patchelfed-ld-wrapper-2.40/nix-support/libc-ldflags-before: No such file or directory
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/dsf3x5giy4z5clmw4f1h35pfg4gmpv6c-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
applying patch /nix/store/9577hmdlmhki67cg8ar85cvidyg7xr7p-gcc-12-no-sys-dirs.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a/gcc/cppdefault.cc 2013-01-10 21:38:27.000000000 +0100
|+++ b/gcc/cppdefault.cc 2014-08-18 16:20:32.893944536 +0200
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 14
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- a/gcc/gcc.cc 2014-03-23 12:30:57.000000000 +0100
|+++ b/gcc/gcc.cc 2014-08-18 13:19:32.689201690 +0200
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
The source is fairly simple cpp which just spits out a string in the terminal.
Any help on this would be really appreciated!
Cheers,
Bhavesh.