aboutsummaryrefslogtreecommitdiff
path: root/nix/utils.nix
blob: 9848a785ebe6403b36c4d47468cdf37044cc2c7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{ pkgs, ... }:
# https://stackoverflow.com/questions/42136197/how-to-override-compile-flags-for-a-single-package-in-nixos
let
  overrideWithFlags = pkg: flags:
    pkgs.lib.overrideDerivation pkg (old:
      let
        newflags = pkgs.lib.foldl' (acc: x: "${acc} ${x}") "" flags;
        oldflags = if (pkgs.lib.hasAttr "NIX_CFLAGS_COMPILE" old)
                   then "${old.NIX_CFLAGS_COMPILE}"
                   else "";
      in
        {
          NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}";
        });
in
{
  overrideWithFlags = overrideWithFlags;
  optimizeForThisHost = pkg:
    overrideWithFlags pkg [ "-O3" "-march=native" "-fPIC" ];

  withDebugSymbols = pkg:
    overrideWithFlags pkg [ "-DDEBUG" ];

  importDirs = path: with builtins;
    map (n: import (path + ("/" + n)))
      (filter (n: match ".*\\.nix" n != null ||
                  pathExists (path + ("/" + n + "/default.nix")))
        (attrNames (readDir path)));
}