[PATCH] gnu: ipfs: Install bash completion.

  • Done
  • quality assurance status badge
Details
3 participants
  • Ludovic Courtès
  • Maxime Devos
  • Michael Rohleder
Owner
unassigned
Submitted by
Michael Rohleder
Severity
normal

Debbugs page

Michael Rohleder wrote 3 years ago
(address . guix-patches@gnu.org)(name . Michael Rohleder)(address . mike@rohleder.de)
20220910214721.9993-1-mike@rohleder.de
* 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(-)

Toggle diff (43 lines)
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@ambrevar.xyz>
;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
-;;; Copyright © 2020, 2021 Michael Rohleder <mike@rohleder.de>
+;;; Copyright © 2020, 2021, 2022 Michael Rohleder <mike@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
Maxime Devos wrote 3 years ago
5d80a74a-fb2f-2236-a722-62e9d20b8487@telenet.be
On 10-09-2022 23:47, Michael Rohleder wrote:
Toggle quote (1 lines)
> + (lambda* (#:key inputs outputs #:allow-other-keys)
'inputs' is unused.
Toggle quote (2 lines)
> + (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 _ [...]).
Toggle quote (8 lines)
> + (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.
Attachment: OpenPGP_signature
Maxime Devos wrote 2 years ago
9f447f03-f1fe-30c9-bd7b-b0c490bc4999@telenet.be
On 11-09-2022 13:47, Maxime Devos wrote:
Toggle quote (11 lines)
>
> 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.
Attachment: OpenPGP_signature
Michael Rohleder wrote 2 years ago
(name . Maxime Devos)(address . maximedevos@telenet.be)(address . 57722@debbugs.gnu.org)
87k067ppru.fsf@rohleder.de
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. ;)
From bbf32c53a2402f6f123d00d2e5ece9efdbf10504 Mon Sep 17 00:00:00 2001
From: Michael Rohleder <mike@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.
---
gnu/packages/ipfs.scm | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

Toggle diff (55 lines)
diff --git a/gnu/packages/ipfs.scm b/gnu/packages/ipfs.scm
index ccc36007b4..d1e04c3ae0 100644
--- a/gnu/packages/ipfs.scm
+++ b/gnu/packages/ipfs.scm
@@ -2,7 +2,7 @@
;;; Copyright © 2018 Pierre Neidhardt <mail@ambrevar.xyz>
;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019, 2020 Martin Becze <mjbecze@riseup.net>
-;;; Copyright © 2020, 2021 Michael Rohleder <mike@rohleder.de>
+;;; Copyright © 2020, 2021, 2022 Michael Rohleder <mike@rohleder.de>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -22,6 +22,7 @@
(define-module (gnu packages ipfs)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
+ #:use-module (guix gexp)
#:use-module (guix git-download)
#:use-module (guix download)
#:use-module (guix build-system go)
@@ -229,10 +230,28 @@ (define-public go-ipfs
(file-name (string-append name "-" version "-source"))))
(build-system go-build-system)
(arguments
- `(#:unpack-path "github.com/ipfs/go-ipfs"
- #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs"))
+ (list
+ #:unpack-path "github.com/ipfs/go-ipfs"
+ #:import-path "github.com/ipfs/go-ipfs/cmd/ipfs"
+ #:phases
+ #~(modify-phases %standard-phases
+ ;; https://github.com/ipfs/kubo/blob/master/docs/command-completion.md
+ (add-after 'install 'install-bashcompletion
+ (lambda _
+ (let ((completiondir (string-append #$output
+ "/etc/bash_completion.d")))
+ (mkdir-p completiondir)
+ (with-output-to-file (string-append completiondir "/ipfs")
+ (lambda _
+ (invoke #$(if (%current-target-system)
+ "ipfs"
+ #~(string-append #$output "/bin/ipfs"))
+ "commands" "completion" "bash")))))))))
(native-inputs
- (list python-minimal-wrapper zsh))
+ (append (if (%current-target-system)
+ (list this-package)
+ '())
+ (list python-minimal-wrapper zsh)))
(home-page "https://ipfs.io")
(synopsis "Go implementation of IPFS, a peer-to-peer hypermedia protocol")
(description "IPFS is a global, versioned, peer-to-peer file system. It
--
2.37.3
--
Nichts ist in der Welt ist so gerecht verteilt wie der Verstand.
Jedermann ist der Meinung, dass er genuegend davon hat.
-----BEGIN PGP SIGNATURE-----

iQFFBAEBCAAvFiEEdV4t5dDVhcUueCgwfHr/vv7yyyUFAmMgUkURHG1pa2VAcm9o
bGVkZXIuZGUACgkQfHr/vv7yyyVrlwf/dGqZZQltkSkjBiZXlGSikHul2/r9xvLz
/MVyg2IZUmpygMXIqp1lfAn4SQYzsEzBwEfjdUecwV2YJ5XzA3q8tha0D4L59ctX
SGthJjQICRlAIqGj/TXBGrFjv7lLqPvYj2qanGhPaCTuWfUfjXjY03lLMKd2BzlG
32cTg/dDt0dzTN47X7zt1pXaSg2T/Xha39mlUoFetUsPiFBYGMLOC//5YZA+nxSv
X6/t5XNQdtx+duk0aS95DODO3CYOX4SH+agLdEAzQvOJb2TUbpqaZ/B+MHWs5zqq
LMedHzI7KKZ5niKmpUZbAcRcZDNb02N1w0GcnKY8DT2qJoTgSrZyLQ==
=wYfj
-----END PGP SIGNATURE-----

Maxime Devos wrote 2 years ago
(name . Michael Rohleder)(address . mike@rohleder.de)(address . 57722@debbugs.gnu.org)
89a2af02-9c06-a43b-a833-f6027dc4a5f2@telenet.be
On 13-09-2022 11:49, Michael Rohleder wrote:
Toggle quote (4 lines)
> 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.
Attachment: OpenPGP_signature
Maxime Devos wrote 2 years ago
(name . Michael Rohleder)(address . mike@rohleder.de)(address . 57722@debbugs.gnu.org)
d4c9028e-05e4-ae3b-6c46-b84d022ff78d@telenet.be
On 13-09-2022 12:48, Maxime Devos wrote:
Toggle quote (6 lines)
> [...]
>
> ./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).
Toggle quote (2 lines)
> Greetings,
> Maxime.
Attachment: OpenPGP_signature
Ludovic Courtès wrote 2 years ago
Re: bug#57722: [PATCH] gnu: ipfs: Install bash completion.
(name . Michael Rohleder)(address . mike@rohleder.de)
87r10dtzka.fsf_-_@gnu.org
Michael Rohleder <mike@rohleder.de> skribis:

Toggle quote (8 lines)
> From bbf32c53a2402f6f123d00d2e5ece9efdbf10504 Mon Sep 17 00:00:00 2001
> From: Michael Rohleder <mike@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. :-)
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 57722@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 57722
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help