mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-03 13:30:36 +00:00
98 lines
2.7 KiB
Nix
98 lines
2.7 KiB
Nix
{
|
|
buildGoModule,
|
|
fetchFromGitHub,
|
|
nix-update-script,
|
|
versionCheckHook,
|
|
|
|
lib,
|
|
makeWrapper,
|
|
xdg-utils,
|
|
}:
|
|
|
|
buildGoModule (finalAttrs: {
|
|
pname = "granted";
|
|
version = "0.39.0";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "fwdcloudsec";
|
|
repo = "granted";
|
|
tag = "v${finalAttrs.version}";
|
|
sha256 = "sha256-/5JP6laC+k+O8GWSl1eo0slqzYzYB86UF3irDX6Z0iQ=";
|
|
};
|
|
|
|
vendorHash = "sha256-L96zj/AEUze/SfuFeK+I1+w2zXcxr5BSW3wGQFbTbJU=";
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
ldflags = [
|
|
"-s"
|
|
"-w"
|
|
"-X github.com/fwdcloudsec/granted/internal/build.Version=v${finalAttrs.version}"
|
|
"-X github.com/fwdcloudsec/granted/internal/build.Commit=${finalAttrs.src.rev}"
|
|
"-X github.com/fwdcloudsec/granted/internal/build.Date=1970-01-01-00:00:01"
|
|
"-X github.com/fwdcloudsec/granted/internal/build.BuiltBy=Nix"
|
|
"-X github.com/fwdcloudsec/granted/internal/build.ConfigFolderName=.granted"
|
|
];
|
|
|
|
subPackages = [
|
|
"cmd/granted"
|
|
];
|
|
|
|
postInstall =
|
|
let
|
|
# assume depends on assumego, so we add (placeholder "out") to its path
|
|
addToAssumePath = lib.makeBinPath [
|
|
xdg-utils
|
|
(placeholder "out")
|
|
];
|
|
in
|
|
''
|
|
ln -s $out/bin/granted $out/bin/assumego
|
|
|
|
# Create script with correct permissions
|
|
install -Dm755 /dev/null $out/bin/assume
|
|
|
|
# assume is a script that must be sourced
|
|
# We can't wrap it because it inspects $0 and calls return, which can only
|
|
# be done in sourced scripts.
|
|
# So instead we insert the following snippet into the beginning of the
|
|
# script to add to PATH.
|
|
# This is borrowed from wrapProgram --suffix PATH :
|
|
addToPath="$(cat << 'EOF'
|
|
|
|
PATH=''${PATH:+':'$PATH':'}
|
|
if [[ $PATH != *':'''${addToAssumePath}''':'* ]]; then
|
|
PATH=$PATH'${addToAssumePath}'
|
|
fi
|
|
PATH=''${PATH#':'}
|
|
PATH=''${PATH%':'}
|
|
export PATH
|
|
|
|
EOF
|
|
)"
|
|
|
|
# Insert below the #!/bin/sh shebang
|
|
echo "$addToPath" | sed "/#!\/bin\/sh/r /dev/stdin" $src/scripts/assume >> $out/bin/assume
|
|
|
|
# Install fish script
|
|
install -Dm755 $src/scripts/assume.fish $out/share/assume.fish
|
|
substituteInPlace $out/share/assume.fish \
|
|
--replace-fail "#!/bin/fish" "#!/usr/bin/env fish"
|
|
'';
|
|
|
|
nativeInstallCheckInputs = [ versionCheckHook ];
|
|
doInstallCheck = true;
|
|
|
|
passthru.updateScript = nix-update-script { };
|
|
|
|
meta = {
|
|
description = "Easiest way to access your cloud";
|
|
homepage = "https://github.com/fwdcloudsec/granted";
|
|
changelog = "https://github.com/fwdcloudsec/granted/releases/tag/v${finalAttrs.version}";
|
|
license = lib.licenses.mit;
|
|
maintainers = with lib.maintainers; [
|
|
jlbribeiro
|
|
];
|
|
};
|
|
})
|