Subject: [bug#70265] [PATCH 1/3] gnu: Add docker-credential-secretservice.

From: Giacomo Leidi <[email-masked]>
Date: Sun, 7 Apr 2024 22:57:17 +0200

* gnu/packages/docker.scm (docker-credential-helpers): New variable.
* gnu/packages/gnome.scm (docker-credential-secretservice): New variable.

Change-Id: I6c46d429fa2842969b0fcde58ded72e5b04ee321
---
 gnu/packages/docker.scm | 70 ++++++++++++++++++++++++++++++++++++++++-
 gnu/packages/gnome.scm  |  6 +++-
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 0fe1f2c1c7..31501e50b9 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2020 Jesse Dowell <[email-masked]>
 ;;; Copyright © 2021, 2022 Oleg Pykhalov <[email-masked]>
 ;;; Copyright © 2022 Pierre Langlois <[email-masked]>
+;;; Copyright © 2024 Giacomo Leidi <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -51,7 +52,8 @@ (define-module (gnu packages docker)
   #:use-module (gnu packages python-web)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages version-control)
-  #:use-module (gnu packages virtualization))
+  #:use-module (gnu packages virtualization)
+  #:export (docker-credential-helpers))
 
 ;; Note - when changing Docker versions it is important to update the versions
 ;; of several associated packages (docker-libnetwork and go-sctp).
@@ -670,6 +672,72 @@ (define-public docker-cli
     (home-page "https://www.docker.com/")
     (license license:asl2.0)))
 
+;; Actual users of this procedure are
+;; docker-credentials-secretservice and docker-credential-pass, they live in
+;; different modules to avoid circular imports.
+(define* (docker-credential-helpers plugin-name #:key (inputs '()))
+  (package
+    (name (string-append "docker-credential-" plugin-name))
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/docker/docker-credential-helpers")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1kric2yrgypdqncqfrmrh7l7904km5zisygi3fg6zlfkyh6rsm23"))))
+    (build-system go-build-system)
+    (arguments
+     (list
+      #:install-source? #f
+      #:go go-1.19
+      #:unpack-path "github.com/docker/docker-credential-helpers"
+      #:import-path
+      (string-append "github.com/docker/docker-credential-helpers/"
+                     plugin-name "/cmd")
+      #:phases
+      #~(modify-phases %standard-phases
+          (replace 'build
+            (lambda* (#:key unpack-path import-path build-flags #:allow-other-keys)
+              (apply invoke "go" "build"
+                     "-v"
+                     "-x"
+                     (string-append "-ldflags=-s -w "
+                                    "-X github.com/docker/docker-credential-helpers"
+                                    "/credentials.Version=" #$version " "
+                                    "-X github.com/docker/docker-credential-helpers"
+                                    "/credentials.Package=" unpack-path " "
+                                    "-X github.com/docker/docker-credential-helpers"
+                                    "/credentials.Name=" #$name)
+                     "-o" (string-append "bin/" #$name)
+                     `(,@build-flags ,import-path))))
+          (replace 'install
+            (lambda _
+              (let* ((bin
+                     (string-append #$output "/bin"))
+                    (lib
+                     (string-append #$output "/libexec/docker/cli-plugins"))
+                    (entrypoint
+                     (string-append lib "/" #$name)))
+                (mkdir-p bin)
+                (mkdir-p lib)
+                (copy-file (string-append "bin/" #$name) entrypoint)
+                (symlink entrypoint
+                         (string-append bin "/" #$name))))))))
+    (native-inputs
+     (list pkg-config))
+    (inputs inputs)
+    (home-page "https://github.com/docker/docker-credential-helpers")
+    (synopsis "Store Docker login credentials in platform keystores")
+    (description
+     (string-append "docker-credential-helpers is a suite of programs to use native stores to keep
+Docker credentials safe.
+
+This package provides the @code{" name "} plugin."))
+    (license license:expat)))
+
 (define-public cqfd
   (package
     (name "cqfd")
diff --git a/gnu/packages/gnome.scm b/gnu/packages/gnome.scm
index 06256066bc..58b53aba22 100644
--- a/gnu/packages/gnome.scm
+++ b/gnu/packages/gnome.scm
@@ -36,7 +36,7 @@
 ;;; Copyright © 2019 Danny Milosavljevic <[email-masked]>
 ;;; Copyright © 2019, 2020, 2022 Marius Bakke <[email-masked]>
 ;;; Copyright © 2019 Florian Pelz <[email-masked]>
-;;; Copyright © 2019 Giacomo Leidi <[email-masked]>
+;;; Copyright © 2019, 2024 Giacomo Leidi <[email-masked]>
 ;;; Copyright © 2019 Jelle Licht <[email-masked]>
 ;;; Copyright © 2019 Jonathan Frederickson <[email-masked]>
 ;;; Copyright © 2019, 2020, 2021, 2022, 2023 Maxim Cournoyer <[email-masked]>
@@ -5229,6 +5229,10 @@ (define-public libsecret
 and other secrets.  It communicates with the \"Secret Service\" using DBus.")
     (license license:lgpl2.1+)))
 
+(define-public docker-credential-secretservice
+  (docker-credential-helpers "secretservice"
+                             #:inputs (list libsecret)))
+
 (define-public five-or-more
   (package
     (name "five-or-more")

base-commit: 69951a61a1d8f1f2135ea2dc836738be282b97bc
-- 
2.41.0