unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How can I set architecture/system-specific origin sources?
@ 2019-12-31 11:30 Pierre Neidhardt
  2019-12-31 12:06 ` Mathieu Othacehe
  0 siblings, 1 reply; 7+ messages in thread
From: Pierre Neidhardt @ 2019-12-31 11:30 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1920 bytes --]

Hi!

I'd like to write a package definition whose source is different
depending on the system / arch it is built for.

I thought of writing something like this:

--8<---------------cut here---------------start------------->8---
(source (origin
         (method url-fetch)
         (uri
          (string-append "http://foo.bar/"
                         version "-" 
                         (match (or (%current-target-system)
                                    (%current-system))
                           ("i686-linux" "x86")
                           ("x86_64-linux" "x86_64"))
                         ".tgz"))
         (sha256
          (base32
           (match (or (%current-target-system)
                      (%current-system))
             ("x86_64-linux"
              "0y4qms4lm9xiix93g45337rx5nrp0y3gb0x0avyv7l9qrkk03zz8")
             ("i686-linux"
              "0yc8n6vpqyb6qhcv5kwvr3h21ya271fi930fvd98hlkg8cg5kwyf"))))))
--8<---------------cut here---------------end--------------->8---

My laptop is a x86_64-linux and the above definition always uses the
x86_64 source, even with

  guix build --system=i686-linux foo

In Nix, the following works:

--8<---------------cut here---------------start------------->8---
  src =
    if stdenv.hostPlatform.system == "x86_64-linux" then
      fetchurl {
        url = "http://foo.bar/...";
        sha256 = "e8ff01e6cc38d1b3fd56a083f5860737dbd2f319a39037528fb1a74a89ae9878";
      }
    else if stdenv.hostPlatform.system == "i686-linux" then
      fetchurl {
        url = "http://foo.bar/...";
        sha256 = "cef3591e436f528852db0e8c145d3842f920e0c89bcfb219c466797cb7b18879";
      }
    else throw "foo does not support platform ${stdenv.hostPlatform.system}";
--8<---------------cut here---------------end--------------->8---

Is this a Guix bug?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* Re: How can I set architecture/system-specific origin sources?
  2019-12-31 11:30 How can I set architecture/system-specific origin sources? Pierre Neidhardt
@ 2019-12-31 12:06 ` Mathieu Othacehe
  2019-12-31 14:00   ` Pierre Neidhardt
  2020-01-02 22:16   ` Ludovic Courtès
  0 siblings, 2 replies; 7+ messages in thread
From: Mathieu Othacehe @ 2019-12-31 12:06 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: guix-devel


Hello Pierre,

>
> My laptop is a x86_64-linux and the above definition always uses the
> x86_64 source, even with
>
>   guix build --system=i686-linux foo
>
> In Nix, the following works:
>
> --8<---------------cut here---------------start------------->8---
>   src =
>     if stdenv.hostPlatform.system == "x86_64-linux" then
>       fetchurl {
>         url = "http://foo.bar/...";
>         sha256 = "e8ff01e6cc38d1b3fd56a083f5860737dbd2f319a39037528fb1a74a89ae9878";
>       }
>     else if stdenv.hostPlatform.system == "i686-linux" then
>       fetchurl {
>         url = "http://foo.bar/...";
>         sha256 = "cef3591e436f528852db0e8c145d3842f920e0c89bcfb219c466797cb7b18879";
>       }
>     else throw "foo does not support platform ${stdenv.hostPlatform.system}";
> --8<---------------cut here---------------end--------------->8---
>
> Is this a Guix bug?

Well, it's not really a bug, but quite suprising at first. If you look
at the definition of <package> in (guix packages), you'll see that some
fields are (thunked). %current-system and %current-target-system will
only return valid results in (thunked) fields.

As "source" is not thunked, you can make it thunked, but it can hurt
performances. You can also make multiple packages for each architecture,
and use them as inputs conditionned by %current-system and
%current-target-system.

Mathieu

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

* Re: How can I set architecture/system-specific origin sources?
  2019-12-31 12:06 ` Mathieu Othacehe
@ 2019-12-31 14:00   ` Pierre Neidhardt
  2020-01-01 12:22     ` Efraim Flashner
  2020-01-02 22:16   ` Ludovic Courtès
  1 sibling, 1 reply; 7+ messages in thread
From: Pierre Neidhardt @ 2019-12-31 14:00 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

Hi Mathieu!

Thanks for the details, this makes much more sense now! :)
So how can I thunk the source field then?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* Re: How can I set architecture/system-specific origin sources?
  2019-12-31 14:00   ` Pierre Neidhardt
@ 2020-01-01 12:22     ` Efraim Flashner
  2020-01-02 11:21       ` Pierre Neidhardt
  0 siblings, 1 reply; 7+ messages in thread
From: Efraim Flashner @ 2020-01-01 12:22 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 590 bytes --]

On Tue, Dec 31, 2019 at 03:00:50PM +0100, Pierre Neidhardt wrote:
> Hi Mathieu!
> 
> Thanks for the details, this makes much more sense now! :)
> So how can I thunk the source field then?
> 

There's computed-origin-method that's floating around a couple of
package modules or you can look at something like ghc which has a
different blessed binary per-architecture.

-- 
Efraim Flashner   <efraim@flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: How can I set architecture/system-specific origin sources?
  2020-01-01 12:22     ` Efraim Flashner
@ 2020-01-02 11:21       ` Pierre Neidhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Pierre Neidhardt @ 2020-01-02 11:21 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

Thank you Efraim, this is exactly what I needed.  I've applied the trick
used by GHC (simpler in my opinion), it works perfectly.

As Mathieu pointed out, this is a bit unsettling at first.  Is this
(thunked) behaviour documented anywhere?  If not, shall we documented
it?  Where?

Cheers!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

* Re: How can I set architecture/system-specific origin sources?
  2019-12-31 12:06 ` Mathieu Othacehe
  2019-12-31 14:00   ` Pierre Neidhardt
@ 2020-01-02 22:16   ` Ludovic Courtès
  2020-01-02 22:33     ` Pierre Neidhardt
  1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2020-01-02 22:16 UTC (permalink / raw)
  To: Mathieu Othacehe; +Cc: guix-devel

Hi,

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> Well, it's not really a bug, but quite suprising at first. If you look
> at the definition of <package> in (guix packages), you'll see that some
> fields are (thunked). %current-system and %current-target-system will
> only return valid results in (thunked) fields.
>
> As "source" is not thunked, you can make it thunked, but it can hurt
> performances. You can also make multiple packages for each architecture,
> and use them as inputs conditionned by %current-system and
> %current-target-system.

I should say that it’s because source is architecture-independent.  :-)

The package definition for ‘mit-scheme’, for example, passes the
bootstrap binaries, which are architecture-dependent, as inputs.

Ludo’.

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

* Re: How can I set architecture/system-specific origin sources?
  2020-01-02 22:16   ` Ludovic Courtès
@ 2020-01-02 22:33     ` Pierre Neidhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Pierre Neidhardt @ 2020-01-02 22:33 UTC (permalink / raw)
  To: Ludovic Courtès, Mathieu Othacehe; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 340 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> I should say that it’s because source is architecture-independent.  :-)
>
> The package definition for ‘mit-scheme’, for example, passes the
> bootstrap binaries, which are architecture-dependent, as inputs.

Yes, that makes sense! :)

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

end of thread, other threads:[~2020-01-02 22:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-31 11:30 How can I set architecture/system-specific origin sources? Pierre Neidhardt
2019-12-31 12:06 ` Mathieu Othacehe
2019-12-31 14:00   ` Pierre Neidhardt
2020-01-01 12:22     ` Efraim Flashner
2020-01-02 11:21       ` Pierre Neidhardt
2020-01-02 22:16   ` Ludovic Courtès
2020-01-02 22:33     ` Pierre Neidhardt

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