all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Josselin Poiret via Bug reports for GNU Guix <bug-guix@gnu.org>
To: "Ludovic Courtès" <ludo@gnu.org>, "Mathieu Othacehe" <othacehe@gnu.org>
Cc: Josselin Poiret <dev@jpoiret.xyz>, 53210@debbugs.gnu.org
Subject: bug#53210: [WIP PATCH 3/4] gnu: current-guix: Support when running outside a checkout.
Date: Mon, 14 Feb 2022 10:29:07 +0100	[thread overview]
Message-ID: <20220214092908.16801-4-dev@jpoiret.xyz> (raw)
In-Reply-To: <20220214092908.16801-1-dev@jpoiret.xyz>

* guix/channels.scm (channel-build-system): Add build system that
turns a channel record into a package.
* gnu/packages/package-management.scm (current-guix): Use
channel-build-system.
---
 gnu/packages/package-management.scm | 45 +++++++++++++++++++++--------
 guix/channels.scm                   | 23 +++++++++++++++
 2 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/gnu/packages/package-management.scm b/gnu/packages/package-management.scm
index 35913e6153..fe906fd440 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -116,10 +116,14 @@ (define-module (gnu packages package-management)
   #:use-module (guix build-system trivial)
   ;; This will be loaded by build-self.scm, but guile-git is unavailable, so
   ;; lazily load instead.
-  #:autoload (guix channels) (channel-build-system guix-channel?)
+  #:autoload (guix channels) (channel-profile-build-system
+                              channel-build-system
+                              guix-channel?)
+  #:use-module (guix describe)
   #:use-module (guix download)
   #:use-module (guix gexp)
   #:use-module (guix git-download)
+  #:autoload (guix git) (git-checkout)
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
   #:use-module (guix utils)
@@ -588,6 +592,18 @@ (define-public channel-source->profile-package
       (native-inputs '())
       (propagated-inputs '()))))
 
+(define-public channel->package
+  (lambda (channel)
+    "Return a package for the given CHANNEL."
+    (package
+      (inherit guix)
+      (version (string-append (package-version guix) "+"))
+      (build-system channel-build-system)
+      (arguments `(#:channel ,channel))
+      (inputs '())
+      (native-inputs '())
+      (propagated-inputs '()))))
+
 (define-public current-guix-package
   ;; This parameter allows callers to override the package that 'current-guix'
   ;; returns.  This is useful when 'current-guix' cannot compute it by itself,
@@ -595,22 +611,27 @@ (define-public current-guix-package
   (make-parameter #f))
 
 (define-public current-guix
-  (let* ((repository-root (delay (canonicalize-path
-                                  (string-append (current-source-directory)
-                                                 "/../.."))))
-         (select? (delay (or (git-predicate (force repository-root))
-                             source-file?))))
-    (lambda ()
-      "Return a package representing Guix built from the current source tree.
-This works by adding the current source tree to the store (after filtering it
-out) and returning a package that uses that as its 'source'."
+  (lambda ()
+    "Return a package representing Guix built from the currently used one.
+This works by either looking up profile or build metadata, and building from
+the current Guix channel.  If that metadata is missing, assume we are running
+from a Git checkout, so add the current source tree to the store (after
+filtering it out) and return a package that uses that as its 'source'."
+    (let* ((guix-channel (find guix-channel? (current-channels)))
+           (repository-root (canonicalize-path
+                             (string-append (current-source-directory)
+                                            "/../..")))
+           (select? (or (git-predicate  repository-root)
+                        source-file?)))
       (or (current-guix-package)
+          (and guix-channel
+               (channel->package guix-channel))
           (package
             (inherit guix)
             (version (string-append (package-version guix) "+"))
-            (source (local-file (force repository-root) "guix-current"
+            (source (local-file repository-root "guix-current"
                                 #:recursive? #t
-                                #:select? (force select?))))))))
+                                #:select? select?)))))))
 
 (define-public guix-icons
   (package
diff --git a/guix/channels.scm b/guix/channels.scm
index 01f63d9631..c930fd2ae7 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -94,6 +94,7 @@ (define-module (guix channels)
             channel-instances->derivation
             ensure-forward-channel-update
 
+            channel-build-system
             channel-profile-build-system
 
             profile-channels
@@ -955,6 +956,28 @@ (define* (latest-channel-derivation #:optional (channels %default-channels)
                                                   validate-pull)))
     (channel-instances->derivation instances)))
 
+(define channel-build-system
+  ;; Build system used to "convert" a channel to a package.
+  (let* ((build (lambda* (name inputs
+                               #:key channel system
+                               #:allow-other-keys)
+                  (mlet* %store-monad ((instance
+                                        ((store-lift latest-channel-instance)
+                                         channel
+                                         #:authenticate? #f
+                                         #:validate-pull (lambda (. rest) #t))))
+                    (build-from-source instance #:system system))))
+         (lower (lambda* (name #:key system channel
+                               #:allow-other-keys)
+                  (bag
+                    (name name)
+                    (system system)
+                    (build build)
+                    (arguments `(#:channel ,channel))))))
+    (build-system (name 'channel)
+                  (description "Turn a channel into a package.")
+                  (lower lower))))
+
 (define channel-profile-build-system
   ;; Build system used to "convert" a channel instance to a profile, in
   ;; package form.
-- 
2.34.0





  parent reply	other threads:[~2022-02-14  9:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12 16:23 bug#53210: installer: referring to N-1 guix is problematic Mathieu Othacehe
2022-01-12 17:41 ` Ludovic Courtès
2022-02-14  9:29   ` bug#53210: [WIP PATCH 0/4] Make current-guix work when run outside a Git checkout Josselin Poiret via Bug reports for GNU Guix
2022-02-14  9:29     ` bug#53210: [WIP PATCH 1/4] gnu: ci: Move generic channel building code Josselin Poiret via Bug reports for GNU Guix
2022-02-14 17:12       ` Ludovic Courtès
2022-02-14  9:29     ` bug#53210: [WIP PATCH 2/4] gnu: Rename channel-build-system and channel-source->package Josselin Poiret via Bug reports for GNU Guix
2022-07-18 19:35       ` bug#53210: installer: referring to N-1 guix is problematic Ludovic Courtès
2022-02-14  9:29     ` Josselin Poiret via Bug reports for GNU Guix [this message]
2022-02-14 17:15       ` bug#53210: [WIP PATCH 3/4] gnu: current-guix: Support when running outside a checkout Ludovic Courtès
2022-02-14  9:29     ` bug#53210: [WIP PATCH 4/4] gnu: package-management: Memoize current-guix Josselin Poiret via Bug reports for GNU Guix
2022-02-14 17:10     ` bug#53210: [WIP PATCH 0/4] Make current-guix work when run outside a Git checkout Ludovic Courtès
2022-08-09 13:26     ` bug#53210: installer: referring to N-1 guix is problematic Ludovic Courtès
2022-08-09 19:17       ` Josselin Poiret via Bug reports for GNU Guix
2022-08-10 10:13       ` Mathieu Othacehe
2022-08-11 14:03         ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220214092908.16801-4-dev@jpoiret.xyz \
    --to=bug-guix@gnu.org \
    --cc=53210@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=ludo@gnu.org \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.