base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / gr / granted / package.nix
bloba105ffedf71bdefbd86f9971918648404062afda
2   bash,
3   buildGoModule,
4   fetchFromGitHub,
5   nix-update-script,
6   versionCheckHook,
8   withFish ? false,
9   fish,
11   lib,
12   makeWrapper,
13   xdg-utils,
16 buildGoModule rec {
17   pname = "granted";
18   version = "0.36.1";
20   src = fetchFromGitHub {
21     owner = "common-fate";
22     repo = pname;
23     rev = "v${version}";
24     sha256 = "sha256-sIn6D0696QPo4fs7HzvQNIopIfYYV4fYLmVdwQZnZag=";
25   };
27   vendorHash = "sha256-QswW1PyxrVWf6ZAPKW69q0JIXpyhSHucE5A7hkr8uxw=";
29   nativeBuildInputs = [ makeWrapper ];
31   ldflags = [
32     "-s"
33     "-w"
34     "-X github.com/common-fate/granted/internal/build.Version=v${version}"
35     "-X github.com/common-fate/granted/internal/build.Commit=${src.rev}"
36     "-X github.com/common-fate/granted/internal/build.Date=1970-01-01-00:00:01"
37     "-X github.com/common-fate/granted/internal/build.BuiltBy=Nix"
38   ];
40   subPackages = [
41     "cmd/granted"
42   ];
44   postInstall =
45     let
46       # assume depends on assumego, so we add (placeholder "out") to its path
47       addToAssumePath = lib.makeBinPath [
48         xdg-utils
49         (placeholder "out")
50       ];
51     in
52     ''
53       ln -s $out/bin/granted $out/bin/assumego
55       # Create script with correct permissions
56       install -Dm755 /dev/null $out/bin/assume
58       # assume is a script that must be sourced
59       # We can't wrap it because it inspects $0 and calls return, which can only
60       # be done in sourced scripts.
61       # So instead we insert the following snippet into the beginning of the
62       # script to add to PATH.
63       # This is borrowed from wrapProgram --suffix PATH :
64       addToPath="$(cat << 'EOF'
66       PATH=''${PATH:+':'$PATH':'}
67       if [[ $PATH != *':'''${addToAssumePath}''':'* ]]; then
68           PATH=$PATH'${addToAssumePath}'
69       fi
70       PATH=''${PATH#':'}
71       PATH=''${PATH%':'}
72       export PATH
74       EOF
75       )"
77       # Insert below the #!/bin/sh shebang
78       echo "$addToPath" | sed "/#!\/bin\/sh/r /dev/stdin" $src/scripts/assume >> $out/bin/assume
79     ''
80     + lib.optionalString withFish ''
81       # Install fish script
82       install -Dm755 $src/scripts/assume.fish $out/share/assume.fish
83       substituteInPlace $out/share/assume.fish \
84         --replace /bin/fish ${fish}/bin/fish
85     '';
87   nativeInstallCheckInputs = [ versionCheckHook ];
88   doInstallCheck = true;
90   passthru.updateScript = nix-update-script { };
92   meta = with lib; {
93     description = "Easiest way to access your cloud";
94     homepage = "https://github.com/common-fate/granted";
95     changelog = "https://github.com/common-fate/granted/releases/tag/${version}";
96     license = licenses.mit;
97     maintainers = with maintainers; [
98       jlbribeiro
99     ];
100   };