nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 115 lines 3.9 kB view raw
1{ 2 lib, 3 makeWrapper, 4 buildGoModule, 5 fetchFromGitHub, 6 installShellFiles, 7 writableTmpDirAsHomeHook, 8 jq, 9 gnupg, 10 gopass, 11 versionCheckHook, 12}: 13 14let 15 # https://github.com/gopasspw/gopass-jsonapi/blob/v1.16.0/internal/jsonapi/manifest/manifest_path_linux.go 16 manifestPaths = { 17 firefox = "$out/lib/mozilla/native-messaging-hosts/com.justwatch.gopass.json"; 18 chrome = "$out/etc/opt/chrome/native-messaging-hosts/com.justwatch.gopass.json"; 19 chromium = "$out/etc/chromium/native-messaging-hosts/com.justwatch.gopass.json"; 20 brave = "$out/etc/opt/chrome/native-messaging-hosts/com.justwatch.gopass.json"; 21 vivaldi = "$out/etc/opt/vivaldi/native-messaging-hosts/com.justwatch.gopass.json"; 22 iridium = "$out/etc/iridium-browser/native-messaging-hosts/com.justwatch.gopass.json"; 23 slimjet = "$out/etc/opt/slimjet/native-messaging-hosts/com.justwatch.gopass.json"; 24 }; 25in 26buildGoModule (finalAttrs: { 27 pname = "gopass-jsonapi"; 28 version = "1.16.1"; 29 30 src = fetchFromGitHub { 31 owner = "gopasspw"; 32 repo = "gopass-jsonapi"; 33 tag = "v${finalAttrs.version}"; 34 hash = "sha256-JN/SC7lvPVTONNbOUmgu//xK/GaR5Tljxn99Zb1J/kQ="; 35 }; 36 37 vendorHash = "sha256-Ki0gzhDkoUvgTCN4bYrqvN0u3AgdG22MWxcVHIE9lUQ="; 38 39 subPackages = [ "." ]; 40 41 nativeBuildInputs = [ 42 installShellFiles 43 makeWrapper 44 writableTmpDirAsHomeHook 45 ]; 46 47 ldflags = [ 48 "-s" 49 "-w" 50 "-X main.version=${finalAttrs.version}" 51 "-X main.commit=${finalAttrs.src.rev}" 52 ]; 53 54 postInstall = '' 55 # Generate native messaging manifests for Chrome and Firefox. 56 ${gnupg}/bin/gpg --batch --passphrase "" --quick-generate-key "user <user@localhost>" 57 ${gopass}/bin/gopass setup --name "user" --email "user@localhost" 58 59 ${lib.concatMapStrings ( 60 browser: 61 let 62 manifestPath = manifestPaths.${browser}; 63 in 64 # The options after `--print=false` are of no effect, but if missing 65 # `gopass-jsonapi configure` will ask for them. (`--libpath` and `--global` 66 # are overridden by `--manifest-path`. `--libpath` is only used to 67 # compute Firefox's global manifest path. See 68 # https://github.com/gopasspw/gopass-jsonapi/blob/v1.16.0/setup_others.go#L33-L46) 69 # 70 # `gopass-jsonapi configure` ask for confirmation before writing any files, 71 # `echo y` gives it. 72 # Prepend $PATH so we can run gopass-jsonapi before wrapProgram in postFixup. 73 '' 74 echo y | PATH="${gopass.wrapperPath}:$PATH" $out/bin/gopass-jsonapi configure \ 75 --browser ${browser} \ 76 --path $out/lib/gopass \ 77 --manifest-path ${manifestPath} \ 78 --print=false \ 79 --global \ 80 --libpath /var/empty 81 # replace gopass_wrapper.sh with ./browser-jsonapi-wrapper.sh 82 rm $out/lib/gopass/gopass_wrapper.sh 83 ${jq}/bin/jq --arg script $out/lib/gopass/browser-jsonapi-wrapper.sh \ 84 '.path = $script' ${manifestPath} > ${manifestPath}.tmp 85 mv ${manifestPath}.tmp ${manifestPath} 86 '' 87 ) (builtins.attrNames manifestPaths)} 88 substitute ${./browser-jsonapi-wrapper.sh} $out/lib/gopass/browser-jsonapi-wrapper.sh \ 89 --replace-fail "@OUT@" "$out" 90 chmod +x $out/lib/gopass/browser-jsonapi-wrapper.sh 91 ''; 92 93 postFixup = '' 94 wrapProgram $out/bin/gopass-jsonapi \ 95 --prefix PATH : "${gopass.wrapperPath}" 96 ''; 97 98 doInstallCheck = true; 99 nativeInstallCheckInputs = [ 100 versionCheckHook 101 ]; 102 versionCheckKeepEnvironment = [ "HOME" ]; 103 104 meta = { 105 description = "Enables communication with gopass via JSON messages"; 106 homepage = "https://github.com/gopasspw/gopass-jsonapi"; 107 changelog = "https://github.com/gopasspw/gopass-jsonapi/blob/v${finalAttrs.version}/CHANGELOG.md"; 108 license = lib.licenses.mit; 109 maintainers = with lib.maintainers; [ 110 maxhbr 111 doronbehar 112 ]; 113 mainProgram = "gopass-jsonapi"; 114 }; 115})