I’m trying to build my system from source with global CFLAGS. with this overlay:
(
self: super: {
.
.
.
stdenv = super.stdenv // {
mkDerivation = args: super.stdenv.mkDerivation (
args // {
NIX_CFLAGS_COMPILE = toString (args.NIX_CFLAGS_COMPILE or "") + " -pipe - march=skylake -O3";
}
);
};
.
.
.
}
)
It works for most things, but go fails tests with O3. I can get around this for adding go to system packages by overriding go’s NIX_CFLAGS_COMPILE attribute within the same overlay
(
self: super: {
.
.
.
go = super.go.overrideAttrs (
oldAttrs: {
NIX_CFLAGS_COMPILE = " -pipe -march=skylake";
}
);
.
.
.
}
)
But that doesn’t seem to be enough for packages that are built using buildGoPackage
. In its inputDrvs I see another derivation of go that still has NIX_CFLAGS_COMPILE = " -pipe - march=skylake -O3"
.
What’s the best way to make sure things built using buildGoPackage don’t have O3 enabled in the go it uses in its inputDrvs?
overriding go in the overlay as shown above results in two different go packages showing up in the inputDrvs of docker
docker drv:
go drv with O3:
go drv without O3:
One of these has NIX_CFLAGS_COMPILE = " -pipe -march=skylake"
as per the go package overlay, while the other has "NIX_CFLAGS_COMPILE": " -pipe -march=skylake -O3"
. I don’t under why the docker derivation is getting both even though go’s flags have been modified by the overlay.
After a lot of digging around, I found that buildGoPackage
is defined in all-packages.nix:1603 as buildGoPackage = buildGo115Package;
and
buildGo114Package = callPackage ../development/go-packages/generic {
go = buildPackages.go_1_14;
};
buildGo115Package = callPackage ../development/go-packages/generic {
go = buildPackages.go_1_15;
};
In addition to the go package overlay, go_1_15
and go_1_14
had to have their NIX_CFLAGS_COMPILE overridden.
This makes most golang based packages (like prometheus) work, but docker still fails because of some other error.
This time the issue is with docker-runc:
nix-store -r /nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv
these derivations will be built:
/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv
building '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' on 'ssh://192.168.1.27'...
unpacking sources
unpacking source archive /nix/store/b4rd7610n606hkcppzf4sr4awh1c7iq9-source
source root is source
patching sources
configuring
building
patching script interpreter paths in .
./script/tmpmount: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./script/check-config.sh: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./script/validate-gofmt: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./script/validate-c: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./script/release.sh: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./tests/rootless.sh: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
./man/md2man-all.sh: interpreter directive changed from "/bin/bash" to "/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash"
/nix/store/v1q6wkhxbyfw77qn7h4s3dspwz0q2mjw-bash-4.4-p23/bin/bash: git: command not found
go build -buildmode=pie -ldflags "-X main.gitCommit="" -X main.version=1.0.0-rc10 " -tags "seccomp apparmor selinux" -o runc .
# github.com/opencontainers/runc/vendor/github.com/seccomp/libseccomp-golang
cgo-dwarf-inference:2:8: error: enumerator value for '__cgo_enum__0' is not an integer constant
cgo-dwarf-inference:4:8: error: enumerator value for '__cgo_enum__1' is not an integer constant
cgo-dwarf-inference:6:8: error: enumerator value for '__cgo_enum__2' is not an integer constant
cgo-dwarf-inference:8:8: error: enumerator value for '__cgo_enum__3' is not an integer constant
cgo-dwarf-inference:10:8: error: enumerator value for '__cgo_enum__4' is not an integer constant
cgo-dwarf-inference:12:8: error: enumerator value for '__cgo_enum__5' is not an integer constant
cgo-dwarf-inference:14:8: error: enumerator value for '__cgo_enum__6' is not an integer constant
cgo-dwarf-inference:16:8: error: enumerator value for '__cgo_enum__7' is not an integer constant
cgo-dwarf-inference:18:8: error: enumerator value for '__cgo_enum__8' is not an integer constant
cgo-dwarf-inference:20:8: error: enumerator value for '__cgo_enum__9' is not an integer constant
cgo-dwarf-inference:22:8: error: enumerator value for '__cgo_enum__10' is not an integer constant
cgo-dwarf-inference:24:8: error: enumerator value for '__cgo_enum__11' is not an integer constant
cgo-dwarf-inference:26:8: error: enumerator value for '__cgo_enum__12' is not an integer constant
cgo-dwarf-inference:28:8: error: enumerator value for '__cgo_enum__13' is not an integer constant
cgo-dwarf-inference:30:8: error: enumerator value for '__cgo_enum__14' is not an integer constant
cgo-dwarf-inference:32:8: error: enumerator value for '__cgo_enum__15' is not an integer constant
cgo-dwarf-inference:34:8: error: enumerator value for '__cgo_enum__16' is not an integer constant
cgo-dwarf-inference:36:8: error: enumerator value for '__cgo_enum__17' is not an integer constant
cgo-dwarf-inference:38:8: error: enumerator value for '__cgo_enum__18' is not an integer constant
cgo-dwarf-inference:40:8: error: enumerator value for '__cgo_enum__19' is not an integer constant
cgo-dwarf-inference:42:8: error: enumerator value for '__cgo_enum__20' is not an integer constant
cgo-dwarf-inference:44:8: error: enumerator value for '__cgo_enum__21' is not an integer constant
cgo-dwarf-inference:46:8: error: enumerator value for '__cgo_enum__22' is not an integer constant
cgo-dwarf-inference:48:8: error: enumerator value for '__cgo_enum__23' is not an integer constant
cgo-dwarf-inference:50:8: error: enumerator value for '__cgo_enum__24' is not an integer constant
cgo-dwarf-inference:52:8: error: enumerator value for '__cgo_enum__25' is not an integer constant
cgo-dwarf-inference:54:8: error: enumerator value for '__cgo_enum__26' is not an integer constant
cgo-dwarf-inference:56:8: error: enumerator value for '__cgo_enum__27' is not an integer constant
cgo-dwarf-inference:58:8: error: enumerator value for '__cgo_enum__28' is not an integer constant
cgo-dwarf-inference:60:8: error: enumerator value for '__cgo_enum__29' is not an integer constant
cgo-dwarf-inference:62:8: error: enumerator value for '__cgo_enum__30' is not an integer constant
cgo-dwarf-inference:64:8: error: enumerator value for '__cgo_enum__31' is not an integer constant
cgo-dwarf-inference:66:8: error: enumerator value for '__cgo_enum__32' is not an integer constant
cgo-dwarf-inference:68:8: error: enumerator value for '__cgo_enum__33' is not an integer constant
cgo-dwarf-inference:70:8: error: enumerator value for '__cgo_enum__34' is not an integer constant
cgo-dwarf-inference:72:8: error: enumerator value for '__cgo_enum__35' is not an integer constant
make: *** [Makefile:34: runc] Error 2
builder for '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' failed with exit code 2
error: build of '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' on 'ssh://192.168.1.27' failed: builder for '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' failed with exit code 2
builder for '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' failed with exit code 1
error: build of '/nix/store/czqya8hl326s699sif2da8r2j4wf72ay-docker-runc-19.03.12.drv' failed
I tried the same old trick to override NIX_CFLAGS_COMPILE
for docker-runc in the overlay, but that does not seem to reflect in the docker-runc derivation.
probably unrelated, i presume it needs git and not finding it… probably a red herring?
Yes, git had nothing to do with it. I got it working by overriding cflags for runc (not docker-runc).
Here’s the overlay I ended up with. Both docker and prometheus work. I didn’t test any other go based applications. I’m not sure if this is the best way of doing this.
Now I’m running into some issues with qt5 when trying to install pass, but that is outside the scope of this thread.
The whole overriding stuff seems quite a dark art to it, maybe someone here can give you the ‘best’ way’ to do it. With nix there are usually many ways to solve a problem , and none of them are the. ‘standard/best’ way. Hopefully you can write up your results for others to learn from soon.
It’s on my list to take a spin of yocto linux, which can perform magic like this…but how hard is to perform this recompilation magic remains to be seen.
Good Luck and thanks for sharing your solutions…