Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 136 lines 4.2 kB view raw
1{ 2 callPackage, 3 lib, 4 stdenv, 5 fetchFromGitHub, 6 gitMinimal, 7 zsh, 8 zlib, 9 runtimeShell, 10}: 11stdenv.mkDerivation rec { 12 pname = "gitstatus"; 13 version = "1.5.5"; 14 15 src = fetchFromGitHub { 16 owner = "romkatv"; 17 repo = "gitstatus"; 18 rev = "v${version}"; 19 sha256 = "sha256-b+9bwJ87VV6rbOPobkwMkDXGH34STjYPlt8wCRR5tEc="; 20 }; 21 22 env.NIX_LDFLAGS = toString ( 23 [ 24 # required by libgit2.a 25 "-lz" 26 ] 27 ++ lib.optional stdenv.hostPlatform.isDarwin "-liconv" 28 ); 29 30 buildInputs = [ 31 zlib 32 (callPackage ./romkatv_libgit2.nix { }) 33 ]; 34 35 postPatch = '' 36 sed -i '1i GITSTATUS_AUTO_INSTALL=''${GITSTATUS_AUTO_INSTALL-0}' gitstatus.plugin.sh 37 sed -i '1i GITSTATUS_AUTO_INSTALL=''${GITSTATUS_AUTO_INSTALL-0}' gitstatus.plugin.zsh 38 sed -i "1a GITSTATUS_DAEMON=$out/bin/gitstatusd" install 39 ''; 40 41 installPhase = '' 42 install -Dm755 usrbin/gitstatusd $out/bin/gitstatusd 43 install -Dm444 gitstatus.plugin.sh -t $out/share/gitstatus/ 44 install -Dm444 gitstatus.plugin.zsh -t $out/share/gitstatus/ 45 install -Dm444 gitstatus.prompt.sh -t $out/share/gitstatus/ 46 install -Dm444 gitstatus.prompt.zsh -t $out/share/gitstatus/ 47 install -Dm555 install -t $out/share/gitstatus/ 48 install -Dm444 build.info -t $out/share/gitstatus/ 49 50 # the fallback path is wrong in the case of home-manager 51 # because the FHS directories don't start at / 52 substituteInPlace install \ 53 --replace "_gitstatus_install_main ." "_gitstatus_install_main $out" 54 55 cat <<EOF > $out/bin/gitstatus-share 56 #!${runtimeShell} 57 # Run this script to find the gitstatus shared folder where all the shell 58 # integration scripts are living. 59 echo $out/share/gitstatus 60 EOF 61 chmod +x $out/bin/gitstatus-share 62 ''; 63 64 # Don't install the "install" and "build.info" files, which the end user 65 # should not need to worry about. 66 pathsToLink = [ 67 "/bin/gitstatusd" 68 "/share/gitstatus/gitstatus.plugin.sh" 69 "/share/gitstatus/gitstatus.plugin.zsh" 70 "/share/gitstatus/gitstatus.prompt.sh" 71 "/share/gitstatus/gitstatus.prompt.zsh" 72 ]; 73 74 # The install check sets up an empty Git repository and a minimal zshrc that 75 # invokes gitstatus.plugin.zsh. It runs zsh against this zshrc and verifies 76 # that the script was sourced successfully and that the "gitstatus_query" 77 # command ran successfully. This tests the binary itself and the zsh 78 # integration. 79 nativeInstallCheckInputs = [ 80 gitMinimal 81 zsh 82 ]; 83 doInstallCheck = true; 84 installCheckPhase = '' 85 TEMP=$(mktemp -d) 86 cd "$TEMP" 87 88 git init 89 90 echo ' 91 GITSTATUS_LOG_LEVEL=DEBUG 92 . $out/share/gitstatus/gitstatus.plugin.zsh || exit 1 93 94 gitstatus_stop NIX_TEST && gitstatus_start NIX_TEST 95 gitstatus_query NIX_TEST 96 if [[ $? -ne 0 ]]; then 97 print -- "Something went wrong with gitstatus" 98 exit 1 99 elif [[ $VCS_STATUS_RESULT != "ok-sync" ]]; then 100 print -- "Not in a Git repo" 101 exit 1 102 else 103 print -- "OK" 104 exit 0 105 fi 106 ' > .zshrc 107 108 # If we try to run zsh like "zsh -i -c true" or "zsh -i > output" then job 109 # control will be disabled in the shell and the gitstatus plugin script 110 # will fail when it tries to set the MONITOR option. As a workaround, we 111 # run zsh as a full-fledged independent process and then wait for it to 112 # exit. (The "exit" statements in the zshrc ensure that zsh will exit 113 # almost immediately after starting.) 114 ZDOTDIR=. zsh -d -i & 115 wait $! 116 ''; 117 118 meta = with lib; { 119 description = "10x faster implementation of `git status` command"; 120 longDescription = '' 121 To enable the included gitstatus prompt, add the appropriate line to your NixOS configuration: 122 `programs.bash.promptInit = "source $(gitstatus-share)/gitstatus.prompt.sh";` 123 `programs.zsh.promptInit = "source $(gitstatus-share)/gitstatus.prompt.zsh";` 124 125 See the project homepage for details on customization. 126 ''; 127 homepage = "https://github.com/romkatv/gitstatus"; 128 license = licenses.gpl3Only; 129 maintainers = with maintainers; [ 130 mmlb 131 SuperSandro2000 132 ]; 133 platforms = platforms.all; 134 mainProgram = "gitstatusd"; 135 }; 136}