all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicolas Graves via "Development of GNU Guix and the GNU System distribution." <guix-devel@gnu.org>
To: guix-devel@gnu.org
Subject: (almost) deterministic patchsets
Date: Tue, 13 Feb 2024 14:35:17 +0100	[thread overview]
Message-ID: <87le7owkq2.fsf@ngraves.fr> (raw)


Hi !

I've written this (gpl3+) that should be able to fetch patchsets for
both guix and rde. This should be robust enough for guix/rde use IMO.

(define-module (guix mbox-download)
  #:use-module (guix packages)
  #:use-module ((guix self) #:select (make-config.scm))
  #:use-module (guix modules)
  #:use-module (guix monads)
  #:use-module (gnu packages guile)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages version-control)
  #:use-module (guix store)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:export (mbox-fetch
            mbox-reference))

(define-record-type* <mbox-reference>
  mbox-reference make-mbox-reference
  mbox-reference?
  (type mbox-reference-type)
  (id mbox-reference-id)
  (version mbox-reference-version))

(define* (mbox-fetch ref hash-algo hash #:optional name
                     #:key (system %current-system) guile)

  (define uri
    (format
     #f
     (assoc-ref
      '((gnu . "https://debbugs.gnu.org/cgi-bin/bugreport.cgi?bug=~a;mbox=yes")
        (rde . "https://lists.sr.ht/~~abcdw/rde-devel/patches/~a/mbox"))
       (mbox-reference-type ref))
     (mbox-reference-id ref)))

  (define modules
    (cons `((guix config) => ,(make-config.scm))
          (delete '(guix config)
                  (source-module-closure '((guix build download)
                                           (guix build utils))))))

  (define build
    (with-extensions (list guile-json-4 guile-gnutls)
      (with-imported-modules modules
        #~(begin
            (use-modules (guix build utils) (guix build download))
            (let ((mbox #$(match-record ref <mbox-reference>
                                        (type id version)
                            (format #f "~a-~a-~a.mbx" type id version))))
              (setenv "TMPDIR" (getcwd))
              (setenv "XDG_DATA_HOME" (getcwd))
              (invoke #$(file-append b4 "/bin/b4")
                      "-d" "-n" "--offline-mode" "--no-stdin"
                      "am" "--no-cover" "--no-cache"
                      "--use-local-mbox"
                      (url-fetch #$uri "mbox" #:verify-certificate? #f)
                      "--use-version"
                      (number->string #$(mbox-reference-version ref))
                      "--no-add-trailers"
                      "--outdir" "."
                      "--mbox-name" mbox)
              (install-file mbox #$output))))))

  (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
                                                  system)))
    (gexp->derivation (or name
                          (match-record ref <mbox-reference>
                                        (type id version)
                            (format #f "~a-~a-~a-mbox" type id version)))
      build
      ;; Use environment variables and a fixed script name so
      ;; there's only one script in store for all the
      ;; downloads.
      #:system system
      #:local-build? #t ;don't offload repo cloning
      #:hash-algo hash-algo
      #:hash hash
      #:recursive? #t
      #:guile-for-build guile)))


This can be used in such an example :

(use-modules (guix mbox-download) (guix packages) (guix gexp)
             (guix monads) (guix store) (guix derivations))

(with-store store
  (run-with-store store
    (mlet* %store-monad
        ((drv (origin->derivation
               (pk 'o (origin
                        (method mbox-fetch)
                        (uri (mbox-reference
                              (type 'rde)
                              (id 44893)
                              (version 4)))
                        (sha256
                         (base32 "1rs09wxvdaxrk2zh6g23s9min76wjm9lw0a5pjklc7cfraasi7s9")))))))
      (return drv))))

Is guix interested in this, should I send a patch? What about renaming
this to patchset-reference instead of mbox-reference?

My end-goal here is to use this to extend channels to channels with
patches, with something like this :

(define* (instantiate-channel ch)
  (match ch
    ((name url ref patches)
     (primitive-eval
      `(channel
        (name ',name)
        ,@(if (null? patches)
              `((url ,(find-home url)))
              `((url ,(patched-source
               (symbol->string name)
               (git-checkout
                (url (find-home url))
                (commit ref))
               (search-patches patches)))))
        ,@(if ((@ (guix git) commit-id?) ref)
              `((commit ,ref))
              `((branch ,ref)))
        (introduction ,(assoc-ref channels-introductions name)))))))

in the hypothesis where patched-source is exported from (guix transformations).

-- 
Best regards,
Nicolas Graves


             reply	other threads:[~2024-02-13 13:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 13:35 Nicolas Graves via Development of GNU Guix and the GNU System distribution. [this message]
2024-02-24 23:05 ` (almost) deterministic patchsets Nicolas Graves via Development of GNU Guix and the GNU System distribution.
2024-05-10 11:46   ` Nicolas Graves via Development of GNU Guix and the GNU System distribution.
2024-05-10 15:48     ` Richard Sent
2024-05-10 22:51       ` Ricardo Wurmus
2024-05-10 22:51       ` Ricardo Wurmus

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=87le7owkq2.fsf@ngraves.fr \
    --to=guix-devel@gnu.org \
    --cc=ngraves@ngraves.fr \
    /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.