Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ bash, stdenv, lib, runCommand, writeText, fetchFromGitHub }: 2let 3 version = "1.0.0"; 4 5 shab = stdenv.mkDerivation { 6 pname = "shab"; 7 inherit version; 8 9 src = fetchFromGitHub { 10 owner = "zimbatm"; 11 repo = "shab"; 12 rev = "v${version}"; 13 sha256 = "02lf1s6plhhcfyj9xha44wij9jbphb1x5q55xj3b5bx2ji2jsvji"; 14 }; 15 16 postPatch = '' 17 for f in test.sh test/*.sh; do 18 patchShebangs "$f" 19 done 20 ''; 21 22 doCheck = true; 23 doInstallCheck = true; 24 25 checkPhase = '' 26 ./test.sh 27 ''; 28 29 installPhase = '' 30 mkdir -p $out/bin 31 cp ./shab $out/bin/shab 32 ''; 33 34 installCheckPhase = '' 35 [[ "$(echo 'Hello $entity' | entity=world $out/bin/shab)" == 'Hello world' ]] 36 ''; 37 38 passthru = { 39 inherit render renderText; 40 }; 41 42 meta = with lib; { 43 description = "The bash templating language"; 44 homepage = "https://github.com/zimbatm/shab"; 45 license = licenses.unlicense; 46 maintainers = with maintainers; [ zimbatm ]; 47 platforms = bash.meta.platforms; 48 }; 49 }; 50 51 /* 52 shabScript: a path or filename to use as a template 53 parameters.name: the name to use as part of the store path 54 parameters: variables to expose to the template 55 */ 56 render = shabScript: parameters: 57 let extraParams = { 58 inherit shabScript; 59 }; 60 in runCommand "out" (parameters // extraParams) '' 61 ${shab}/bin/shab "$shabScript" >$out 62 ''; 63 64 /* 65 shabScriptText: a string to use as a template 66 parameters.name: the name to use as part of the store path 67 parameters: variables to expose to the template 68 */ 69 renderText = shabScriptText: parameters: 70 render (writeText "template" shabScriptText) parameters; 71 72in 73 shab