guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(almost) deterministic patchsets


From: Nicolas Graves
Subject: (almost) deterministic patchsets
Date: Tue, 13 Feb 2024 14:35:17 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]