unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Apply a patch to a given package definition
@ 2024-08-19  8:19 Christoph Buck
  2024-08-19 23:02 ` Ian Eure
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Buck @ 2024-08-19  8:19 UTC (permalink / raw)
  To: help-guix

Hi!

How do i define a new package which is just a variation of a given
package defined in guix?

In my concrete example i try to add a new board definition file via a
patch to the u-boot bootloader. What i come up with, looks like this:

```
;; Defines a package ub which will compile u-boot for the
;; `new-cool-board` description file

(define ub (make-u-boot-package "new-cool-board" "arm-linux-gnueabihf"))

(define-public u-boot-new-cool-board-arm
  (package
    (inherit ub)
    (version "2024.01")
    (source (origin
              (patches '("0001-Add-board-description-for-new-cool-board.patch"))
              (method url-fetch)
              (uri (string-append
                    "https://ftp.denx.de/pub/u-boot/"
                    "u-boot-" version ".tar.bz2"))
              (sha256
               (base32
                "1czmpszalc6b8cj9j7q6cxcy19lnijv3916w3dag6yr3xpqi35mr"))))))

```

I create a u-boot variant for my "new-cool-board" using the build in
`make-u-boot-package` function, then i define a new package and inherit
from the package variant created with the `make-u-boot-package`
function. Then i overwrite `source` entry with an entry which also
applies my patch file. This works, however the original u-boot package
also apply some patches, which are now lost and must manually added by
me again. This seems rather error prone. Is there a better solution?

I saw that you can also apply patches via package transformation, but i
can't get it to work. I have tried the following:

```test.scm

(define u-boot-new-cool-board
  (make-u-boot-package "new-cool-board" "arm-linux-gnueabihf"))

(define transform
  (options->transformation
   '((with-patch
   . "u-boot-new-cool-board=/home/icepic/guix/raspberry/touchscreen/0001-Add-board-description-for-new-cool-board.patch"))))

(transform u-boot-new-cool-board)

```

If i now build the test.scm with

`guix build -f test.scm --target=arm-linux-gnueabihf -v3 -K`

my patch is not applied and the build fails, because there is no target
for "new-cool-board".

Thanks for your help!


-- 
Best regards

Christoph


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

* Re: Apply a patch to a given package definition
  2024-08-19  8:19 Apply a patch to a given package definition Christoph Buck
@ 2024-08-19 23:02 ` Ian Eure
  2024-08-20  9:15   ` Christoph Buck
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Eure @ 2024-08-19 23:02 UTC (permalink / raw)
  To: Christoph Buck; +Cc: help-guix

Hi Christoph,

Christoph Buck <dev@icepic.de> writes:

> Hi!
>
> How do i define a new package which is just a variation of a 
> given
> package defined in guix?
>
> In my concrete example i try to add a new board definition file 
> via a
> patch to the u-boot bootloader. What i come up with, looks like 
> this:
>
> ```
> ;; Defines a package ub which will compile u-boot for the
> ;; `new-cool-board` description file
>
> (define ub (make-u-boot-package "new-cool-board" 
> "arm-linux-gnueabihf"))
>
> (define-public u-boot-new-cool-board-arm
>   (package
>     (inherit ub)
>     (version "2024.01")
>     (source (origin
>               (patches 
>               '("0001-Add-board-description-for-new-cool-board.patch"))
>               (method url-fetch)
>               (uri (string-append
>                     "https://ftp.denx.de/pub/u-boot/"
>                     "u-boot-" version ".tar.bz2"))
>               (sha256
>                (base32
>                 "1czmpszalc6b8cj9j7q6cxcy19lnijv3916w3dag6yr3xpqi35mr"))))))
>
> ```
>
> I create a u-boot variant for my "new-cool-board" using the 
> build in
> `make-u-boot-package` function, then i define a new package and 
> inherit
> from the package variant created with the `make-u-boot-package`
> function. Then i overwrite `source` entry with an entry which 
> also
> applies my patch file. This works, however the original u-boot 
> package
> also apply some patches, which are now lost and must manually 
> added by
> me again. This seems rather error prone. Is there a better 
> solution?
>

You can have your source inherit from the original package’s, but 
with modifications -- just like the package itself.  This might 
not be exaxtly right, but should give you the right idea:

    (define-public u-boot-new-cool-board-arm
      (package
        (inherit ub)
        (version "2024.01")
        (source
         (origin
           (inherit (package-source ub))
           (patches (append (origin-patches (package-source ub))
                            '("0001-Add-board-description-for-new-cool-board.patch")))))))

Any fields you don’t want to modify will be inherited, so you may 
be able to eliminate the version field as well.

  — Ian


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

* Re: Apply a patch to a given package definition
  2024-08-19 23:02 ` Ian Eure
@ 2024-08-20  9:15   ` Christoph Buck
  2024-08-20 21:15     ` Ian Eure
  2024-08-27 14:19     ` Simon Tournier
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Buck @ 2024-08-20  9:15 UTC (permalink / raw)
  To: Ian Eure; +Cc: help-guix

Hi Ian!

> You can have your source inherit from the original package’s, but with
> modifications -- just like the package itself.  This might not be
> exaxtly right, but should give you the right idea:
>
>    (define-public u-boot-new-cool-board-arm
>      (package
>        (inherit ub)
>        (version "2024.01")
>        (source
>         (origin
>           (inherit (package-source ub))
>           (patches (append (origin-patches (package-source ub))
>                            '("0001-Add-board-description-for-new-cool-board.patch")))))))
>
> Any fields you don’t want to modify will be inherited, so you may be
> able to eliminate the version field as well.

Oh i didn't know i can use inherit for all all (?) record types. On
hindsight it is pretty obvious. Thanks! Your solution works perfect!


By chance, do you know if a transformation would also work and if so,
how?

Thanks

Christoph

-- 
Best regards

Christoph


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

* Re: Apply a patch to a given package definition
  2024-08-20  9:15   ` Christoph Buck
@ 2024-08-20 21:15     ` Ian Eure
  2024-08-27 14:19     ` Simon Tournier
  1 sibling, 0 replies; 5+ messages in thread
From: Ian Eure @ 2024-08-20 21:15 UTC (permalink / raw)
  To: Christoph Buck; +Cc: help-guix

Hi Cristoph,

Christoph Buck <dev@icepic.de> writes:

> Hi Ian!
>
>> You can have your source inherit from the original package’s, 
>> but with
>> modifications -- just like the package itself.  This might not 
>> be
>> exaxtly right, but should give you the right idea:
>>
>>    (define-public u-boot-new-cool-board-arm
>>      (package
>>        (inherit ub)
>>        (version "2024.01")
>>        (source
>>         (origin
>>           (inherit (package-source ub))
>>           (patches (append (origin-patches (package-source ub))
>>                            '("0001-Add-board-description-for-new-cool-board.patch")))))))
>>
>> Any fields you don’t want to modify will be inherited, so you 
>> may be
>> able to eliminate the version field as well.
>
> Oh i didn't know i can use inherit for all all (?) record 
> types. On
> hindsight it is pretty obvious. Thanks! Your solution works 
> perfect!
>

Yes, it’s very handy.  I’m glad my suggestion was helpful.

>
> By chance, do you know if a transformation would also work and 
> if so,
> how?
>

I’ve never messed with package transformations, so I don’t know.

Thanks,

  — Ian


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

* Re: Apply a patch to a given package definition
  2024-08-20  9:15   ` Christoph Buck
  2024-08-20 21:15     ` Ian Eure
@ 2024-08-27 14:19     ` Simon Tournier
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Tournier @ 2024-08-27 14:19 UTC (permalink / raw)
  To: Christoph Buck, Ian Eure; +Cc: help-guix

Hi,

On Tue, 20 Aug 2024 at 11:15, Christoph Buck <dev@icepic.de> wrote:

> By chance, do you know if a transformation would also work and if so,
> how?

Yes.  Roughly and quickly, ’inherit’ is only a macro that copies all the
record fields. Other said,

        (package
          (inherit foo)
           …)

creates a new ’package’ record where all the fields of ’foo’ are copied
expect the ones defined by ’…’.  Therefore, that defines a package and
this package can be manipulated as any other packages.


At the command-line, the derivations of one package and the same with
a transformation.

--8<---------------cut here---------------start------------->8---
$ guix build -d hello
/gnu/store/qr00sgbh3vwwqswmgjjymg6wkys9r4i2-hello-2.12.1.drv

$ guix build -d hello --without-tests=hello
/gnu/store/rfxhb9z4vrdp1hhhq96qh13wyfkrmapf-hello-2.12.1.drv
--8<---------------cut here---------------end--------------->8---

Using the REPL, let start with the case where all the fields are copied
without any modification.

--8<---------------cut here---------------start------------->8---
$ guix repl
GNU Guile 3.0.9
Copyright (C) 1995-2023 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guix-user)> ,use(gnu packages base)
scheme@(guix-user)> ,use(guix packages)
scheme@(guix-user)> (define hey (package (inherit hello)))
scheme@(guix-user)> hey
$1 = #<package hello@2.12.1 7ee70718a790>
--8<---------------cut here---------------end--------------->8---

As you can see, the variable ’hey’ is just a ’package’.  And since all
the record fields are the same as the ones of ’hello’, the both
derivations are exactly the same.

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,lower hey
$2 = #<derivation /gnu/store/qr00sgbh3vwwqswmgjjymg6wkys9r4i2-hello-2.12.1.drv => /gnu/store/6fbh8phmp3izay6c0dpggpxhcjn4xlm5-hello-2.12.1 7ee6f93cd050>
scheme@(guix-user)> ,lower hello
$3 = #<derivation /gnu/store/qr00sgbh3vwwqswmgjjymg6wkys9r4i2-hello-2.12.1.drv => /gnu/store/6fbh8phmp3izay6c0dpggpxhcjn4xlm5-hello-2.12.1 7ee6f93cd050>
--8<---------------cut here---------------end--------------->8---

So far so good!  Now, let apply some transformation as described in the
manual by “(guix) Defining Package Variants” [1].

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> ,use(guix transformations)
scheme@(guix-user)> (define (transform p) ((options->transformation `((without-tests . ,(package-name p)))) p))
scheme@(guix-user)> (package-arguments (transform hey))
$4 = (#:tests? #f)
--8<---------------cut here---------------end--------------->8---

And the derivation reads:

--8<---------------cut here---------------start------------->8---
scheme@(guix-user)> (transform hey)
$5 = #<package hello@2.12.1 guix/transformations.scm:1098 7ee7071856e0>
scheme@(guix-user)> ,lower $5
$6 = #<derivation /gnu/store/rfxhb9z4vrdp1hhhq96qh13wyfkrmapf-hello-2.12.1.drv => /gnu/store/w6003221bya21djwrbp9adqyykhsljii-hello-2.12.1 7ee6f8921550>
--8<---------------cut here---------------end--------------->8---

Which is the same as above.

Hope that helps,
simon

1: https://guix.gnu.org/manual/devel/en/guix.html#Defining-Package-Variants


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

end of thread, other threads:[~2024-08-27 14:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-19  8:19 Apply a patch to a given package definition Christoph Buck
2024-08-19 23:02 ` Ian Eure
2024-08-20  9:15   ` Christoph Buck
2024-08-20 21:15     ` Ian Eure
2024-08-27 14:19     ` Simon Tournier

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).