diff mbox series

[bug#56770] gnu: Add grimshot.

Message ID 20220725205412.336878-1-antero@mailbox.org
State Accepted
Headers show
Series [bug#56770] 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 25, 2022, 8:54 p.m. UTC
* gnu/packages/wm.scm (grimshot): New variable.
---
 gnu/packages/wm.scm | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

M July 26, 2022, 3:46 p.m. UTC | #1
> +          (copy-recursively
> +           (string-append #$(package-source this-package) "/contrib") ".")
I would have expected trivial-build-system to automatically unpack the 
source, so maybe this can be simplified to (chdir "/contrib") (untested!)

On 25-07-2022 22:54, Antero Mejr via Guix-patches via wrote:
> +          (system
> +           (string-append #$scdoc "/bin/scdoc < grimshot.1.scd > grimshot.1"))

This ignores any errors coming from 'system'. Try (invoke ...) + 
with-input-from-file + with-output-to-file instead, which will report 
errors as exceptions:

(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")))))

Here it is important to use #+ instead of #$ for cross-compilation.  I 
use this-package-native-input here to make the --with-input 
transformation work.

> +          (substitute* "grimshot"
> +            (("date ") (string-append #$coreutils "/bin/date "))
> +            (("jq ") (string-append #$jq "/bin/jq "))
> +            (("swaymsg ") (string-append #$sway "/bin/swaymsg "))
> +            (("notify-send ") (string-append #$libnotify "/bin/notify-send "))
> +            (("grim ") (string-append #$grim "/bin/grim "))
> +            (("slurp ") (string-append #$slurp "/bin/slurp "))
> +            (("wl-copy ") (string-append #$wl-clipboard "/bin/wl-copy ")))
Likewise, you should use this-package-input here (but unlike the 
previous case, not this-package-native-input).

(I only looked at the package definition, not the underlying source 
code, and did not test it)

Greetings,
Maxime
M July 26, 2022, 3:49 p.m. UTC | #2
On 25-07-2022 22:54, Antero Mejr via Guix-patches via wrote:
> +          (delete-file "grimshot.1")

Why is it deleted?  If it's to build the man page from source instead of 
copying the pre-made binary, I think a snippet in the origin would be a 
slightly better fit, to clean up the result of "guix build --source" a 
bit, though it doesn't matter much I suppose.

Greetings,
Maxime.
M July 26, 2022, 3:52 p.m. UTC | #3
On 26-07-2022 17:46, Maxime Devos wrote:
>
>> + (copy-recursively
>> +           (string-append #$(package-source this-package) 
>> "/contrib") ".")
> I would have expected trivial-build-system to automatically unpack the 
> source, so maybe this can be simplified to (chdir "/contrib") (untested!) 

Or even simpler: remove this line, and add (source (file-append 
(package-source sway) "/contrib")) as a field.

A quick  "git grep -F '(source (file-append" doesn't result in any 
packages already doing that, but it seems a perfect fit here to me ...  
OTOH, this probably interferes with --with-git-url and such, so I'd 
guess better not.

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/gnu/packages/wm.scm b/gnu/packages/wm.scm
index 8fef7de77b..9aad6c1c37 100644
--- a/gnu/packages/wm.scm
+++ b/gnu/packages/wm.scm
@@ -2742,3 +2742,38 @@  (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")
+    (build-system trivial-build-system)
+    (arguments
+     (list
+      #:modules '((guix build utils))
+      #:builder
+      #~(begin
+          (use-modules (guix build utils))
+          (copy-recursively
+           (string-append #$(package-source this-package) "/contrib") ".")
+          (substitute* "grimshot"
+            (("date ") (string-append #$coreutils "/bin/date "))
+            (("jq ") (string-append #$jq "/bin/jq "))
+            (("swaymsg ") (string-append #$sway "/bin/swaymsg "))
+            (("notify-send ") (string-append #$libnotify "/bin/notify-send "))
+            (("grim ") (string-append #$grim "/bin/grim "))
+            (("slurp ") (string-append #$slurp "/bin/slurp "))
+            (("wl-copy ") (string-append #$wl-clipboard "/bin/wl-copy ")))
+          (delete-file "grimshot.1")
+          (system
+           (string-append #$scdoc "/bin/scdoc < grimshot.1.scd > grimshot.1"))
+          (install-file "grimshot" (string-append #$output "/bin"))
+          (install-file "grimshot.1"
+                        (string-append #$output "/usr/share/man/man1")))))
+    (native-inputs (list scdoc))
+    (inputs (list coreutils grim jq libnotify 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.")))