Subject: bug#76698: Activations interfere with each other modules

From: Tomas Volf <[email-masked]>
Date: Mon, 03 Mar 2025 02:02:22 +0100

Hello,

when using `activation-service-type' combined with `with-extension', the
various modules seem to interfere with each other.

In my case the samba-service-type interferes with my custom service:

--8<---------------cut here---------------start------------->8---
(define (watcher-activation* config)
  (match-record config <watcher-configuration>
                (user group cache-dir state-dir)
    (with-extension/guile-wolfsden
     #~(begin
         (use-modules (wolfsden fs)
                      (wolfsden sh))
         (for-each (lambda (dir)
                     (mkdir-p dir)
                     (invoke* #$(file-append coreutils "/bin/chown")
                              "-Rv" (string-append #$user ":" #$group) dir)
                     (chmod dir #o700))
                   '(#$cache-dir
                     #$state-dir))))))
--8<---------------cut here---------------end--------------->8---

samba-service-type's activation starts with:

--8<---------------cut here---------------start------------->8---
(define (samba-activation config)
  (let ((package (samba-configuration-package config))
        (config-file (samba-configuration-config-file config)))
    (with-imported-modules '((guix build utils))
--8<---------------cut here---------------end--------------->8---

Both (guix build utils) and (wolfsden sh) provide (invoke) procedure,
however with incompatible parameters, leading to somewhat annoying to
debug issues.  In my case the error was:

--8<---------------cut here---------------start------------->8---
guix deploy: error: failed to deploy x: failed to switch systems while deploying '127.0.0.1':
keyword-argument-error #f "Invalid keyword" () ("/etc/samba/smb.conf") 
--8<---------------cut here---------------end--------------->8---

Which makes sense now when I understand what the problem is, but it took
while to get to it.

I do not think this should be the case.  Either each activation service
should be isolated into a fresh user module, or the services provided by
Guix should not introduce any additional modules into the scope.
Alternatively, each activation service could be wrapped into
program-file, that would ensure isolation as well.

Tomas
-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.