[PATCH 0/2] Activate system when switching generations.

  • Done
  • quality assurance status badge
Details
2 participants
  • Brice Waegeneire
  • Ludovic Courtès
Owner
unassigned
Submitted by
Brice Waegeneire
Severity
normal
B
B
Brice Waegeneire wrote on 16 Feb 2021 13:35
(address . guix-patches@gnu.org)
87czx06ubt.fsf@waegenei.re
Hello,

As reported on previous bug report, rolling-back or switching generation
doesn't activate the system as a system reconfiguration would do. This is
especially problematic when modifying in /run/setuid-programs, as it can't be
reverted easily. Also it hinder modification in the activation script since
it's not straight forward to revert change made by those script without a
functional roll-back mechanism.

I'm not sure it's the right approach but at least it work: it add the
activate.scm script to the system profile and then load it when
switching-generation.

This is related to issues:
- #37596 and #38884 (they are duplicate)
- #36855 a more wider discussion

Cheers,
- Brice

Brice Waegeneire (2):
gnu: services: Add activate script to the profile system directory.
scripts: system: Activate system when switching generations.

gnu/services.scm | 10 +++++++++-
guix/scripts/system.scm | 8 ++++++--
2 files changed, 15 insertions(+), 3 deletions(-)

--
2.30.1
B
B
Brice Waegeneire wrote on 16 Feb 2021 14:22
[PATCH 1/2] gnu: services: Add activate script to the profile system directory.
(address . 46560@debbugs.gnu.org)
20210216132235.15811-1-brice@waegenei.re
* gnu/services.scm (activation-profile-entry): New procedure...
(activation-service-type): ... use it.
---
gnu/services.scm | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Toggle diff (29 lines)
diff --git a/gnu/services.scm b/gnu/services.scm
index 13259dfaee..ddd1bac30c 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -617,13 +617,21 @@ ACTIVATION-SCRIPT-TYPE."
"Return a gexp that runs the activation script containing GEXPS."
#~(primitive-load #$(activation-script gexps)))
+(define (activation-profile-entry gexps)
+ "Return, as a monadic value, an entry for the activation script in the
+system directory."
+ (mlet %store-monad ((activate (lower-object (activation-script gexps))))
+ (return `(("activate" ,activate)))))
+
(define (second-argument a b) b)
(define activation-service-type
(service-type (name 'activate)
(extensions
(list (service-extension boot-service-type
- gexps->activation-gexp)))
+ gexps->activation-gexp)
+ (service-extension system-service-type
+ activation-profile-entry)))
(compose identity)
(extend second-argument)
(description
--
2.30.1
B
B
Brice Waegeneire wrote on 16 Feb 2021 14:22
[PATCH 2/2] scripts: system: Activate system when switching generations.
(address . 46560@debbugs.gnu.org)
20210216132235.15811-2-brice@waegenei.re
Fixes #38884.

* guix/scripts/system.scm (switch-to-system-generation): Load the
activate script for that generation.
---
guix/scripts/system.scm | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Toggle diff (31 lines)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 19b8c5163c..4c7af52ad5 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -8,6 +8,7 @@
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -363,11 +364,14 @@ connection to the store."
"Switch the system profile to the generation specified by SPEC, and
re-install bootloader with a configuration file that uses the specified system
generation as its default entry. STORE is an open connection to the store."
- (let ((number (relative-generation-spec->number %system-profile spec)))
+ (let* ((number (relative-generation-spec->number %system-profile spec))
+ (generation (generation-file-name %system-profile number))
+ (activate (string-append generation "/activate")))
(if number
(begin
(reinstall-bootloader store number)
- (switch-to-generation* %system-profile number))
+ (switch-to-generation* %system-profile number)
+ (primitive-load activate))
(leave (G_ "cannot switch to system generation '~a'~%") spec))))
(define* (system-bootloader-name #:optional (system %system-profile))
--
2.30.1
L
L
Ludovic Courtès wrote on 1 Mar 2021 16:55
Re: bug#46560: [PATCH 0/2] Activate system when switching generations.
(name . Brice Waegeneire)(address . brice@waegenei.re)(address . 46560@debbugs.gnu.org)
87mtvmrhqm.fsf_-_@gnu.org
Hi,

Brice Waegeneire <brice@waegenei.re> skribis:

Toggle quote (3 lines)
> * gnu/services.scm (activation-profile-entry): New procedure...
> (activation-service-type): ... use it.

[...]

Toggle quote (17 lines)
> +(define (activation-profile-entry gexps)
> + "Return, as a monadic value, an entry for the activation script in the
> +system directory."
> + (mlet %store-monad ((activate (lower-object (activation-script gexps))))
> + (return `(("activate" ,activate)))))
> +
> (define (second-argument a b) b)
>
> (define activation-service-type
> (service-type (name 'activate)
> (extensions
> (list (service-extension boot-service-type
> - gexps->activation-gexp)))
> + gexps->activation-gexp)
> + (service-extension system-service-type
> + activation-profile-entry)))

Good idea, LGTM!
L
L
Ludovic Courtès wrote on 1 Mar 2021 16:56
(name . Brice Waegeneire)(address . brice@waegenei.re)(address . 46560@debbugs.gnu.org)
87im6arhoj.fsf_-_@gnu.org
Brice Waegeneire <brice@waegenei.re> skribis:

Toggle quote (2 lines)
> Fixes #38884.

Nitpick: “Fixes https://bugs.gnu.org/38884.”

Toggle quote (3 lines)
> * guix/scripts/system.scm (switch-to-system-generation): Load the
> activate script for that generation.

[...]

Toggle quote (3 lines)
> + (switch-to-generation* %system-profile number)
> + (primitive-load activate))

I suppose you need to wrap catch 'system-error here and to keep going
upon ENOENT.

Could you send an updated patch?

Thanks!

Ludo’.
B
B
Brice Waegeneire wrote on 4 Mar 2021 07:57
[PATCH v2 0/2] Activate system when switching generations.
(address . 46560@debbugs.gnu.org)(address . ludo@gnu.org)
20210304065754.18619-1-brice@waegenei.re
Hello Ludovic,

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

Toggle quote (17 lines)
> Brice Waegeneire <brice@waegenei.re> skribis:
>
> > Fixes #38884.
>
> Nitpick: “Fixes <https://bugs.gnu.org/38884>.”
>
> > * guix/scripts/system.scm (switch-to-system-generation): Load the
> > activate script for that generation.
>
> [...]
>
> > + (switch-to-generation* %system-profile number)
> > + (primitive-load activate))
>
> I suppose you need to wrap catch 'system-error here and to keep going
> upon ENOENT.

This patch set fixes both issues.

Cheers,
- Brice

Brice Waegeneire (2):
gnu: services: Add activate script to the profile system directory.
scripts: system: Activate system when switching generations.

gnu/services.scm | 10 +++++++++-
guix/scripts/system.scm | 8 ++++++--
2 files changed, 15 insertions(+), 3 deletions(-)

--
2.30.1
B
B
Brice Waegeneire wrote on 4 Mar 2021 07:57
[PATCH v2 1/2] gnu: services: Add activate script to the profile system directory.
(address . 46560@debbugs.gnu.org)(address . ludo@gnu.org)
20210304065754.18619-2-brice@waegenei.re
* gnu/services.scm (activation-profile-entry): New procedure...
(activation-service-type): ... use it.
---
gnu/services.scm | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Toggle diff (29 lines)
diff --git a/gnu/services.scm b/gnu/services.scm
index 13259dfaee..ddd1bac30c 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -617,13 +617,21 @@ ACTIVATION-SCRIPT-TYPE."
"Return a gexp that runs the activation script containing GEXPS."
#~(primitive-load #$(activation-script gexps)))
+(define (activation-profile-entry gexps)
+ "Return, as a monadic value, an entry for the activation script in the
+system directory."
+ (mlet %store-monad ((activate (lower-object (activation-script gexps))))
+ (return `(("activate" ,activate)))))
+
(define (second-argument a b) b)
(define activation-service-type
(service-type (name 'activate)
(extensions
(list (service-extension boot-service-type
- gexps->activation-gexp)))
+ gexps->activation-gexp)
+ (service-extension system-service-type
+ activation-profile-entry)))
(compose identity)
(extend second-argument)
(description
--
2.30.1
B
B
Brice Waegeneire wrote on 4 Mar 2021 07:57
[PATCH v2 2/2] scripts: system: Activate system when switching generations.
(address . 46560@debbugs.gnu.org)(address . ludo@gnu.org)
20210304065754.18619-3-brice@waegenei.re

* guix/scripts/system.scm (switch-to-system-generation): Load the
activate script for that generation.

squash! scripts: system: Activate system when switching generations.
---
guix/scripts/system.scm | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Toggle diff (31 lines)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index e3cf99acc6..c226f08371 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -8,6 +8,7 @@
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -363,11 +364,14 @@ connection to the store."
"Switch the system profile to the generation specified by SPEC, and
re-install bootloader with a configuration file that uses the specified system
generation as its default entry. STORE is an open connection to the store."
- (let ((number (relative-generation-spec->number %system-profile spec)))
+ (let* ((number (relative-generation-spec->number %system-profile spec))
+ (generation (generation-file-name %system-profile number))
+ (activate (string-append generation "/activate")))
(if number
(begin
(reinstall-bootloader store number)
- (switch-to-generation* %system-profile number))
+ (switch-to-generation* %system-profile number)
+ (unless-file-not-found (primitive-load activate)))
(leave (G_ "cannot switch to system generation '~a'~%") spec))))
(define* (system-bootloader-name #:optional (system %system-profile))
--
2.30.1
L
L
Ludovic Courtès wrote on 8 Mar 2021 15:15
Re: [PATCH v2 0/2] Activate system when switching generations.
(name . Brice Waegeneire)(address . brice@waegenei.re)(address . 46560@debbugs.gnu.org)
87blbtd95l.fsf@gnu.org
Hi Brice,

Brice Waegeneire <brice@waegenei.re> skribis:

Toggle quote (4 lines)
> Brice Waegeneire (2):
> gnu: services: Add activate script to the profile system directory.
> scripts: system: Activate system when switching generations.

LGTM, thanks!

Ludo’.
B
B
Brice Waegeneire wrote on 9 Mar 2021 07:12
Re: bug#46560: [PATCH 0/2] Activate system when switching generations.
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 46560-done@debbugs.gnu.org)
87k0qgzwh3.fsf_-_@waegenei.re
Hello Ludo,

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

Toggle quote (8 lines)
> Brice Waegeneire <brice@waegenei.re> skribis:
>
>> Brice Waegeneire (2):
>> gnu: services: Add activate script to the profile system directory.
>> scripts: system: Activate system when switching generations.
>
> LGTM, thanks!

Pushed as df138dc20858725b90ed77be85f3318cbe1be73a and later. I'll close
#38884 and will do the same or comment #36855 and #37596 about the new
feature.

Cheers,
- Brice.
Closed
?