From patchwork Sun Apr 7 20:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: paul X-Patchwork-Id: 62834 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D118827BBEA; Sun, 7 Apr 2024 21:59:21 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 507A627BBE2 for ; Sun, 7 Apr 2024 21:59:20 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtZbO-0003jG-FZ; Sun, 07 Apr 2024 16:58:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtZbN-0003go-2S for guix-patches@gnu.org; Sun, 07 Apr 2024 16:58:57 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rtZbM-0000PM-Qn for guix-patches@gnu.org; Sun, 07 Apr 2024 16:58:56 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rtZbT-0005Ve-HK for guix-patches@gnu.org; Sun, 07 Apr 2024 16:59:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70265] [PATCH 3/3] gnu: Add home-docker-cli-service-type. Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Sun, 07 Apr 2024 20:59:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70265 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 70265@debbugs.gnu.org Cc: Giacomo Leidi , ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= , Tanguy Le Carrour X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?utf-8?q?Court=C3=A8s?= , Tanguy Le Carrour Received: via spool by 70265-submit@debbugs.gnu.org id=B70265.171252351821071 (code B ref 70265); Sun, 07 Apr 2024 20:59:03 +0000 Received: (at 70265) by debbugs.gnu.org; 7 Apr 2024 20:58:38 +0000 Received: from localhost ([127.0.0.1]:44879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtZb0-0005T7-8a for submit@debbugs.gnu.org; Sun, 07 Apr 2024 16:58:37 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:45423) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rtZar-0005Rl-Dv for 70265@debbugs.gnu.org; Sun, 07 Apr 2024 16:58:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1712523497; bh=0tPiOteJ1jJCw3ZhCP9T3sjkiNYfOfI5TBGeyhXf+bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o3P8ctTdGzRf3g1ry7LChglReB36jQKj54Fh7bqXIEJwFVUQO0mi7fStQZT7MBIEc XQJSd4z1QdiNY+w292lGzhAgcZ58ZnVw1sQgdzjd8P45qTUvlDR4RzEU7mEcowRBwo ET+3faC3Z59eBepQDmENe3oJEgt430mH5iLoDxWU= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4VCPh95xprz11Pm; Sun, 7 Apr 2024 20:58:17 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4VCPh94Tgsz11NC; Sun, 7 Apr 2024 20:58:17 +0000 (UTC) Date: Sun, 7 Apr 2024 22:57:19 +0200 Message-ID: <814c5c6c8ba59b4069966f46c995e7a8fd0d9b88.1712523439.git.goodoldpaul@autistici.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <95e5c6e85e09ead19a43fc37612d62bc91a64048.1712523439.git.goodoldpaul@autistici.org> References: <95e5c6e85e09ead19a43fc37612d62bc91a64048.1712523439.git.goodoldpaul@autistici.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches X-Patchwork-Original-From: Giacomo Leidi via Guix-patches via From: paul Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/home/services/containers.scm (home-docker-cli-service-type): New variable; * doc/guix.texi: document it; * gnu/local.mk: add it. Change-Id: I71e7a2805fe8754511c8e02ee4ae667e34e4aaf6 --- doc/guix.texi | 53 +++++++++++ gnu/home/services/containers.scm | 148 +++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 202 insertions(+) create mode 100644 gnu/home/services/containers.scm diff --git a/doc/guix.texi b/doc/guix.texi index 20f007b1c0..61cc904f9d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -46500,6 +46500,59 @@ Miscellaneous Home Services (dicod-configuration @dots{}))) @end lisp +@subsubheading Container Services + +@cindex docker cli service, for Home +The @code{(gnu home services containers)} module provides the following service: + +@defvar home-docker-cli-service-type +This service allows for configuring the Docker command line interface, for +example to make it aware of Guix provided plugins. +@end defvar + +For example, you can use it like this to make Docker safely store your registry +credentials with the system +@uref{https://wiki.gnome.org/Projects/Libsecret, libsecret} compatible Secret service: + +@lisp +(use-modules (gnu packages docker)) + +(service home-docker-cli-service-type + (docker-cli-configuration + (creds-store "secretservice") + (cli-plugins + (list docker-credential-secretservice)) + (extra-content ", \"auths\": @{\"https://index.docker.io/v1/\": @{@}@}"))) +@end lisp + + +@c %start of fragment + +@deftp {Data Type} docker-cli-configuration +Available @code{docker-cli-configuration} fields are: + +@table @asis +@item @code{docker-cli} (default: @code{docker-cli}) (type: package) +The Docker cli package installed to the Home profile. + +@item @code{creds-store} (type: maybe-string) +A native secrets store used to store Docker credentials. + +@item @code{cli-plugins} (default: @code{()}) (type: list-of-docker-cli-plugins) +A list of Docker cli plugin package records that will be configured to +work with Docker's cli. + +@item @code{extra-content} (default: @code{""}) (type: string) +Additional literal content that will be appended to Docker cli +config.json. + +@end table + +@end deftp + + +@c %end of fragment + @node Invoking guix home @section Invoking @command{guix home} diff --git a/gnu/home/services/containers.scm b/gnu/home/services/containers.scm new file mode 100644 index 0000000000..89d6ad5f39 --- /dev/null +++ b/gnu/home/services/containers.scm @@ -0,0 +1,148 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Giacomo Leidi +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu home services containers) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu packages docker) + #:use-module (gnu services configuration) + #:use-module (gnu home services) + #:use-module (ice-9 match) + #:use-module (ice-9 string-fun) + #:export (docker-cli-configuration + docker-cli-configuration? + docker-cli-configuration-fields + docker-cli-configuration-docker-cli + docker-cli-configuration-creds-store + docker-cli-configuration-cli-plugins + + home-docker-cli-service-type + home-docker-cli-configuration-file + docker-cli-configuration->json-fields)) + +;; Turn field names, which are Scheme symbols into strings +;; cli-plugins-extra-dirs -> cliPluginsExtraDirs +(define (format-name name) + (define without-dashes (string-replace-substring (symbol->string name) "-" " ")) + (define splitted (string-split without-dashes #\space)) + (string-replace-substring + (apply string-append + `(,(car splitted) + ,@(map string-capitalize (cdr splitted)))) + " " "")) + +(define (serialize-json-value name value) + #~(begin + (use-modules (ice-9 format)) + (format #f "\"~a\": ~a" #$(format-name name) #$value))) + +(define (serialize-json-list values) + #~(string-append "[" + (string-join + (map (lambda (s) (string-append "\"" s "\"")) + (list #$@values)) + ", ") + "]")) + +(define (serialize-string field-name value) + (serialize-json-value field-name (string-append "\"" value "\""))) + +(define (serialize-maybe-string field-name value) + (if (maybe-value-set? value) + (serialize-string field-name value) + '())) + +(define (serialize-list-of-strings field-name value) + (serialize-json-value field-name (serialize-json-list value))) + +(define (serialize-list-of-docker-cli-plugins value) + (serialize-json-value 'cli-plugins-extra-dirs + (serialize-json-list + (map (lambda (p) + (file-append p "/libexec/docker/cli-plugins")) + value)))) + +(define list-of-strings? + (list-of string?)) + +(define list-of-docker-cli-plugins? + (list-of package?)) + +(define-maybe string) + +(define-configuration/no-serialization docker-cli-configuration + (docker-cli + (package docker-cli) + "The Docker cli package installed to the Home profile.") + (creds-store + (maybe-string) + "A native secrets store used to store Docker credentials.") + (cli-plugins + (list-of-docker-cli-plugins '()) + "A list of Docker cli plugin package records that will be configured to work with Docker's cli.") + (extra-content + (string "") + "Additional literal content that will be appended to Docker cli config.json.")) + +(define docker-cli-configuration->json-fields + (lambda (config) + (filter (compose not (lambda (f) (or (null? f) (and (string? f) (string-null? f))))) + (map (lambda (f) + (let ((field-name (configuration-field-name f)) + (type (configuration-field-type f)) + (value ((configuration-field-getter f) config))) + (if (not (member field-name '(docker-cli extra-content))) + (match type + ('string + (serialize-string field-name value)) + ('maybe-string + (serialize-maybe-string field-name value)) + ('list-of-strings + (serialize-list-of-strings field-name value)) + ('list-of-docker-cli-plugins + (serialize-list-of-docker-cli-plugins value)) + (_ + (raise + (formatted-message + (G_ "Unknown docker-cli-configuration field type: ~a") + type)))) + '()))) + docker-cli-configuration-fields)))) + +(define (home-docker-cli-configuration-file config) + `((".docker/config.json" + ,(computed-file "docker-cli-config.json" + #~(with-output-to-file #$output + (lambda _ + (display + (string-append "{" + (string-join (list #$@(docker-cli-configuration->json-fields config)) ",") + #$(docker-cli-configuration-extra-content config) + "}\n")))))))) + +(define home-docker-cli-service-type + (service-type (name 'docker-cli) + (extensions (list (service-extension home-profile-service-type + (lambda (config) + `(,(docker-cli-configuration-docker-cli config) + ,@(docker-cli-configuration-cli-plugins config)))) + (service-extension home-files-service-type + home-docker-cli-configuration-file))) + (default-value (docker-cli-configuration)) + (description + "This service install and configures Docker's command line interface."))) diff --git a/gnu/local.mk b/gnu/local.mk index 7f1006010b..4960f32a1a 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -95,6 +95,7 @@ GNU_SYSTEM_MODULES = \ %D%/compression.scm \ %D%/home.scm \ %D%/home/services.scm \ + %D%/home/services/containers.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \