1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
.Dd October 15, 2026
.Dt DEPLOY 1
.Os
.Sh NAME
.Nm deploy
.Nd build a NixOS machine from the local checkout and switch to it
.Sh SYNOPSIS
.Nm
.Op Fl -remote-build
.Op Fl -profile Ns Op = Ns Ar path
.Ar machine
.Nm
.Cm history
.Op Fl n Ar count
.Op Ar machine
.Sh DESCRIPTION
.Nm
deploys
.Li nixosConfigurations.\& Ns Ar machine
from the flake at
.Pa /home/philip/kot/Profpatsch ,
as it is on disk: uncommitted changes are deployed too, and nothing has to be
pushed first.
.Pp
A deploy runs these phases in order, and stops at the first one that fails:
.Bl -tag -width "profile"
.It Cm eval
Evaluate the system toplevel to its derivation
.Pq Li nix path-info --derivation .
.It Cm build
Build that derivation, locally or, with
.Fl -remote-build ,
on the target after copying the derivations there.
.It Cm copy
Copy the built closure to the target
.Pq Li nix copy --substitute-on-destination .
Skipped when there is nothing to copy: for
.Fl -remote-build ,
and for the local machine.
.It Cm profile
Point
.Pa /nix/var/nix/profiles/system
at the result, creating a new generation.
This is what makes the boot menu and a rollback know about it.
.It Cm switch
Run the result's
.Pa bin/switch-to-configuration switch .
.El
.Pp
Each command is printed before it runs.
.Ss The local machine
If
.Ar machine
is the host
.Nm
runs on
.Pq compared with the hostname, without any domain ,
all phases run locally and the two that need root go through
.Xr sudo 8 .
This is not an optimisation: the workstation typically runs no sshd, so
.Li root@ Ns Ar machine
does not answer.
.Pp
The sudo password is asked for up front, before the build, and the credential
is refreshed every minute until the deploy ends.
Asked only when root is first needed, sudo would prompt minutes into the
deploy, when nobody is watching any more, and give up after its own prompt
timeout, failing the deploy at
.Cm profile .
.Fl -remote-build
is ignored with a note.
.Ss Remote machines
Everything on the target is done as
.Li root
over
.Xr ssh 1 ,
so
.Li ssh root@ Ns Ar machine
must work.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl -remote-build
Evaluate locally but build on the target.
Use it when the target is faster, or when copying the closure over the network
costs more than building it there.
.It Fl -profile Ns Op = Ns Ar path
Profile the evaluation and write a flamegraph to
.Ar path ,
by default
.Pa nix-eval.profile .
.El
.Sh HISTORY DATABASE
Every attempt is recorded, including the ones that fail, in an SQLite database:
when it started, the mode
.Po
.Li local ,
.Li local-build
or
.Li remote-build
.Pc ,
the git commit of the checkout and whether the work tree was dirty, the
derivation and output paths, the closure size, the duration of each phase,
and how it ended.
.Pp
The row is written before the first phase and updated after each one, so an
attempt that is killed outright still appears, as
.Li unfinished .
An interrupt
.Pq Ctrl-C
is caught and recorded as a failure of the phase it interrupted.
.Pp
The database is bookkeeping only: if it cannot be opened or written,
.Nm
warns and carries on with the deploy.
.Ss deploy history
Lists the last
.Ar count
attempts
.Pq default 20 ,
oldest first, so that the latest is the last line, optionally only those to
.Ar machine .
Besides what was recorded, it asks every machine involved, live, what it still
has of each result:
.Bl -tag -width "commit"
.It Li store
.Li \(OK
if the output path is still in the machine's
.Pa /nix/store ,
.Li \(mu
if it is not
.Pq garbage collected, or never got there .
.It Li gen
The newest system profile generation pointing at the output path, if any, and
.Li (current)
if the machine is running it.
A path with a generation is safe from the garbage collector and can be rolled
back to; one without can be collected at any time.
.It Li commit
Abbreviated commit, with a
.Li +
if the work tree was dirty.
A dirty deploy cannot be reproduced from the commit alone.
.El
.Pp
Remote machines are asked over ssh in batch mode with a short timeout, so a
listing never prompts or hangs; a machine that does not answer gets
.Li \&?
in both columns.
.Sh FILES
.Bl -tag -width Ds
.It Pa $XDG_STATE_HOME/deploy/deploy.sqlite
The history database, by default under
.Pa ~/.local/state .
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
Deploy a server, then the workstation you are sitting at:
.Bd -literal -offset indent
$ deploy legosi
$ deploy rolery
.Ed
.Pp
Is the system deployed to haku last month still there to roll back to?
.Bd -literal -offset indent
$ deploy history haku
.Ed
.Sh SEE ALSO
.Xr nix-store 1 ,
.Xr nixos-rebuild 8
.Sh CAVEATS
The local-machine check is by name only.
Deploying the configuration of one machine onto another is not supported.
.Pp
Store paths are recorded, not generations: the
.Li gen
column is worked out afresh on every listing, so it is correct after
rollbacks and generation deletion, but it cannot tell which of several
generations of the same closure a particular deploy created.
|