diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 00000000..1baee1f5 --- /dev/null +++ b/lib/default.nix | |||
@@ -0,0 +1,82 @@ | |||
1 | { pkgs }: | ||
2 | with pkgs; | ||
3 | rec { | ||
4 | yarn2nixPackage = let | ||
5 | src = builtins.fetchGit { | ||
6 | url = "git://github.com/moretea/yarn2nix.git"; | ||
7 | ref = "master"; | ||
8 | rev = "780e33a07fd821e09ab5b05223ddb4ca15ac663f"; | ||
9 | }; | ||
10 | in | ||
11 | (callPackage src {}) // { inherit src; }; | ||
12 | |||
13 | nodeEnv = import ./node-env.nix; | ||
14 | |||
15 | fetchedGithub = path: | ||
16 | let | ||
17 | json = lib.importJSON path; | ||
18 | in rec { | ||
19 | version = json.tag; | ||
20 | name = "${json.meta.name}-${version}"; | ||
21 | src = fetchFromGitHub json.github; | ||
22 | }; | ||
23 | |||
24 | fetchedGit = path: | ||
25 | let | ||
26 | json = lib.importJSON path; | ||
27 | in rec { | ||
28 | version = json.tag; | ||
29 | name = "${json.meta.name}-${version}"; | ||
30 | src = fetchgit json.git; | ||
31 | }; | ||
32 | |||
33 | fetchedGitPrivate = path: | ||
34 | let | ||
35 | json = lib.importJSON path; | ||
36 | in rec { | ||
37 | version = json.tag; | ||
38 | name = "${json.meta.name}-${version}"; | ||
39 | src = builtins.fetchGit { | ||
40 | url = json.git.url; | ||
41 | ref = "master"; | ||
42 | rev = json.git.rev; | ||
43 | }; | ||
44 | }; | ||
45 | |||
46 | wrap = { paths ? [], vars ? {}, file ? null, script ? null, name ? "wrap" }: | ||
47 | assert file != null || script != null || | ||
48 | abort "wrap needs 'file' or 'script' argument"; | ||
49 | with rec { | ||
50 | set = n: v: "--set ${pkgs.lib.escapeShellArg n} " + | ||
51 | "${pkgs.lib.escapeShellArg v}"; | ||
52 | args = (map (p: "--prefix PATH : ${p}/bin") paths) ++ | ||
53 | (builtins.attrValues (pkgs.lib.mapAttrs set vars)); | ||
54 | }; | ||
55 | runCommand name | ||
56 | { | ||
57 | f = if file == null then writeScript name script else file; | ||
58 | buildInputs = [ makeWrapper ]; | ||
59 | } | ||
60 | '' | ||
61 | makeWrapper "$f" "$out" ${toString args} | ||
62 | ''; | ||
63 | |||
64 | # This adds header colors to the builds, but it rebuilds the whole | ||
65 | # world from scratch, so only use it to debug! | ||
66 | # add it as postHook in derivations | ||
67 | immaePostHook = '' | ||
68 | header() { | ||
69 | echo -ne "\033[1;36m" | ||
70 | echo -n "$1" | ||
71 | echo -e "\033[0m" | ||
72 | } | ||
73 | |||
74 | echoCmd() { | ||
75 | printf "\033[1;34m%s:\033[0m" "$1" | ||
76 | shift | ||
77 | printf ' %q' "$@" | ||
78 | echo | ||
79 | } | ||
80 | ''; | ||
81 | |||
82 | } // (if builtins.pathExists ./lib/private then import ./lib/private else {}) | ||