Hi Daniel,

On Thu, Feb 26 2026, Daniel Littlewood wrote:
> I am wanting to try out the `guix deploy` command, but I am a little
> scared to use it.

This isn't much worse than doing the reconfigure on the system itself,
though. You can always have another ssh session open as root to recover
from a faulty deployment with a "guix system roll-back".

> I will probably attempt to write something, unless I find out somebody
> else has. So if you are interested in this, even if you don't have an
> answer, let me know.

I haven't written anything to do this sort of automatic roll-back, but I
did just have a quick look through, and I think it wouldn't be too hard
to do.

The steps to deploy a machine are controlled by the environment-type
record's "deploy-machine" function. This means you could write your own
environment type which does whatever you want here. For an ssh machine
this might be something like:

--8<---------------cut here---------------start------------->8---
(define (deployment-okay? machine)
  ;; Your logic here.  This runs on the local machine, so you can try to make
  ;; an SSH connection or something like that.
  )

(define (deploy-auto-roll-back-managed-host machine)
  (mbegin %store-monad
    (deploy-managed-host machine)
    (unless (deployment-okay? machine)
      (raise (condition (&deploy-error
                         (should-roll-back #t)
                         (captured-args
                          (raise "Deployment not okay - triggered 
roll-back"))))))))

(define auto-roll-back-managed-host-environment-type
  (environment-type
    (inherit managed-host-environment-type)
    (deploy-machine deploy-auto-roll-back-managed-host)))
--8<---------------cut here---------------end--------------->8---

Something like this should let you write whatever condition you want.
The condition would be checked on the local machine, and the roll-back
would be triggered using the one persistent ssh connection that "guix
deploy" establishes. That means there are issues where this wouldn't
roll back where you might expect it to (e.g. the network fails during
"deployment-okay?"), but I expect it would catch a lot of configuration
issues.

If you give it a go, please let us know how it went.

Carlo

Reply via email to