~kaction/config

0ad1a0c92310fc4c32a26ed8fff8c2693beef6cb — Dmitry Bogatov 3 months ago bd83900
Drop expressions to rebuild rev-deps of git

Now that I provision ~/.gitconfig with nix-sys and use stock git binary,
there is no longer need to rebuild its reverse dependencies.

Also drop universe/githooks derivation, since more flexible solution is
used now.
8 files changed, 0 insertions(+), 201 deletions(-)

M flake.nix
D universe/git-bug/default.nix
D universe/git/builder.bash
D universe/git/default.nix
D universe/githooks/build.py
D universe/githooks/default.nix
D universe/githooks/run-directory.c
D universe/githooks/run-parts.sh
M flake.nix => flake.nix +0 -5
@@ 74,12 74,8 @@
          fasm-arch = call ./universe/fasm-arch;
          firewall = call ./universe/firewall;

          git-bug = callPackage ./universe/git-bug {
            inherit (pkgs.gitAndTools) git-bug;
          };
          git-recall = call ./universe/git-recall;
          git-merge-pr = call ./universe/git-merge-pr;
          githooks = call ./universe/githooks;

          mk-runscript = call ./universe/mk-runscript;



@@ 93,7 89,6 @@
          srht-ui = call ./universe/srht-ui;
          selectors = call ./universe/selectors;
          scripts = call ./universe/scripts;
          git-crypt = pkgs.git-crypt.override { inherit (self') git; };

          passphrase2pgp = call ./universe/passphrase2pgp;
          posixrc = callPackage ./universe/posixrc { };

D universe/git-bug/default.nix => universe/git-bug/default.nix +0 -8
@@ 1,8 0,0 @@
{ git-bug }:
let
  stage1 = git-bug.overrideAttrs (_: {
    patchPhase = ''
      sed -i s,--global,--local,g repository/config_git.go
    '';
  });
in stage1

D universe/git/builder.bash => universe/git/builder.bash +0 -16
@@ 1,16 0,0 @@
#!/bin/bash -- source only
mkdir $out/config/git -p
cp -t $out -rs $git/*

chmod u+w $out/bin && unlink $out/bin/git

cat << EOF > $out/bin/git
#!${execline}/bin/execlineb -S0
export XDG_CONFIG_HOME $out/config
export FILTER_BRANCH_SQUELCH_WARNING 1
${blurdate}/bin/blurdate =hMs ${git}/bin/git \$@
EOF
chmod +x $out/bin/git

substituteAll $gitconfig $out/config/git/config
cp $gitignore $out/config/git/ignore

D universe/git/default.nix => universe/git/default.nix +0 -50
@@ 1,50 0,0 @@
{ git, writeScript, blurdate, perl, busybox, execline, runCommand, substituteAll, githooks }:
let
  stage1 = git.override {
    sendEmailSupport = true;
    coreutils = busybox;
    perlPackages = perl.pkgs;

    # Pure violence. git maintainer did not though about overrides hard
    # enough.
    #
    # Copied from pkgs/applications/version-management/git-and-tools.nix
    perlLibs = with perl.pkgs; [ LWP URI TermReadKey ];
    smtpPerlLibs = with perl.pkgs; [
      libnet
      NetSMTPSSL
      IOSocketSSL
      NetSSLeay
      AuthenSASL
      DigestHMAC
    ];
  };
  stage2 = stage1.overrideAttrs (old: {
    makeFlags = old.makeFlags ++ [ "SHELL_PATH=${busybox}/bin/sh" ];
    doInstallCheck = false;
  });
  stage3 = let
    env = {
      gitconfig = substituteAll {
        # This is tricky. Hooks scripts need git, and git includes
        # config which refers to hooks directory. Recursion.
        #
        # Here I break the loop by providing scripts with git that do
        # not have configuration embedded. This construction will
        # collapse when hook will need git for write operation and will
        # start complaining that user.name is not available.
        githooks = githooks.override { git = stage2; };
        logp = writeScript "logp" ''
          #!${execline}/bin/execlineb -WS0
          pipeline
            { git log -p --color=always --decorate=short $@ }
              less -R -p"^commit [0-9a-f]{40}"
        '';
        src = ./gitconfig.in;
      };
      gitignore = ./gitignore;
      git = stage2;
      inherit execline perl blurdate;
    };
  in runCommand git.name env "source ${./builder.bash}";
in stage3

D universe/githooks/build.py => universe/githooks/build.py +0 -20
@@ 1,20 0,0 @@
import os
import json

for key, value in os.environ.items():
    globals()[key] = value

hooks = json.loads(hooks)

for hook, scripts in hooks.items():
    os.makedirs(f"{out}/{hook}.d")
    for name, path in scripts.items():
        os.symlink(path, f"{out}/{hook}.d/{name}")
    with open(f"{out}/{hook}", "w") as fp:
        fp.write(f"""
#!{execline}/bin/execlineb -WS0
{rundir} {out}/{hook}.d $@
"""[1:])
    os.chmod(f"{out}/{hook}", 0o777)



D universe/githooks/default.nix => universe/githooks/default.nix +0 -52
@@ 1,52 0,0 @@
{ 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}";
}

D universe/githooks/run-directory.c => universe/githooks/run-directory.c +0 -34
@@ 1,34 0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	const char **args;
	const char *directory;
	int i;
	if (argc < 2) {
		fputs("usage: run-directory <directory> [ARGS ...]\n", stderr);
		return 1;
	}
	directory = argv[1];
	argv++;

	args = malloc(sizeof(char *) * (2 + argc * 2));
	if (!args) {
		fputs("fatal: malloc() failed", stderr);
		return 1;
	}

	i = 0;
	args[i++] = RUN_PARTS;
	while (*++argv) {
		args[i++] = "--arg";
		args[i++] = *argv;
	}
	args[i++] = "--";
	args[i++] = directory;
	args[i++] = NULL;

	return execvp(RUN_PARTS, (char *const *)args);
}

D universe/githooks/run-parts.sh => universe/githooks/run-parts.sh +0 -16
@@ 1,16 0,0 @@
#!@busybox@/bin/sh
set -eu
export PATH=@busybox@/bin
export LC_COLLATION=POSIX

directory=$1; shift
tempfile=$(mktemp)
cat > "${tempfile}"
cleanup() { rm -f "${tempfile}"; }
trap cleanup 0

for script in "${directory}"/* ; do
	if [ -x "${script}" ] && [ -f "${script}" ] ; then