Snippets: Difference between revisions
imported>Makefu syntaxHighlight |
imported>Samueldr m toc |
||
Line 1: | Line 1: | ||
__TOC__ | |||
This page contains some nix script snippets which might be useful. | This page contains some nix script snippets which might be useful. | ||
Latest revision as of 19:16, 7 June 2018
This page contains some nix script snippets which might be useful.
Adding compiler flags to a package
optimizeWithFlag = pkg: flag:
pkg.overrideAttrs (attrs: {
NIX_CFLAGS_COMPILE = (attrs.NIX_CFLAGS_COMPILE or "") + " ${flag}";
});
This function can further be used to define the following helpers:
optimizeWithFlags = pkg: flags: pkgs.lib.foldl' (pkg: flag: optimizeWithFlag pkg flag) pkg flags;
optimizeForThisHost = pkg: optimizeWithFlags pkg [ "-O3" "-march=native" "-fPIC" ];
withDebuggingCompiled = pkg: optimizeWithFlag pkg "-DDEBUG";
Overriding callPackage for finding updated upstream packages in own overrides
With this override for the `callPackage` function, one can automatically detect if the upstream package set has a newer version of an locally overridden package:
callPackage = path: args: let
override = super.callPackage path args;
upstream = optionalAttrs (override ? "name")
(super.${(parseDrvName override.name).name} or {});
in if upstream ? "name" &&
override ? "name" &&
compareVersions upstream.name override.name != -1
then
trace
"Upstream `${upstream.name}' gets overridden by `${override.name}'."
override
else override;