GNU bug report logs - #57722
[PATCH] gnu: ipfs: Install bash completion.

Previous Next

Package: guix-patches;

Reported by: Michael Rohleder <mike <at> rohleder.de>

Date: Sat, 10 Sep 2022 21:49:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 57722 in the body.
You can then email your comments to 57722 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Sat, 10 Sep 2022 21:49:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michael Rohleder <mike <at> rohleder.de>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sat, 10 Sep 2022 21:49:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Rohleder <mike <at> rohleder.de>
To: guix-patches <at> gnu.org
Cc: Michael Rohleder <mike <at> rohleder.de>
Subject: [PATCH] gnu: ipfs: Install bash completion.
Date: Sat, 10 Sep 2022 23:47:21 +0200
* gnu/packages/ipfs.scm (ipfs)[arguments]: Add 'install-bashcompletion
phase to install bash completion.
---
 gnu/packages/ipfs.scm | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/ipfs.scm b/gnu/packages/ipfs.scm
index ccc36007b4..faa209bf2a 100644
--- a/gnu/packages/ipfs.scm
+++ b/gnu/packages/ipfs.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2018 Pierre Neidhardt <mail <at> ambrevar.xyz>
 ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me <at> tobias.gr>
 ;;; Copyright © 2019, 2020 Martin Becze <mjbecze <at> riseup.net>
-;;; Copyright © 2020, 2021 Michael Rohleder <mike <at> rohleder.de>
+;;; Copyright © 2020, 2021, 2022 Michael Rohleder <mike <at> rohleder.de>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -230,7 +230,26 @@ (define-public go-ipfs
     (build-system go-build-system)
     (arguments
      `(#:unpack-path "github.com/ipfs/go-ipfs"
-       #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs"))
+       #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs"
+       #:modules ((guix build utils)
+                  (guix build go-build-system)
+                  (ice-9 popen)
+                  (ice-9 textual-ports))
+       #:phases
+       (modify-phases %standard-phases
+         ;; https://github.com/ipfs/kubo/blob/master/docs/command-completion.md
+         (add-after 'install 'install-bashcompletion
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (completiondir (string-append out "/etc/bash_completion.d")))
+               (mkdir-p completiondir)
+               (call-with-output-file (string-append completiondir "/ipfs")
+                 (lambda (port)
+                   (let ((input-pipe (open-pipe* OPEN_READ
+                                                 (string-append out "/bin/ipfs")
+                                                 "commands" "completion" "bash")))
+                     (display (get-string-all input-pipe) port)
+                     (close-pipe input-pipe))))))))))
     (native-inputs
      (list python-minimal-wrapper zsh))
     (home-page "https://ipfs.io")
-- 
2.37.3





Information forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Sun, 11 Sep 2022 11:49:02 GMT) Full text and rfc822 format available.

Message #8 received at 57722 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Michael Rohleder <mike <at> rohleder.de>, 57722 <at> debbugs.gnu.org
Subject: Re: [bug#57722] [PATCH] gnu: ipfs: Install bash completion.
Date: Sun, 11 Sep 2022 13:47:58 +0200
[Message part 1 (text/plain, inline)]

On 10-09-2022 23:47, Michael Rohleder wrote:
> +           (lambda* (#:key inputs outputs #:allow-other-keys)

'inputs' is unused.

> +             (let* ((out (assoc-ref outputs "out"))
> +                    (completiondir (string-append out "/etc/bash_completion.d")))

#$output can be used nowadays instead of (assoc-ref outputs "out"). 
Then 'outputs' would be unused as well and the lambda can be simplified 
to (lambda _ [...]).

> +               (mkdir-p completiondir)
> +               (call-with-output-file (string-append completiondir "/ipfs")
> +                 (lambda (port)
> +                   (let ((input-pipe (open-pipe* OPEN_READ
> +                                                 (string-append out "/bin/ipfs")
> +                                                 "commands" "completion" "bash")))
> +                     (display (get-string-all input-pipe) port)
> +                     (close-pipe input-pipe))))))))))

Can be simplified to

  (with-output-to-file (string-append completiondir "/ipfs")
    (invoke (string-append out "/bin/ipfs")
            "commands" "completion" "bash"))

(untested)

When cross-compiling, the cross-compiled bin/ipfs cannot be run.  To 
solve this, you can add 'this-package' to the native-inputs conditional 
upon (%current-target-system):

 (native-inputs
    (append
      (if (%current-target-system)
          (list this-package)
          '())
      (list python-minimal-wrapper zsh))).

and in the build phase, do two separate cases: when compiling natively, 
use the ipfs from #$output as you're doing, when cross-compiling, use 
the ipfs from $PATH:

  (with-output-to-file (string-append completiondir "/ipfs")
    (invoke #$(if (%current-target-system)
                  "ipfs"
                  #~(string-append #$output "/bin/ipfs"))
            "commands" "completion" "bash"))

Greetings,
Maxime.
[OpenPGP_0x49E3EE22191725EE.asc (application/pgp-keys, attachment)]
[OpenPGP_signature (application/pgp-signature, attachment)]

Information forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Mon, 12 Sep 2022 11:22:02 GMT) Full text and rfc822 format available.

Message #11 received at 57722 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Michael Rohleder <mike <at> rohleder.de>, 57722 <at> debbugs.gnu.org
Subject: Re: [bug#57722] [PATCH] gnu: ipfs: Install bash completion.
Date: Mon, 12 Sep 2022 13:21:00 +0200
[Message part 1 (text/plain, inline)]

On 11-09-2022 13:47, Maxime Devos wrote:
> 
> and in the build phase, do two separate cases: when compiling natively, 
> use the ipfs from #$output as you're doing, when cross-compiling, use 
> the ipfs from $PATH:
> 
>    (with-output-to-file (string-append completiondir "/ipfs")
>      (invoke #$(if (%current-target-system)
>                    "ipfs"
>                    #~(string-append #$output "/bin/ipfs"))
>              "commands" "completion" "bash"))
> 

Oops that incorrect, with-output-to-file is not a macro but a procedure 
accepting a thunk, try

(with-output-to-file [...]
  (lambda ()
    (invoke ...)))

instead.
[OpenPGP_0x49E3EE22191725EE.asc (application/pgp-keys, attachment)]
[OpenPGP_signature (application/pgp-signature, attachment)]

Information forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Tue, 13 Sep 2022 09:52:02 GMT) Full text and rfc822 format available.

Message #14 received at 57722 <at> debbugs.gnu.org (full text, mbox):

From: Michael Rohleder <mike <at> rohleder.de>
To: Maxime Devos <maximedevos <at> telenet.be>
Cc: 57722 <at> debbugs.gnu.org
Subject: Re: [bug#57722] [PATCH] gnu: ipfs: Install bash completion.
Date: Tue, 13 Sep 2022 11:49:57 +0200
[Message part 1 (text/plain, inline)]
Hey Maxime,

Thank you for reviewing and your helpful tips!

Here is a second version, I hope it's better.

I dont know how to test cross compiling, though (on a x86_64 system):

./pre-inst-env guix build --system=aarch64-linux go-ipfs
[...]
building /gnu/store/ssvif7gdgv7xn7jmgmcp4ws71fgmwn5x-go-ipfs-0.11.0.drv...
;;; Stat of /tmp/guix-build-go-ipfs-0.11.0.drv-0/guile failed:
;;; In procedure stat: No such file or directory: "/tmp/guix-build-go-ipfs-0.11.0.drv-0/guile"
Backtrace:
           0 (primitive-load "/tmp/guix-build-go-ipfs-0.11.0.drv-0/g?")

ERROR: In procedure primitive-load:
In procedure open-file: No such file or directory: "/tmp/guix-build-go-ipfs-0.11.0.drv-0/guile"

And then I'm completely lost and confused. ;)

[0001-gnu-go-ipfs-Install-bash-completion.patch (text/x-patch, attachment)]
[Message part 3 (text/plain, inline)]
-- 
Nichts ist in der Welt ist so gerecht verteilt wie der Verstand. 
Jedermann ist der Meinung, dass er genuegend davon hat.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Tue, 13 Sep 2022 10:49:02 GMT) Full text and rfc822 format available.

Message #17 received at 57722 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Michael Rohleder <mike <at> rohleder.de>
Cc: 57722 <at> debbugs.gnu.org
Subject: Re: [bug#57722] [PATCH] gnu: ipfs: Install bash completion.
Date: Tue, 13 Sep 2022 12:48:51 +0200
[Message part 1 (text/plain, inline)]

On 13-09-2022 11:49, Michael Rohleder wrote:
> I dont know how to test cross compiling, though (on a x86_64 system):
> 
> ./pre-inst-env guix build --system=aarch64-linux go-ipfs
> [...]

That's (emulated) native compilation (which requires setting up QEMU 
transparent emulation), not cross-compilation.  While they can 
accomplish the same result, they function completely different -- from 
Guix POV, emulated builds are just native (non-cross-compiling) builds.

Instead, try

./pre-inst-env guix build --target=aarch64-linux-gnu go-ipfs

... which will fail because the imported-modules aren't imported, which 
is a bug (I'll report it).

Greetings,
Maxime.
[OpenPGP_0x49E3EE22191725EE.asc (application/pgp-keys, attachment)]
[OpenPGP_signature (application/pgp-signature, attachment)]

Information forwarded to guix-patches <at> gnu.org:
bug#57722; Package guix-patches. (Tue, 13 Sep 2022 11:03:01 GMT) Full text and rfc822 format available.

Message #20 received at 57722 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: Michael Rohleder <mike <at> rohleder.de>
Cc: 57722 <at> debbugs.gnu.org
Subject: Re: [bug#57722] [PATCH] gnu: ipfs: Install bash completion.
Date: Tue, 13 Sep 2022 13:02:42 +0200
[Message part 1 (text/plain, inline)]

On 13-09-2022 12:48, Maxime Devos wrote:
> [...]
> 
> ./pre-inst-env guix build --target=aarch64-linux-gnu go-ipfs
> 
> ... which will fail because the imported-modules aren't imported, which 
> is a bug (I'll report it).

See: <https://issues.guix.gnu.org/57766>.

> Greetings,
> Maxime.
[OpenPGP_0x49E3EE22191725EE.asc (application/pgp-keys, attachment)]
[OpenPGP_signature (application/pgp-signature, attachment)]

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Wed, 14 Sep 2022 21:30:02 GMT) Full text and rfc822 format available.

Notification sent to Michael Rohleder <mike <at> rohleder.de>:
bug acknowledged by developer. (Wed, 14 Sep 2022 21:30:02 GMT) Full text and rfc822 format available.

Message #25 received at 57722-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Michael Rohleder <mike <at> rohleder.de>
Cc: 57722-done <at> debbugs.gnu.org, Maxime Devos <maximedevos <at> telenet.be>
Subject: Re: bug#57722: [PATCH] gnu: ipfs: Install bash completion.
Date: Wed, 14 Sep 2022 23:29:25 +0200
Michael Rohleder <mike <at> rohleder.de> skribis:

> From bbf32c53a2402f6f123d00d2e5ece9efdbf10504 Mon Sep 17 00:00:00 2001
> From: Michael Rohleder <mike <at> rohleder.de>
> Date: Tue, 13 Sep 2022 11:29:23 +0200
> Subject: [PATCH] gnu: go-ipfs: Install bash completion.
>
> * gnu/packages/ipfs.scm (go-ipfs)[arguments]: Use gexp.
> Add 'install-bashcompletion phase to install bash completion.

Applied, thanks!

Great that Maxime found a bug as a side effect.  :-)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 13 Oct 2022 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 167 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.