all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Export udev-configuration functions.
@ 2015-11-18 11:30 Ricardo Wurmus
  2015-11-18 17:57 ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Wurmus @ 2015-11-18 11:30 UTC (permalink / raw)
  To: guix-devel

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

Hi Guix,

as I tried to add a custom udev rule I noticed that I could only really
do this when the udev-configuration accessor functions are exported.

In my system configuration I first created the new udev rule (that’s all
a bit verbose, unfortunately), which is almost identical to the
‘kvm-udev-rule’:

~~~~~~~~~~~~~~~~
(define (avrispmkii-udev-rule)
  "Return a directory with a udev rule that sets the group owner and
group write permissions on the node matching the AVRISPmkII
microcontroller programming device."
  (computed-file "avrispmkii-rules"
                 #~(begin
                     (use-modules (guix build utils))

                     (define rules.d
                       (string-append #$output "/lib/udev/rules.d"))

                     (mkdir-p rules.d)
                     (call-with-output-file
                         (string-append rules.d "/90-avrispmkii.rules")
                       (lambda (port)
                         (display "\
SUBSYSTEM!=\"usb\", ACTION!=\"add\", GOTO=\"avrisp_end\"

# Atmel Corp. JTAG ICE mkII
ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2103\", MODE=\"660\", GROUP=\"dialout\"
# Atmel Corp. AVRISP mkII
ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2104\", MODE=\"660\", GROUP=\"dialout\"
# Atmel Corp. Dragon
ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2107\", MODE=\"660\", GROUP=\"dialout\"

LABEL=\"avrisp_end\"\n" port))))
                 #:modules '((guix build utils))))
~~~~~~~~~~~~~~~~

Then I replaced %desktop-services to amend the service of
‘udev-service-type’:

~~~~~~~~~~~~~~~~
(modify-services %desktop-services
  (udev-service-type config =>
                     (udev-configuration
                      (inherit config)
                      (rules (append (udev-configuration-rules config)
                                     (list (avrispmkii-udev-rule)))))))
~~~~~~~~~~~~~~~~

As you can see I need ‘udev-configuration’ to create a new
configuration, and ‘udev-configuration-rules’ to append my new rule to
the existing rules.

The attached patch just exports ‘udev-configuration’,
‘udev-configuration?’ (why not?), and ‘udev-configuration-rules’.

~~ Ricardo


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-services-Export-udev-configuration-procedures.patch --]
[-- Type: text/x-patch, Size: 830 bytes --]

From 46091d6045443a1bedbd1ca37e8ac31c1399d551 Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Wed, 18 Nov 2015 12:17:42 +0100
Subject: [PATCH] services: Export udev-configuration procedures.

* gnu/services/base.scm (udev-configuration, udev-configuration?,
  udev-configuration-rules): Export.
---
 gnu/services/base.scm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index b2bf7d9..bb5854d 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -51,6 +51,10 @@
             host-name-service
             console-keymap-service
             console-font-service
+
+            udev-configuration
+            udev-configuration?
+            udev-configuration-rules
             udev-service-type
             udev-service
 
-- 
2.5.0


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

* Re: [PATCH] Export udev-configuration functions.
  2015-11-18 11:30 [PATCH] Export udev-configuration functions Ricardo Wurmus
@ 2015-11-18 17:57 ` Ludovic Courtès
  2015-11-18 21:03   ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2015-11-18 17:57 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Ricardo Wurmus <rekado@elephly.net> skribis:

> In my system configuration I first created the new udev rule (that’s all
> a bit verbose, unfortunately), which is almost identical to the
> ‘kvm-udev-rule’:
>
> ~~~~~~~~~~~~~~~~
> (define (avrispmkii-udev-rule)
>   "Return a directory with a udev rule that sets the group owner and
> group write permissions on the node matching the AVRISPmkII
> microcontroller programming device."
>   (computed-file "avrispmkii-rules"
>                  #~(begin
>                      (use-modules (guix build utils))
>
>                      (define rules.d
>                        (string-append #$output "/lib/udev/rules.d"))
>
>                      (mkdir-p rules.d)
>                      (call-with-output-file
>                          (string-append rules.d "/90-avrispmkii.rules")
>                        (lambda (port)
>                          (display "\
> SUBSYSTEM!=\"usb\", ACTION!=\"add\", GOTO=\"avrisp_end\"
>
> # Atmel Corp. JTAG ICE mkII
> ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2103\", MODE=\"660\", GROUP=\"dialout\"
> # Atmel Corp. AVRISP mkII
> ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2104\", MODE=\"660\", GROUP=\"dialout\"
> # Atmel Corp. Dragon
> ATTR{idVendor}==\"03eb\", ATTR{idProduct}==\"2107\", MODE=\"660\", GROUP=\"dialout\"
>
> LABEL=\"avrisp_end\"\n" port))))
>                  #:modules '((guix build utils))))
> ~~~~~~~~~~~~~~~~

We should factorize this so one can write:

  (udev-rule "90-avrispmkii.rules"
             "SUBSYSTEM != …")

Because here it’s arguably sufficiently verbose to discourage newcomers.
:-)

> Then I replaced %desktop-services to amend the service of
> ‘udev-service-type’:
>
> ~~~~~~~~~~~~~~~~
> (modify-services %desktop-services
>   (udev-service-type config =>
>                      (udev-configuration
>                       (inherit config)
>                       (rules (append (udev-configuration-rules config)
>                                      (list (avrispmkii-udev-rule)))))))
> ~~~~~~~~~~~~~~~~

That’s one way do do it.

Another one would be to write an avrispmkii service that would extend
‘udev-service-type’ by passing it its rule (and maybe it could do other
useful things as well?)

> From 46091d6045443a1bedbd1ca37e8ac31c1399d551 Mon Sep 17 00:00:00 2001
> From: Ricardo Wurmus <rekado@elephly.net>
> Date: Wed, 18 Nov 2015 12:17:42 +0100
> Subject: [PATCH] services: Export udev-configuration procedures.
>
> * gnu/services/base.scm (udev-configuration, udev-configuration?,
>   udev-configuration-rules): Export.

Good idea indeed.  OK!

Ludo’.

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

* Re: [PATCH] Export udev-configuration functions.
  2015-11-18 17:57 ` Ludovic Courtès
@ 2015-11-18 21:03   ` Ricardo Wurmus
  2015-11-18 21:28     ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Ricardo Wurmus @ 2015-11-18 21:03 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

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


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

> We should factorize this so one can write:
>
>   (udev-rule "90-avrispmkii.rules"
>              "SUBSYSTEM != …")
>
> Because here it’s arguably sufficiently verbose to discourage newcomers.
> :-)

Patch attached.  Is this okay?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-services-Add-udev-rule-procedure.patch --]
[-- Type: text/x-patch, Size: 2731 bytes --]

From 77f22cb933a9740cccc62f6bac2d3f9381192eba Mon Sep 17 00:00:00 2001
From: Ricardo Wurmus <rekado@elephly.net>
Date: Wed, 18 Nov 2015 21:58:53 +0100
Subject: [PATCH] services: Add udev-rule procedure.

* gnu/services/base.scm (udev-rule): New procedure.
(kvm-udev-rule): Rewrite in terms of udev-rule.
---
 gnu/services/base.scm | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index bb5854d..1308065 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -57,6 +57,7 @@
             udev-configuration-rules
             udev-service-type
             udev-service
+            udev-rule
 
             mingetty-configuration
             mingetty-configuration?
@@ -956,12 +957,9 @@ item of @var{packages}."
                  #:modules '((guix build union)
                              (guix build utils))))
 
-(define* (kvm-udev-rule)
-  "Return a directory with a udev rule that changes the group of
-@file{/dev/kvm} to \"kvm\" and makes it #o660."
-  ;; Apparently QEMU-KVM used to ship this rule, but now we have to add it by
-  ;; ourselves.
-  (computed-file "kvm-udev-rules"
+(define (udev-rule filename contents)
+  "Return a directory with a udev rule file FILENAME containing CONTENTS."
+  (computed-file filename
                  #~(begin
                      (use-modules (guix build utils))
 
@@ -970,15 +968,22 @@ item of @var{packages}."
 
                      (mkdir-p rules.d)
                      (call-with-output-file
-                         (string-append rules.d "/90-kvm.rules")
+                         (string-append rules.d "/" #$filename)
                        (lambda (port)
-                         ;; Build users are part of the "kvm" group, so we
-                         ;; can fearlessly make /dev/kvm 660 (see
-                         ;; <http://bugs.gnu.org/18994>, for background.)
-                         (display "\
-KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0660\"\n" port))))
+                         (display #$contents port))))
                  #:modules '((guix build utils))))
 
+(define (kvm-udev-rule)
+  "Return a directory with a udev rule that changes the group of
+@file{/dev/kvm} to \"kvm\" and makes it #o660."
+  ;; Apparently QEMU-KVM used to ship this rule, but now we have to add it by
+  ;; ourselves.
+
+  ;; Build users are part of the "kvm" group, so we can fearlessly make
+  ;; /dev/kvm 660 (see <http://bugs.gnu.org/18994>, for background.)
+  (udev-rule "90-kvm.rules"
+             "KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0660\"\n"))
+
 (define udev-dmd-service
   ;; Return a <dmd-service> for UDEV with RULES.
   (match-lambda
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 880 bytes --]


> That’s one way do do it.
>
> Another one would be to write an avrispmkii service that would extend
> ‘udev-service-type’ by passing it its rule (and maybe it could do other
> useful things as well?)

I did this first but then it seemed overly complicated when there
already is a service that does almost exactly what I want.  But in more
complicated cases it may make sense to add a new service.  I really like
how straight forward this new service composition feature is!

>> From 46091d6045443a1bedbd1ca37e8ac31c1399d551 Mon Sep 17 00:00:00 2001
>> From: Ricardo Wurmus <rekado@elephly.net>
>> Date: Wed, 18 Nov 2015 12:17:42 +0100
>> Subject: [PATCH] services: Export udev-configuration procedures.
>>
>> * gnu/services/base.scm (udev-configuration, udev-configuration?,
>>   udev-configuration-rules): Export.
>
> Good idea indeed.  OK!

Pushed!  Thanks!

~~ Ricardo

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

* Re: [PATCH] Export udev-configuration functions.
  2015-11-18 21:03   ` Ricardo Wurmus
@ 2015-11-18 21:28     ` Ludovic Courtès
  2015-11-19 16:08       ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2015-11-18 21:28 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Ricardo Wurmus <rekado@elephly.net> skribis:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> We should factorize this so one can write:
>>
>>   (udev-rule "90-avrispmkii.rules"
>>              "SUBSYSTEM != …")
>>
>> Because here it’s arguably sufficiently verbose to discourage newcomers.
>> :-)
>
> Patch attached.  Is this okay?
>
> From 77f22cb933a9740cccc62f6bac2d3f9381192eba Mon Sep 17 00:00:00 2001
> From: Ricardo Wurmus <rekado@elephly.net>
> Date: Wed, 18 Nov 2015 21:58:53 +0100
> Subject: [PATCH] services: Add udev-rule procedure.
>
> * gnu/services/base.scm (udev-rule): New procedure.
> (kvm-udev-rule): Rewrite in terms of udev-rule.

[...]

> +(define (udev-rule filename contents)
> +  "Return a directory with a udev rule file FILENAME containing CONTENTS."

Rather “file-name” (sorry for being pedantic ;-)).

> +(define (kvm-udev-rule)

This can even become a plain variable.

Otherwise LGTM!

> > That’s one way do do it.
> >
> > Another one would be to write an avrispmkii service that would extend
> > ‘udev-service-type’ by passing it its rule (and maybe it could do other
> > useful things as well?)
> 
> I did this first but then it seemed overly complicated when there
> already is a service that does almost exactly what I want.

Yeah, makes sense!

Thank you,
Ludo’.

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

* Re: [PATCH] Export udev-configuration functions.
  2015-11-18 21:28     ` Ludovic Courtès
@ 2015-11-19 16:08       ` Ricardo Wurmus
  0 siblings, 0 replies; 5+ messages in thread
From: Ricardo Wurmus @ 2015-11-19 16:08 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel


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

>> From 77f22cb933a9740cccc62f6bac2d3f9381192eba Mon Sep 17 00:00:00 2001
>> From: Ricardo Wurmus <rekado@elephly.net>
>> Date: Wed, 18 Nov 2015 21:58:53 +0100
>> Subject: [PATCH] services: Add udev-rule procedure.
>>
>> * gnu/services/base.scm (udev-rule): New procedure.
>> (kvm-udev-rule): Rewrite in terms of udev-rule.
>
> [...]
>
>> +(define (udev-rule filename contents)
>> +  "Return a directory with a udev rule file FILENAME containing CONTENTS."
>
> Rather “file-name” (sorry for being pedantic ;-)).

Okay.

>> +(define (kvm-udev-rule)
>
> This can even become a plain variable.

Okay!

> Otherwise LGTM!

Thanks.  I pushed it with these two changes.

~~ Ricardo

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

end of thread, other threads:[~2015-11-19 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-18 11:30 [PATCH] Export udev-configuration functions Ricardo Wurmus
2015-11-18 17:57 ` Ludovic Courtès
2015-11-18 21:03   ` Ricardo Wurmus
2015-11-18 21:28     ` Ludovic Courtès
2015-11-19 16:08       ` Ricardo Wurmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.