From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id dXykBi4N1GANRQAAgWs5BA (envelope-from ) for ; Thu, 24 Jun 2021 06:42:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gDW3AS4N1GCqTgAAbx9fmQ (envelope-from ) for ; Thu, 24 Jun 2021 04:42:22 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 69A51226C5 for ; Thu, 24 Jun 2021 06:42:21 +0200 (CEST) Received: from localhost ([::1]:49112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lwHC0-0005y6-ET for larch@yhetil.org; Thu, 24 Jun 2021 00:42:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lwHBi-0005xN-Bq for guix-patches@gnu.org; Thu, 24 Jun 2021 00:42:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58866) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lwHBi-0002vs-4Y for guix-patches@gnu.org; Thu, 24 Jun 2021 00:42:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lwHBh-0002QY-VS for guix-patches@gnu.org; Thu, 24 Jun 2021 00:42:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49149] [PATCH v2 1/7] pack: Extract builder code from self-contained-tarball. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 24 Jun 2021 04:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49149 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49149@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 49149-submit@debbugs.gnu.org id=B49149.16245096799206 (code B ref 49149); Thu, 24 Jun 2021 04:42:01 +0000 Received: (at 49149) by debbugs.gnu.org; 24 Jun 2021 04:41:19 +0000 Received: from localhost ([127.0.0.1]:42162 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lwHB1-0002OQ-4k for submit@debbugs.gnu.org; Thu, 24 Jun 2021 00:41:19 -0400 Received: from mail-qk1-f181.google.com ([209.85.222.181]:39800) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lwHAz-0002Nv-A9 for 49149@debbugs.gnu.org; Thu, 24 Jun 2021 00:41:18 -0400 Received: by mail-qk1-f181.google.com with SMTP id j184so11219550qkd.6 for <49149@debbugs.gnu.org>; Wed, 23 Jun 2021 21:41:17 -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=nK+XZhiFPUZF48SwwcEJOQPOaSHkTwT9yOejmrHORIk=; b=Hj8dAtWfuxhvHPFfpDnMNayrdFUzQ8gCmVrVKjk/c91Bi+fNxrYRGsKO1DtBJYVfn4 81q0AXComecleIMJNxyyMqNUC9oWHwoRD4ybUMAq6mCqt48HZAUu2HVZRYyc7GzDw5Uh SVU/49P+5D7rmm4jmovI8lrbcWH9RFtQLL44MBrHMIKpX6l2c/rKeNBkH2hYA83QYG1O n0bW+Ba7HtQt1YbY2yKKD9j1NBn65eRXjqQaLI8/6Z0S47kW19mVwIN3VWqTGPpdtDVf X6XVPSjjp1FqNIb/Z1j+gs4ZUFpnTBo/MMNGd9nfvV6N678MZ2+Gc5NI5Czs40g91tyD aupg== 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=nK+XZhiFPUZF48SwwcEJOQPOaSHkTwT9yOejmrHORIk=; b=MfLZrzbV4v8OtLsKksXwi9sUOslDRO1HpDdPzqtZP2Ws9iudTVNbc44tTH/0igw6Ao oZEMv6qiI3Tn3eO2sWUUEQl0kzAmqRlR5Xyt4Mxqf+OYzFTco33omzfj8XfWZuGdUrqo 7Wlurqh/PNO9sNf5B9Kpwi7Qe2rJpZNFAB02Hm+Wv0dfKh2bjczIu87KnMzTTPwLhOEP MEL1Juf9CRIYKH6oVKzpW796doPZUvkf5Cc2qEu/n5YQx6hNcZIqCSfWSHbly8VCr33c kRltP3fKyUa4w3lWv/O+8Jh9fBHX/imqKiq6OZlhGhCChWsSlPVWBBWxEp2s2zO9A2E0 Yi8A== X-Gm-Message-State: AOAM533nKc7VR6BMd8NL+FyKbmSyH7HPK76RrVUMKgoN+LfNC4+Vtq38 77KBzTHP4ELdQL/Hhy5/x9AatFAEnZIR2w== X-Google-Smtp-Source: ABdhPJwEP3nP1famFNutfg/u+zpOBkjCUnLE/g9MG0oS2n/cdYHeJy2I52jLsDCploIXOnohMSKw+A== X-Received: by 2002:a37:a3d5:: with SMTP id m204mr3653449qke.401.1624509671611; Wed, 23 Jun 2021 21:41:11 -0700 (PDT) Received: from localhost.localdomain ([207.35.95.2]) by smtp.gmail.com with ESMTPSA id q199sm1603880qka.112.2021.06.23.21.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 21:41:11 -0700 (PDT) From: Maxim Cournoyer Date: Thu, 24 Jun 2021 00:40:43 -0400 Message-Id: <20210624044049.17906-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1624509741; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=kdBQA0TSysst8Tloj0y+XBA/sAwpUaMZBZgIxmAveW8=; b=jMB3ffcqEd1uQ0OnzJP+cfo+8dT2EnvFEOFkG2waxxA92vUwTntumnIx2aEmJYjYASDCfu 6WyXTOtgvkyEnPmFbZLt9UMSYbnnN95pcPelj9nz7Rzi0RT2r++RwKzkpRjv5/1CfgQIzZ A4OqvMwqy0IaNRmwFHKXPFqMZe3x7mD0J2uxT8YFieAc5uAjXBN4nSOri23QYU/12wmV5n Vzo8w4Z1NA8E9PTjbz/bd9hjJaM+U/QgxEgUpVMuZBU4OYzJk1eSlCZ/pBIHDx/VDPqurS RXYormb5KXf/xNfGJvXHmKmGRhQJN11UjTk7lKEHCWw2Cq4QcJUQycZGQgupwA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624509741; a=rsa-sha256; cv=none; b=mgtu7USjE4qV7fSyyf5B9baUwylk/xj9qms8E0OCWFKm9QGaD/QeS1AnClBy6oKZhdL7vT wuwcPDPg8lAb/ZZ7nvvNQVXDf3ZRNcBxPlZ6n2PvNYAi7AcNqHnnomI3vgpLJsja3irOBZ MkEOKdwhhEkwmTI30fYnAvPiEV5hJx9B80YnOpAxTEc2yt8JdPM0k1XWQl+93b1raYVsD8 dSOyxD3EPFplyWN7d8BcIAH6hwWqoJhzwOUpf+8rBOQxKlBlg3+ZNjkPj5Q8yOnRwf2nJN mSGUlKROgqatCzc1QsBc8jUy/N7L8n5kM5m7D/+ctA2tX5KAUEwBSnX+pbjgfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=Hj8dAtWf; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.33 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=Hj8dAtWf; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 69A51226C5 X-Spam-Score: -1.33 X-Migadu-Scanner: scn1.migadu.com X-TUID: QAb/ZJDdrhFs This is made to allow reusing it for the debian-archive pack format, added in a subsequent commit. * guix/scripts/pack.scm (self-contained-tarball/builder): New procedure, containing the build code extracted from self-contained-tarball. (self-contained-tarball): Use the above procedure. --- guix/scripts/pack.scm | 270 ++++++++++++++++++++++-------------------- 1 file changed, 141 insertions(+), 129 deletions(-) diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index 8cb4e6d2cc..ac477850e6 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -172,22 +172,17 @@ dependencies are registered." (computed-file "store-database" build #:options `(#:references-graphs ,(zip labels items)))) -(define* (self-contained-tarball name profile - #:key target - (profile-name "guix-profile") - deduplicate? - entry-point - (compressor (first %compressors)) - localstatedir? - (symlinks '()) - (archiver tar)) - "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 -with a properly initialized store database. - -SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be -added to the pack." + +;;; +;;; Tarball format. +;;; +(define* (self-contained-tarball/builder profile + #:key (profile-name "guix-profile") + (compressor (first %compressors)) + localstatedir? + (symlinks '()) + (archiver tar)) + "Return the G-Expression of the builder used for self-contained-tarball." (define database (and localstatedir? (file-append (store-database (list profile)) @@ -209,125 +204,142 @@ added to the pack." (and (not-config? module) (not (equal? '(guix store deduplication) module)))) - (define build - (with-imported-modules (source-module-closure - `((guix build utils) - (guix build union) - (gnu build install)) - #:select? import-module?) - #~(begin - (use-modules (guix build utils) - ((guix build union) #:select (relative-file-name)) - (gnu build install) - (srfi srfi-1) - (srfi srfi-26) - (ice-9 match)) + (with-imported-modules (source-module-closure + `((guix build utils) + (guix build union) + (gnu build install)) + #:select? import-module?) + #~(begin + (use-modules (guix build utils) + ((guix build union) #:select (relative-file-name)) + (gnu build install) + (srfi srfi-1) + (srfi srfi-26) + (ice-9 match)) + + (define %root "root") + + (define symlink->directives + ;; Return "populate directives" to make the given symlink and its + ;; parent directories. + (match-lambda + ((source '-> target) + (let ((target (string-append #$profile "/" target)) + (parent (dirname source))) + ;; Never add a 'directory' directive for "/" so as to + ;; preserve its ownnership when extracting the archive (see + ;; below), and also because this would lead to adding the + ;; same entries twice in the tarball. + `(,@(if (string=? parent "/") + '() + `((directory ,parent))) + (,source + -> ,(relative-file-name parent target))))))) + + (define directives + ;; Fully-qualified symlinks. + (append-map symlink->directives '#$symlinks)) + + ;; The --sort option was added to GNU tar in version 1.28, released + ;; 2014-07-28. For testing, we use the bootstrap tar, which is + ;; older and doesn't support it. + (define tar-supports-sort? + (zero? (system* (string-append #+archiver "/bin/tar") + "cf" "/dev/null" "--files-from=/dev/null" + "--sort=name"))) + + ;; Make sure non-ASCII file names are properly handled. + #+set-utf8-locale + + ;; Add 'tar' to the search path. + (setenv "PATH" #+(file-append archiver "/bin")) + + ;; Note: there is not much to gain here with deduplication and there + ;; is the overhead of the '.links' directory, so turn it off. + ;; Furthermore GNU tar < 1.30 sometimes fails to extract tarballs + ;; with hard links: + ;; . + (populate-single-profile-directory %root + #:profile #$profile + #:profile-name #$profile-name + #:closure "profile" + #:database #+database) + + ;; Create SYMLINKS. + (for-each (cut evaluate-populate-directive <> %root) + directives) + + ;; Create the tarball. Use GNU format so there's no file name + ;; length limitation. + (with-directory-excursion %root + (apply invoke "tar" + #+@(if (compressor-command compressor) + #~("-I" + (string-join + '#+(compressor-command compressor))) + #~()) + "--format=gnu" + ;; Avoid non-determinism in the archive. + ;; Use mtime = 1, not zero, because that is what the daemon + ;; does for files in the store (see the 'mtimeStore' constant + ;; in local-store.cc.) + (if tar-supports-sort? "--sort=name" "--mtime=@1") + "--owner=root:0" + "--group=root:0" + "--check-links" + "-cvf" #$output + ;; Avoid adding / and /var to the tarball, so + ;; that the ownership and permissions of those + ;; directories will not be overwritten when + ;; extracting the archive. Do not include /root + ;; because the root account might have a + ;; different home directory. + #$@(if localstatedir? + '("./var/guix") + '()) + + (string-append "." (%store-directory)) + + (delete-duplicates + (filter-map (match-lambda + (('directory directory) + (string-append "." directory)) + ((source '-> _) + (string-append "." source)) + (_ #f)) + directives))))))) - (define %root "root") - - (define symlink->directives - ;; Return "populate directives" to make the given symlink and its - ;; parent directories. - (match-lambda - ((source '-> target) - (let ((target (string-append #$profile "/" target)) - (parent (dirname source))) - ;; Never add a 'directory' directive for "/" so as to - ;; preserve its ownnership when extracting the archive (see - ;; below), and also because this would lead to adding the - ;; same entries twice in the tarball. - `(,@(if (string=? parent "/") - '() - `((directory ,parent))) - (,source - -> ,(relative-file-name parent target))))))) - - (define directives - ;; Fully-qualified symlinks. - (append-map symlink->directives '#$symlinks)) - - ;; The --sort option was added to GNU tar in version 1.28, released - ;; 2014-07-28. For testing, we use the bootstrap tar, which is - ;; older and doesn't support it. - (define tar-supports-sort? - (zero? (system* (string-append #+archiver "/bin/tar") - "cf" "/dev/null" "--files-from=/dev/null" - "--sort=name"))) - - ;; Make sure non-ASCII file names are properly handled. - #+set-utf8-locale - - ;; Add 'tar' to the search path. - (setenv "PATH" #+(file-append archiver "/bin")) - - ;; Note: there is not much to gain here with deduplication and there - ;; is the overhead of the '.links' directory, so turn it off. - ;; Furthermore GNU tar < 1.30 sometimes fails to extract tarballs - ;; with hard links: - ;; . - (populate-single-profile-directory %root - #:profile #$profile - #:profile-name #$profile-name - #:closure "profile" - #:database #+database) - - ;; Create SYMLINKS. - (for-each (cut evaluate-populate-directive <> %root) - directives) - - ;; Create the tarball. Use GNU format so there's no file name - ;; length limitation. - (with-directory-excursion %root - (exit - (zero? (apply system* "tar" - #+@(if (compressor-command compressor) - #~("-I" - (string-join - '#+(compressor-command compressor))) - #~()) - "--format=gnu" - - ;; Avoid non-determinism in the archive. Use - ;; mtime = 1, not zero, because that is what the - ;; daemon does for files in the store (see the - ;; 'mtimeStore' constant in local-store.cc.) - (if tar-supports-sort? "--sort=name" "--mtime=@1") - "--mtime=@1" ;for files in /var/guix - "--owner=root:0" - "--group=root:0" - - "--check-links" - "-cvf" #$output - ;; Avoid adding / and /var to the tarball, so - ;; that the ownership and permissions of those - ;; directories will not be overwritten when - ;; extracting the archive. Do not include /root - ;; because the root account might have a - ;; different home directory. - #$@(if localstatedir? - '("./var/guix") - '()) - - (string-append "." (%store-directory)) - - (delete-duplicates - (filter-map (match-lambda - (('directory directory) - (string-append "." directory)) - ((source '-> _) - (string-append "." source)) - (_ #f)) - directives))))))))) +(define* (self-contained-tarball name profile + #:key target + (profile-name "guix-profile") + deduplicate? + entry-point + (compressor (first %compressors)) + localstatedir? + (symlinks '()) + (archiver tar)) + "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 +with a properly initialized store database. +SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be +added to the pack." (when entry-point (warning (G_ "entry point not supported in the '~a' format~%") 'tarball)) - (gexp->derivation (string-append name ".tar" - (compressor-extension compressor)) - build - #:target target - #:references-graphs `(("profile" ,profile)))) + (gexp->derivation + (string-append name ".tar" + (compressor-extension compressor)) + (self-contained-tarball/builder profile + #:profile-name profile-name + #:compressor compressor + #:localstatedir? localstatedir? + #:symlinks symlinks + #:archiver archiver) + #:target target + #:references-graphs `(("profile" ,profile)))) (define (singularity-environment-file profile) "Return a shell script that defines the environment variables corresponding -- 2.32.0