Subject: bug#71352: branch master updated: services: nix: Mount Nix store read only.

From: Oleg Pykhalov <[email-masked]>
Date: Tue, 04 Jun 2024 11:34:24 +0300

Hello Maxim,

Thank you for your report.  Apologize for any inconvenience caused by
the unexpected breakage.

Maxim Cournoyer <[email-masked]> writes:

> Hello,
>
> [email-masked] writes:
>
>>     services: nix: Mount Nix store read only.
>>     
>>     * gnu/services/nix.scm (nix-shepherd-service): Add requirements.
>>     (%nix-store-directory): New variable.
>>     (nix-service-type): Add file-system-service-type extension.
>>     
>>     Change-Id: I18a5d58c92c1f2b5b6dcecc3d5b439cc15bf4e49
>
> This commit unfortunately appears to introduce a regression where
> reconfiguring a system with the read-only /nix/store causes the
> following error:
>
> guix system: error: chown: Système de fichiers accessible en lecture seulement
>
>
> With the accompanying strace output:
>
> 20261 close(17)                         = 0
> 20261 chown("/nix/store", 0, 981)       = -1 EROFS (Système de fichiers accessible en lecture seulement)
> 20261 close(13)                         = 0
> 20261 write(2, "guix system: \33[1;31merror: \33[0m\33[1mchown\33[0m: Syst\303\250me de fichiers accessible en lecture seulement\n", 99) = 99
>
>
> Are these chown still useful in the activation snippet?
>
> (define (nix-activation _)
>   ;; Return the activation gexp.
>   #~(begin
>       (use-modules (guix build utils)
>                    (srfi srfi-26))
>       (for-each (cut mkdir-p <>) '("/nix/store" "/nix/var/log"
>                                    "/nix/var/nix/gcroots/per-user"
>                                    "/nix/var/nix/profiles/per-user"))
>       (chown "/nix/store"
>              (passwd:uid (getpw "root")) (group:gid (getpw "nixbld01")))
>       (chmod "/nix/store" #o775)
>       (for-each (cut chmod <> #o777) '("/nix/var/nix/profiles"
>                                        "/nix/var/nix/profiles/per-user"))))
>
> If they are useful only on the first time, perhaps we could catch the
> exceptions for when it runs on an already read-only mounted /nix/store?

Indeed, it is a good idea.

A hotfix for the issue was discussed and implemented. It has already
been pushed to the master branch. The fix involves a simple
'file-exists?' check. You can find more details in the discussion at
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71320

What do you think is preferable in this scenario – catching exceptions
or sticking with '(unless (file-exists? ...))'?  Your thoughts on the
best approach here?

Regards,
Oleg.