From patchwork Tue Jul 6 21:11:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 31208 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 0996727BC81; Tue, 6 Jul 2021 22:13:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B3B7827BC78 for ; Tue, 6 Jul 2021 22:13:12 +0100 (BST) Received: from localhost ([::1]:34812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0sNT-0008Hd-Pl for patchwork@mira.cbaines.net; Tue, 06 Jul 2021 17:13:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0sNK-0008HF-Bi for guix-patches@gnu.org; Tue, 06 Jul 2021 17:13:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0sNK-0004JX-47 for guix-patches@gnu.org; Tue, 06 Jul 2021 17:13:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m0sNJ-0000vM-UJ for guix-patches@gnu.org; Tue, 06 Jul 2021 17:13:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49348] [PATCH v2 1/4] pack: Allow embedding custom control files in deb packs. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 06 Jul 2021 21:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49348 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49348@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 49348-submit@debbugs.gnu.org id=B49348.16256059323455 (code B ref 49348); Tue, 06 Jul 2021 21:13:01 +0000 Received: (at 49348) by debbugs.gnu.org; 6 Jul 2021 21:12:12 +0000 Received: from localhost ([127.0.0.1]:50340 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m0sMW-0000te-0N for submit@debbugs.gnu.org; Tue, 06 Jul 2021 17:12:12 -0400 Received: from mail-qk1-f176.google.com ([209.85.222.176]:34671) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m0sMT-0000tS-QC for 49348@debbugs.gnu.org; Tue, 06 Jul 2021 17:12:10 -0400 Received: by mail-qk1-f176.google.com with SMTP id g4so21679645qkl.1 for <49348@debbugs.gnu.org>; Tue, 06 Jul 2021 14:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bx3Fk97oa84BYLDRR2HXWOKM/IvzH6WRlbv0Y/nnfL0=; b=o8mdpHYyN6Yqhwg4pF4EkCgUYtQ2Uo7TG3Iv1JdU6r6IpPp2c8+hb+dr5hZA9m8xVf MSHixfVlwuUNDkCLBpqQK4kFAfeHJjqdZzDb2M/cyxPWwwQbwXglMcfgA1m/Ep/Da2ia ajCjj9wUTNA0/pjFk+Vz6edIoAeE5v+1ZwKTyAvrG/zkdJWo1OHZVznaMA66IK5vPMv+ qPX6P4jqwYLWi22pb0/QhZ6Qvs5+SpdoTxlQzndRf1ckP1AnSumxIKw1M5fx8bj+NAQg 04V9v9ll8DFkwHBXX11I1REfCBOCg0dFwIIx9RXdJ5YUodgD1wcLeS495q04HpKHrXGz rzOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bx3Fk97oa84BYLDRR2HXWOKM/IvzH6WRlbv0Y/nnfL0=; b=Mt10D2SS5dyhnOyrctUMURFFAqbW38/zSFW2YINDI22D/JF0UOxYEt0YcbSmVGm/T0 32W7TVtQe1gjUGcx4fMB+xObDabEU8YPKv5qvEMw6jhmkq035PX3BVUccIKVswmG/NcH Qa1UOXa4voFe2uHeT7vV0abktv4c8P4kKAzaqzzhEYFKi6qZSoPZExy3fp6JZ3Js3x0Q uYFMYbwYOyApYUyWjHGDiecV0KBk/ChFxLQ76+YUMFIq8S6j2P+SgM7wO7czcyf4RUyF TmvDDNnDDY1EbdJ/VK0Imr0fxg5VZMbGYCUVtQMVxtY7KZCPnd/DrlSidQaVd7o0fkql Ze2g== X-Gm-Message-State: AOAM532x0qRH72drT7wShEXLw3TtsBg6A1lUTiz5bSOtTxCFK9vsrXjf BMCUVk3rTGMBn5DLjzga/6grpiH0016Baw== X-Google-Smtp-Source: ABdhPJyN9vqC8CQ+2wjQ18BBS5qwwkLjm6BonbImdogmxy0wDwwgIfNz1hCatfGBKMWFVe2yFsPw5A== X-Received: by 2002:a05:620a:21cd:: with SMTP id h13mr21459393qka.309.1625605923844; Tue, 06 Jul 2021 14:12:03 -0700 (PDT) Received: from localhost.localdomain (dsl-205-233-125-111.b2b2c.ca. [205.233.125.111]) by smtp.gmail.com with ESMTPSA id s19sm7240662qks.77.2021.07.06.14.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 14:12:03 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 6 Jul 2021 17:11:36 -0400 Message-Id: <20210706211139.2806-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210703060642.2424-1-maxim.cournoyer@gmail.com> References: <20210703060642.2424-1-maxim.cournoyer@gmail.com> 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/pack.scm (self-contained-tarball/builder) [extra-options]: New argument. (self-contained-tarball, squashfs-image, docker-image) (debian-archive): Likewise. Remove two TODO comments. Document EXTRA-OPTIONS. Use the custom control files when provided. (%deb-format-options): New variable. (show-deb-format-options, show-deb-format-options/detailed): New procedures. (%options): Register new options. (show-help): Augment with new usage. (guix-pack): Validate and propagate new argument values. * doc/guix.texi (Invoking guix pack)[deb]: Document how to list advanced options. Add an example. * tests/pack.scm (deb archive...): Provide extra-options to the debian-archive procedure, and validate that the provided files are embedded in the pack. --- doc/guix.texi | 8 +++ guix/scripts/pack.scm | 121 +++++++++++++++++++++++++++++++++++------- tests/pack.scm | 27 ++++++++-- 3 files changed, 133 insertions(+), 23 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1086d3220b..39d4cb1929 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6047,6 +6047,14 @@ such file or directory'' message. This produces a Debian archive (a package with the @samp{.deb} file extension) containing all the specified binaries and symbolic links, that can be installed on top of any dpkg-based GNU(/Linux) distribution. +Advanced options can be revealed via the @option{--help-deb-format} +option. They allow embedding control files for more fine-grained +control, such as activating specific triggers or providing a maintainer +configure script to run arbitrary setup code upon installation. + +@example +guix pack -f deb -C xz -S /usr/bin/hello=bin/hello hello +@end example @quotation Note Because archives produced with @command{guix pack} contain a collection diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 6d8b70d1c7..6a8d49e042 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -205,7 +205,8 @@ its source property." (compressor (first %compressors)) localstatedir? (symlinks '()) - (archiver tar)) + (archiver tar) + (extra-options '())) "Return the G-Expression of the builder used for self-contained-tarball." (define database (and localstatedir? @@ -324,7 +325,8 @@ its source property." (compressor (first %compressors)) localstatedir? (symlinks '()) - (archiver tar)) + (archiver tar) + (extra-options '())) "Return a self-contained tarball containing a store initialized with the closure of PROFILE, a derivation. The tarball contains /gnu/store; if LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db @@ -389,7 +391,8 @@ to the search paths of PROFILE." entry-point localstatedir? (symlinks '()) - (archiver squashfs-tools)) + (archiver squashfs-tools) + (extra-options '())) "Return a squashfs image containing a store initialized with the closure of PROFILE, a derivation. The image contains a subset of /gnu/store, empty mount points for virtual file systems (like procfs), and optional symlinks. @@ -567,7 +570,8 @@ added to the pack." entry-point localstatedir? (symlinks '()) - (archiver tar)) + (archiver tar) + (extra-options '())) "Return a derivation to construct a Docker image of PROFILE. The image is a tarball conforming to the Docker Image Specification, compressed with COMPRESSOR. It can be passed to 'docker load'. If TARGET is true, it @@ -654,8 +658,6 @@ the image." ;;; TODO: When relocatable option is selected, install to a unique prefix. ;;; This would enable installation of multiple deb packs with conflicting ;;; files at the same time. -;;; TODO: Allow passing a custom control file from the CLI. -;;; TODO: Allow providing a postinst script. (define* (debian-archive name profile #:key target (profile-name "guix-profile") @@ -664,7 +666,8 @@ the image." (compressor (first %compressors)) localstatedir? (symlinks '()) - (archiver tar)) + (archiver tar) + (extra-options '())) "Return a Debian archive (.deb) containing a store initialized with the closure of PROFILE, a derivation. The archive contains /gnu/store; if LOCALSTATEDIR? is true, it also contains /var/guix, including /var/guix/db @@ -672,7 +675,8 @@ with a properly initialized store database. The supported compressors are \"none\", \"gz\" or \"xz\". SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be -added to the pack." +added to the pack. EXTRA-OPTIONS may contain the CONFIG-FILE, POSTINST-FILE +or TRIGGERS-FILE keyword arguments." ;; For simplicity, limit the supported compressors to the superset of ;; compressors able to compress both the control file (gz or xz) and the ;; data tarball (gz, bz2 or xz). @@ -714,21 +718,23 @@ Valid compressors are: ~a~%") compressor-name %valid-compressors))) (guix build utils) (guix profiles) (ice-9 match) + ((oop goops) #:select (get-keyword)) (srfi srfi-1)) (define machine-type ;; Extract the machine type from the specified target, else from the ;; current system. - (and=> (or #$target %host-type) (lambda (triplet) - (first (string-split triplet #\-))))) + (and=> (or #$target %host-type) + (lambda (triplet) + (first (string-split triplet #\-))))) (define (gnu-machine-type->debian-machine-type type) "Translate machine TYPE from the GNU to Debian terminology." ;; Debian has its own jargon, different from the one used in GNU, for ;; machine types (see data/cputable in the sources of dpkg). (match type - ("i586" "i386") ("i486" "i386") + ("i586" "i386") ("i686" "i386") ("x86_64" "amd64") ("aarch64" "arm64") @@ -773,21 +779,40 @@ Valid compressors are: ~a~%") compressor-name %valid-compressors))) (copy-file #+data-tarball data-tarball-file-name) + ;; Generate the control archive. + (define control-file + (get-keyword #:control-file '#$extra-options)) + + (define postinst-file + (get-keyword #:postinst-file '#$extra-options)) + + (define triggers-file + (get-keyword #:triggers-file '#$extra-options)) + (define control-tarball-file-name (string-append "control.tar" #$(compressor-extension compressor))) ;; Write the compressed control tarball. Only the control file is ;; mandatory (see: 'man deb' and 'man deb-control'). - (call-with-output-file "control" - (lambda (port) - (format port "\ + (if control-file + (copy-file control-file "control") + (call-with-output-file "control" + (lambda (port) + (format port "\ Package: ~a Version: ~a Description: Debian archive generated by GNU Guix. Maintainer: GNU Guix Architecture: ~a -~%" package-name package-version architecture))) +~%" package-name package-version architecture)))) + + (when postinst-file + (copy-file postinst-file "postinst") + (chmod "postinst" #o755)) + + (when triggers-file + (copy-file triggers-file "triggers")) (define tar (string-append #+archiver "/bin/tar")) @@ -796,7 +821,9 @@ Architecture: ~a #:tar tar #:compressor '#+(and=> compressor compressor-command)) "-cvf" ,control-tarball-file-name - "control")) + "control" + ,@(if postinst-file '("postinst") '()) + ,@(if triggers-file '("triggers") '()))) ;; Create the .deb archive using GNU ar. (invoke (string-append #+binutils "/bin/ar") "-rv" #$output @@ -1157,6 +1184,34 @@ last resort for relocation." deb Debian archive installable via dpkg/apt")) (newline)) +(define %deb-format-options + (let ((required-option (lambda (symbol) + (option (list (symbol->string symbol)) #t #f + (lambda (opt name arg result . rest) + (apply values + (alist-cons symbol arg result) + rest)))))) + (list (required-option 'control-file) + (required-option 'postinst-file) + (required-option 'triggers-file)))) + +(define (show-deb-format-options) + (display (G_ " + --help-deb-format list options specific to the deb format"))) + +(define (show-deb-format-options/detailed) + (display (G_ " + --control-file=FILE + Embed the provided control FILE")) + (display (G_ " + --postinst-file=FILE + Embed the provided postinst script")) + (display (G_ " + --triggers-file=FILE + Embed the provided triggers FILE")) + (newline) + (exit 0)) + (define %options ;; Specifications of the command-line options. (cons* (option '(#\h "help") #f #f @@ -1250,7 +1305,12 @@ last resort for relocation." (lambda (opt name arg result) (alist-cons 'bootstrap? #t result))) - (append %transformation-options + (option '("help-deb-format") #f #f + (lambda args + (show-deb-format-options/detailed))) + + (append %deb-format-options + %transformation-options %standard-build-options))) (define (show-help) @@ -1260,6 +1320,8 @@ Create a bundle of PACKAGE.\n")) (newline) (show-transformation-options-help) (newline) + (show-deb-format-options) + (newline) (display (G_ " -f, --format=FORMAT build a pack in the given FORMAT")) (display (G_ " @@ -1369,6 +1431,18 @@ Create a bundle of PACKAGE.\n")) (else (packages->manifest packages)))))) + (define (process-file-arg opts name) + ;; Validate that the file exists and return it as a object, + ;; else #f. + (let ((value (assoc-ref opts name))) + (match value + ((and (? string?) (not (? file-exists?))) + (leave (G_ "file provided with option ~a does not exist: ~a~%") + (string-append "--" (symbol->string name)) value)) + ((? string?) + (local-file value)) + (#f #f)))) + (with-error-handling (with-store store (with-status-verbosity (assoc-ref opts 'verbosity) @@ -1401,6 +1475,15 @@ Create a bundle of PACKAGE.\n")) manifest) manifest))) (pack-format (assoc-ref opts 'format)) + (extra-options (match pack-format + ('deb + (list #:control-file + (process-file-arg opts 'control-file) + #:postinst-file + (process-file-arg opts 'postinst-file) + #:triggers-file + (process-file-arg opts 'triggers-file))) + (_ '()))) (target (assoc-ref opts 'target)) (bootstrap? (assoc-ref opts 'bootstrap?)) (compressor (if bootstrap? @@ -1465,7 +1548,9 @@ to your package list."))) #:profile-name profile-name #:archiver - archiver))) + archiver + #:extra-options + extra-options))) (mbegin %store-monad (mwhen derivation? (return (format #t "~a~%" diff --git a/tests/pack.scm b/tests/pack.scm index 9473d4f384..e9b4c36e0e 100644 --- a/tests/pack.scm +++ b/tests/pack.scm @@ -277,17 +277,25 @@ (built-derivations (list check)))) (unless store (test-skip 1)) - (test-assertm "deb archive with symlinks" store + (test-assertm "deb archive with symlinks and control files" store (mlet* %store-monad ((guile (set-guile-for-build (default-guile))) (profile (profile-derivation (packages->manifest (list %bootstrap-guile)) #:hooks '() #:locales? #f)) - (deb (debian-archive "deb-pack" profile - #:compressor %gzip-compressor - #:symlinks '(("/opt/gnu/bin" -> "bin")) - #:archiver %tar-bootstrap)) + (deb (debian-archive + "deb-pack" profile + #:compressor %gzip-compressor + #:symlinks '(("/opt/gnu/bin" -> "bin")) + #:archiver %tar-bootstrap + #:extra-options + (list #:triggers-file + (plain-file "triggers" + "activate-noawait /usr/share/icons/hicolor\n") + #:postinst-file + (plain-file "postinst" + "echo running configure script\n")))) (check (gexp->derivation "check-deb-pack" (with-imported-modules '((guix build utils)) @@ -344,6 +352,15 @@ (unless (null? hard-links) (error "hard links found in data.tar.gz" hard-links)) + ;; Verify the presence of the control files. + (invoke "tar" "-xf" "control.tar.gz") + (assert (file-exists? "control")) + (assert (and (file-exists? "postinst") + (= #o111 ;script is executable + (logand #o111 (stat:perms + (stat "postinst")))))) + (assert (file-exists? "triggers")) + (mkdir #$output)))))) (built-derivations (list check)))))