~kaction/config

ref: bd83900251b2478f4863aa288b5c68d655e63eba config/universe/githooks/default.nix -rw-r--r-- 1.2 KiB
bd839002 — Dmitry Bogatov Recover git-logp script 4 months ago
                                                                                
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
43
44
45
46
47
48
49
50
51
52
{ stdenv, python3, writeScript, substituteAll, busybox, debianutils, lib, git
, git-bug, execline }:
let
  run-parts = stdenv.mkDerivation {
    name = "run-parts";
    src = debianutils;
    phases = [ "installPhase" ];
    installPhase = ''
      cp $src/bin/run-parts $out
    '';
  };

  # run-parts has brain-damaged interface for passing arguments to
  # script.
  rundir = stdenv.mkDerivation {
    name = "run-directory";
    src = ./run-directory.c;
    phases = [ "installPhase" ];
    installPhase = ''
      cc -D'RUN_PARTS="${run-parts}"' $src -o $out
    '';
  };

  make-shell = { path ? [ ] }:
    let
      path' = if builtins.isString path then
        path
      else
        lib.makeBinPath (path ++ [ busybox ]);
    in writeScript "busybox-shell" ''
      #!${execline}/bin/execlineb -WS0
      export PATH ${path'}
      ${busybox}/bin/sh $@
    '';

  hooks = {
    post-commit.git-bug = substituteAll {
      shell = make-shell { path = [ git git-bug ]; };
      src = ./post-commit/git-bug.sh;
      isExecutable = true;
    };
  };

in stdenv.mkDerivation {
  inherit execline rundir;

  name = "githooks";
  buildInputs = [ python3 ];
  phases = [ "installPhase" ];
  hooks = builtins.toJSON hooks;
  installPhase = "python3 ${./build.py}";
}