]> git.immae.eu Git - perso/Immae/Config/Nix/NUR.git/blob - libs.nix
2ddfcbb59d48598cf8a82c0c8a42b3d45a0015b0
[perso/Immae/Config/Nix/NUR.git] / libs.nix
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 ./lib/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 = fetchgitPrivate json.git;
40 };
41
42 wrap = { paths ? [], vars ? {}, file ? null, script ? null, name ? "wrap" }:
43 assert file != null || script != null ||
44 abort "wrap needs 'file' or 'script' argument";
45 with rec {
46 set = n: v: "--set ${pkgs.lib.escapeShellArg n} " +
47 "${pkgs.lib.escapeShellArg v}";
48 args = (map (p: "--prefix PATH : ${p}/bin") paths) ++
49 (builtins.attrValues (pkgs.lib.mapAttrs set vars));
50 };
51 runCommand name
52 {
53 f = if file == null then writeScript name script else file;
54 buildInputs = [ makeWrapper ];
55 }
56 ''
57 makeWrapper "$f" "$out" ${toString args}
58 '';
59
60 # This adds header colors to the builds, but it rebuilds the whole
61 # world from scratch, so only use it to debug!
62 # add it as postHook in derivations
63 immaePostHook = ''
64 header() {
65 echo -ne "\033[1;36m"
66 echo -n "$1"
67 echo -e "\033[0m"
68 }
69
70 echoCmd() {
71 printf "\033[1;34m%s:\033[0m" "$1"
72 shift
73 printf ' %q' "$@"
74 echo
75 }
76 '';
77
78 } // (if builtins.pathExists ./lib/private then import ./lib/private else {})