Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 97 lines 2.7 kB view raw
1{ 2 buildGoModule, 3 fetchFromGitHub, 4 nix-update-script, 5 versionCheckHook, 6 7 lib, 8 makeWrapper, 9 xdg-utils, 10}: 11 12buildGoModule rec { 13 pname = "granted"; 14 version = "0.38.0"; 15 16 src = fetchFromGitHub { 17 owner = "common-fate"; 18 repo = "granted"; 19 rev = "v${version}"; 20 sha256 = "sha256-xHpYtHG0fJ/VvJ/4lJ90ept3yGzJRnmtFQFbYxJtxwY="; 21 }; 22 23 vendorHash = "sha256-Y8g5495IYgQ2lvq5qbnQmoxwEYfzzx12KfMS6wF2QXE="; 24 25 nativeBuildInputs = [ makeWrapper ]; 26 27 ldflags = [ 28 "-s" 29 "-w" 30 "-X github.com/common-fate/granted/internal/build.Version=v${version}" 31 "-X github.com/common-fate/granted/internal/build.Commit=${src.rev}" 32 "-X github.com/common-fate/granted/internal/build.Date=1970-01-01-00:00:01" 33 "-X github.com/common-fate/granted/internal/build.BuiltBy=Nix" 34 "-X github.com/common-fate/granted/internal/build.ConfigFolderName=.granted" 35 ]; 36 37 subPackages = [ 38 "cmd/granted" 39 ]; 40 41 postInstall = 42 let 43 # assume depends on assumego, so we add (placeholder "out") to its path 44 addToAssumePath = lib.makeBinPath [ 45 xdg-utils 46 (placeholder "out") 47 ]; 48 in 49 '' 50 ln -s $out/bin/granted $out/bin/assumego 51 52 # Create script with correct permissions 53 install -Dm755 /dev/null $out/bin/assume 54 55 # assume is a script that must be sourced 56 # We can't wrap it because it inspects $0 and calls return, which can only 57 # be done in sourced scripts. 58 # So instead we insert the following snippet into the beginning of the 59 # script to add to PATH. 60 # This is borrowed from wrapProgram --suffix PATH : 61 addToPath="$(cat << 'EOF' 62 63 PATH=''${PATH:+':'$PATH':'} 64 if [[ $PATH != *':'''${addToAssumePath}''':'* ]]; then 65 PATH=$PATH'${addToAssumePath}' 66 fi 67 PATH=''${PATH#':'} 68 PATH=''${PATH%':'} 69 export PATH 70 71 EOF 72 )" 73 74 # Insert below the #!/bin/sh shebang 75 echo "$addToPath" | sed "/#!\/bin\/sh/r /dev/stdin" $src/scripts/assume >> $out/bin/assume 76 77 # Install fish script 78 install -Dm755 $src/scripts/assume.fish $out/share/assume.fish 79 substituteInPlace $out/share/assume.fish \ 80 --replace-fail "#!/bin/fish" "#!/usr/bin/env fish" 81 ''; 82 83 nativeInstallCheckInputs = [ versionCheckHook ]; 84 doInstallCheck = true; 85 86 passthru.updateScript = nix-update-script { }; 87 88 meta = { 89 description = "Easiest way to access your cloud"; 90 homepage = "https://github.com/common-fate/granted"; 91 changelog = "https://github.com/common-fate/granted/releases/tag/${version}"; 92 license = lib.licenses.mit; 93 maintainers = with lib.maintainers; [ 94 jlbribeiro 95 ]; 96 }; 97}