Great!
Maybe instead of depending on time, it could use `md5sum /proc/cpuinfo`
or something that identifies the machine?
I get the concepts but I'm very new to the nix language. How
would I modify an existing package to use this in my
~/.nixpkgs/config.nix ?
OK, well technically that is possible,
with something like this:
extra_cflags = import (pkgs.runCommand "cflags" {} ''
mkdir $out
echo "" | gcc -O3 -march=native -mtune=native -v -E - 2>&1
|grep cc1 |sed -r 's/.*? - -(.*)$/-\1/' > $out/flags
echo "builtins.readFile ./flags" > $out/default.nix
'');
Basically, what that does is build a derivation which creates a
nix _expression_, then imports that nix _expression_. One problem with
this is that the result is saved in the nix store, meaning if you
share nix stores between machines it won't work (because it will
run once on one machine and the same result will be used on
different machines). To get around this, you can make the
derivation depend on the current time, which will force it to
calculate the cflags every time you build something. Also, it's
possible that in the future builds run in chroot will be inside
namespaces that block how gcc detects the host system, so we
should make this not run in chroot:
extra_cflags = import (pkgs.runCommand "cflags" {time =
builtins.currentTime; __noChroot = true;} ''
mkdir $out
echo "" | gcc -O3 -march=native -mtune=native -v -E - 2>&1
|grep cc1 |sed -r 's/.*? - -(.*)$/-\1/' > $out/flags
echo "builtins.readFile ./flags" > $out/default.nix
'');
I'm not sure of your level of understanding of nix, so please let
me know if this needs more explanation.
Thanks,
Shea
On 02/07/2013 09:53 AM, Danny Wilson wrote:
Well in this case I am the
user. And I don't want to fill this in for every different server I
might have.
My suggestion was to make -march=native pure, by expanding it on the
system configuring itself at nix _expression_ evaluation time:
$ echo "" | gcc -O3 -march=native -mtune=native -v -E - 2>&1
|grep cc1 |sed -r 's/.*? - -(.*)$/-\1/'
-march=corei7 -mcx16 -msahf -mno-movbe -maes -mno-pclmul -mpopcnt
-mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mno-avx
-msse4.2 -msse4.1 --param l1-cache-size=32 --param
l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=generic -O3
Hi Danny,
Unfortunately, there's not a good answer to this because
-march=native is inherently impure. Is there any reason you can't
tell users "Find out what -march=native means on your system and
then fill in nixpkgs.config.extra_cflags with the result?" or some
such (Note that config.extra_cflags doesn't currently exist AFAIK,
but could)?
~Shea
On 02/07/2013 07:36 AM, Danny Wilson wrote:
With help of the gentoo
wiki (
http://en.gentoo-wiki.com/wiki/Hardware_CFLAGS
)
I found this produces a nice GCC option list:
echo "" | gcc -O3 -march=native -mtune=native -v -E - 2>&1 |grep
cc1 |sed -r 's/.*? - -(.*)$/-\1/'