unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* (almost) deterministic patchsets
@ 2024-02-13 13:35 Nicolas Graves via Development of GNU Guix and the GNU System distribution.
  2024-02-24 23:05 ` Nicolas Graves via Development of GNU Guix and the GNU System distribution.
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Graves via Development of GNU Guix and the GNU System distribution. @ 2024-02-13 13:35 UTC (permalink / raw)
  To: guix-devel


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-10 22:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-13 13:35 (almost) deterministic patchsets Nicolas Graves via Development of GNU Guix and the GNU System distribution.
2024-02-24 23:05 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).