[bug#70460,4/4] gnu: services: Add power-profiles-daemon-service-type.

Message ID 09b1ed88b9e88d98b0b1df3ba3dd571da4a9b110.1713463209.git.dariqq@posteo.net
State New
Headers
Series Update power-profiles-daemon and add a service-type for it. |

Commit Message

Dariqq April 18, 2024, 6:36 p.m. UTC
* gnu/services/pm.scm
(power-profiles-configuration): New configuration.
(power-profiles-daemon-shepherd-service): New function.
(power-profiles-daemon-service-type): New function.
(power-profiles-daemon-activation): New variable.

Change-Id: Ib035d993ed82eec2a43f3ba2b4c92f77e08a0fd7
---
 gnu/services/pm.scm | 56 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
  

Comments

Félix Baylac Jacqué May 1, 2024, 4:43 p.m. UTC | #1
Hey Dariqq,

Thanks for this!

I would like to bump this patchset in the hope it catches the attention
of a maintainer. It sadly do not apply cleanly on current master
anymore.

This daemon is pretty important for laptops. This is the daemon used to
tune the CPU power efficiency by multiple DE: Gnome, KDE, Waybar, and
likely others I'm not aware of.

Power-profiles-daemon is meant to be launched as a system service, not
by dbus itself. This patchset is crutial to get a functional
power-profiles-daemon setup.

I'm also a Guix rookie, so I can't really help wrt. the service
definitions best practices.

I maintain this package on NixOS, I have a bit of experience with it,
and the packaging part looks fine overall. I'm not 100% sure generating
the gtk-doc is worth the closure size increase, but I think it's fine
for now, it shouldn't be a show-stopper.

I'm using this patchset on my system, it works as intended, it'd be
great to see it merged.

What should we do to get this moving forward? I'm up to help in the
process if neccessary.
  
Dariqq May 1, 2024, 9:16 p.m. UTC | #2
Hi Félix,

On 01.05.24 18:43, Félix Baylac Jacqué wrote:
> Hey Dariqq,
> 
> Thanks for this!
> 
> I would like to bump this patchset in the hope it catches the attention
> of a maintainer. It sadly do not apply cleanly on current master
> anymore.
There some issues that qa is unable to build the package on x86_64 due 
to tests timing out (and possibly other problems with tests?).

See 
https://data.qa.guix.gnu.org/gnu/store/5h0j710311kcz9hz87dznz97xirfzgpx-power-profiles-daemon-0.21.drv.

It seems fine for aarch64 and powerpc64le.

I am not really sure what's causing this as the tests are all fine for 
me locally. Maybe increasing the timeout window in the tests could 
improve this?
> 
> This daemon is pretty important for laptops. This is the daemon used to
> tune the CPU power efficiency by multiple DE: Gnome, KDE, Waybar, and
> likely others I'm not aware of.
> 
> Power-profiles-daemon is meant to be launched as a system service, not
> by dbus itself. This patchset is crutial to get a functional
> power-profiles-daemon setup.
> 

Great. The dbus service acts then just as a dummy to make the name 
available.

> I'm also a Guix rookie, so I can't really help wrt. the service
> definitions best practices.
> 

I also forgot include a short documentation for the service in 
doc/guix.texi. I have not yet looked into writing texinfo manuals but 
hopefully will get to do that later this week.

> I maintain this package on NixOS, I have a bit of experience with it,
> and the packaging part looks fine overall. I'm not 100% sure generating
> the gtk-doc is worth the closure size increase, but I think it's fine
> for now, it shouldn't be a show-stopper.

I guess I could move them to a seperate output. Though this does not 
address closure size.
> 
> I'm using this patchset on my system, it works as intended, it'd be
> great to see it merged.

Awesome.
> 
> What should we do to get this moving forward? I'm up to help in the
> process if neccessary.

I'd say fixing the build on the build farm, adding the missing manual 
entry  and getting the attention of someone who knows more about services.
  

Patch

diff --git a/gnu/services/pm.scm b/gnu/services/pm.scm
index 3daf484cc1..bedeebb9d8 100644
--- a/gnu/services/pm.scm
+++ b/gnu/services/pm.scm
@@ -21,18 +21,72 @@  (define-module (gnu services pm)
   #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (gnu packages admin)
+  #:use-module (gnu packages freedesktop)
   #:use-module (gnu packages linux)
   #:use-module (gnu services)
   #:use-module (gnu services base)
   #:use-module (gnu services configuration)
+  #:use-module (gnu services dbus)
   #:use-module (gnu services shepherd)
   #:use-module (gnu system shadow)
-  #:export (tlp-service-type
+  #:export (power-profiles-daemon-service-type
+            power-profiles-daemon-configuration
+
+            tlp-service-type
             tlp-configuration
 
             thermald-configuration
             thermald-service-type))
 
+;;;
+;;; power-profiles-daemon
+;;;
+
+(define-configuration/no-serialization power-profiles-daemon-configuration
+  (power-profiles-daemon
+   (file-like power-profiles-daemon)
+   "The power-profiles-daemon package."))
+
+(define (power-profiles-daemon-shepherd-service config)
+  (match-record
+      config <power-profiles-daemon-configuration>
+      (power-profiles-daemon)
+    (list (shepherd-service (provision '(power-profiles-daemon))
+			    (requirement '(dbus-system))
+                            (documentation "Run the power-profiles-daemon.")
+			    (start #~(make-forkexec-constructor
+				      (list #$(file-append power-profiles-daemon
+                                                           "/libexec/power-profiles-daemon"))))
+			    (stop #~(make-kill-destructor))))))
+
+(define %power-profiles-daemon-activation
+  #~(begin
+      (use-modules (guix build utils))
+      (mkdir-p "/var/lib/power-profiles-daemon")))
+
+(define power-profiles-daemon-service-type
+  (let ((config->package
+         (compose list power-profiles-daemon-configuration-power-profiles-daemon)))
+    (service-type
+     (name 'power-profiles-daemon)
+     (extensions (list
+                  (service-extension shepherd-root-service-type
+                                     power-profiles-daemon-shepherd-service)
+                  (service-extension dbus-root-service-type
+                                     config->package)
+                  (service-extension polkit-service-type
+                                     config->package)
+                  (service-extension profile-service-type
+                                     config->package)
+                  (service-extension activation-service-type
+                                     (const %power-profiles-daemon-activation))))
+     (default-value (power-profiles-daemon-configuration))
+     (description "Run the power-profiles-daemon"))))
+
+;;;
+;;; tlp
+;;;
+
 (define (uglify-field-name field-name)
   (let ((str (symbol->string field-name)))
     (string-join (string-split