aboutsummaryrefslogtreecommitdiff
path: root/stdenv.nix
blob: 607ed76e7d667980562dc390caf140fd94022233 (plain) (blame)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
{ bash
, writeTextFile
, ...
}:

rec {

  mkDerivations = x: derivations (spread (removeAttrs x [ "variations" ]) x.variations);

  spread = x: ys: map (y: x // y) ys;

  addDefaults =
    let
      opt = x: a: if builtins.hasAttr a x then builtins.getAttr a x else "";

      res = x: defaults x // x;

      buildScript = x: writeTextFile {
        name = "build_script.sh";
        executable = true;
        text = ''
          ${opt (res x) "unpack"}
          ${opt (res x) "build"}
          ${opt (res x) "check"}
          ${opt (res x) "install"}
          ${opt (res x) "checkInstall"}
        '';
      };

      defaults = x: {
        name = "${x.pname}-${x.version}";
        system = builtins.currentSystem;
        builder = "${bash}/bin/bash";
        args = [ "-e" (buildScript x) ];
      };
    in res;

  derivations = map (x: derivation (addDefaults x));

  attrMap = f: builtins.foldl' (x: y: x // f y) {};
  attrMap' = f: xs: builtins.listToAttrs (map f xs);
}