diff mbox series

[bug#56770,v2] gnu: Add grimshot.

Message ID 20220726175817.422441-1-antero@mailbox.org
State Accepted
Headers show
Series [bug#56770,v2] gnu: Add grimshot. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Antero Mejr July 26, 2022, 5:58 p.m. UTC
* gnu/packages/wm.scm (grimshot): New variable.
---
changes for v2:
1. using copy-build-system instead of trivial-build-system because it is
simpler, copy-build-system handles unpacking the source
2. using snippet to delete the precompiled grimshot.1 (from review)
3. using this-package-input when substituting the script (from review)
4. using invoke to build man page (from review)
5. put inputs on separate lines (from guix style)

Maxime, this code: (source (file-append (package-source sway) "/contrib"))
didn't work for me, but inheriting the package source worked
with --with-git-url.

 gnu/packages/wm.scm | 65 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

Comments

M July 26, 2022, 6:17 p.m. UTC | #1
On 26-07-2022 19:58, Antero Mejr wrote:
> Maxime, this code: (source (file-append (package-source sway) "/contrib"))
> didn't work for me, but inheriting the package source worked
> with --with-git-url.

It works for me, see attachment (*). However, I've also tested out 
--with-git-url, and it appears that --with-git-url does work when using 
file-append, but the 'file-append' is removed, so I still don't think we 
should go for 'file-append' (unless you want to change --with-git-url to 
support file-append first).

(*) not properly styled, as "guix style" only supports packages, not files.

(Also, I'll write some other comments on the v2)

Greetings,
Maxime.
M July 26, 2022, 6:29 p.m. UTC | #2
On 26-07-2022 19:58, Antero Mejr wrote:
> * gnu/packages/wm.scm (grimshot): New variable.
> ---
> changes for v2:
> 1. using copy-build-system instead of trivial-build-system because it is
> simpler, copy-build-system handles unpacking the source
Now that you are using copy-build-system, using phases, the 
'this-package-input' can be changed to something more robust ...
> +(define-public grimshot
> +  (package
> +    (inherit sway)
> +    (name "grimshot")
> +    (source (origin
> +              (inherit (package-source sway))
> +              (snippet #~(begin
> +                           (delete-file "contrib/grimshot.1")))))
Some people have a preference for writing #~(begin [a single 
invocation]) anyway, but I'd like to note that wrapping the delete-file 
in a (begin ...) is not technically required.
> +    (build-system copy-build-system)
> +    (arguments
> +     (list #:install-plan #~`(("grimshot" "bin/")
> +                              ("grimshot.1" "usr/share/man/man1/"))
> +           #:phases #~(modify-phases %standard-phases
> +                        (add-after 'unpack 'chdir
> +                          (lambda _
> +                            (chdir "contrib")))
> +                        (add-after 'chdir 'patch-script-deps
No need to abbreviate dependencies -> deps, not that it matters much I 
suppose.
> +                          (lambda _
> +                            (substitute* "grimshot"
> +                              (("date ")
> +                               (string-append #$(this-package-input "coreutils")
> +                                              "/bin/date "))

Now that this is written as a phase, it becomes possible to use 
'search-input-file', like this:

> (lambda* (#:key inputs #:allow-other-keys)
>   (substitute*
>     (("\\b(date|jq|swaymsg|...)\\b" _ binary)
>      (search-input-file inputs (string-append "bin/" binary)))))
>
This way, you are not referring to input labels anymore, which has as 
benefit that package transformations become more robust. E.g., if you do 
it this way instead of using input labels (which this-package-input) 
does, it becomes possible to do things like 
--with-input=coreutils=busybox or the Scheme equivalent.
> +                        (add-after 'patch-script-deps 'build-man-page
> +                          (lambda _
> +                            (with-input-from-file "grimshot.1.scd"
> +                              (lambda _
> +                                (with-output-to-file "grimshot.1"
> +                                  (lambda _
> +                                    (invoke #+(file-append
> +                                               (this-package-native-input
> +                                                "scdoc")
> +                                               "/bin/scdoc")))))))))))

'invoke' does not need the absolute file name, so you the #+(file-append 
...) can be simplified to just "scdoc": [all the surrounding 
with-input/output-...+lambda (invoke "scdoc")], 'invoke' will 
automatically figure out the absolute file name.

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/gnu/packages/wm.scm b/gnu/packages/wm.scm
index 8fef7de77b..1e60ceb27b 100644
--- a/gnu/packages/wm.scm
+++ b/gnu/packages/wm.scm
@@ -2742,3 +2742,68 @@  (define-public avizo
      "Avizo is a simple notification daemon for Sway, mainly intended to be
 used for multimedia keys.")
     (license license:gpl3+)))
+
+(define-public grimshot
+  (package
+    (inherit sway)
+    (name "grimshot")
+    (source (origin
+              (inherit (package-source sway))
+              (snippet #~(begin
+                           (delete-file "contrib/grimshot.1")))))
+    (build-system copy-build-system)
+    (arguments
+     (list #:install-plan #~`(("grimshot" "bin/")
+                              ("grimshot.1" "usr/share/man/man1/"))
+           #:phases #~(modify-phases %standard-phases
+                        (add-after 'unpack 'chdir
+                          (lambda _
+                            (chdir "contrib")))
+                        (add-after 'chdir 'patch-script-deps
+                          (lambda _
+                            (substitute* "grimshot"
+                              (("date ")
+                               (string-append #$(this-package-input "coreutils")
+                                              "/bin/date "))
+                              (("jq ")
+                               (string-append #$(this-package-input "jq")
+                                              "/bin/jq "))
+                              (("swaymsg ")
+                               (string-append #$(this-package-input "sway")
+                                              "/bin/swaymsg "))
+                              (("notify-send ")
+                               (string-append #$(this-package-input "libnotify")
+                                              "/bin/notify-send "))
+                              (("grim ")
+                               (string-append #$(this-package-input "grim")
+                                              "/bin/grim "))
+                              (("slurp ")
+                               (string-append #$(this-package-input "slurp")
+                                              "/bin/slurp "))
+                              (("wl-copy ")
+                               (string-append
+                                #$(this-package-input "wl-clipboard")
+                                "/bin/wl-copy ")))))
+                        (add-after 'patch-script-deps 'build-man-page
+                          (lambda _
+                            (with-input-from-file "grimshot.1.scd"
+                              (lambda _
+                                (with-output-to-file "grimshot.1"
+                                  (lambda _
+                                    (invoke #+(file-append
+                                               (this-package-native-input
+                                                "scdoc")
+                                               "/bin/scdoc")))))))))))
+    (native-inputs (list scdoc))
+    (inputs (list coreutils
+                  grim
+                  jq
+                  libnotify
+                  slurp
+                  sway
+                  wl-clipboard))
+    (synopsis "Screenshot utility for the Sway window manager")
+    (description "Grimshot is a screenshot utility for @code{sway}.  It provides
+an interface over @code{grim}, @code{slurp} and @code{jq}, and supports storing
+the screenshot either directly to the clipboard using @code{wl-copy} or to a
+file.")))