Skip to content

Commit 0d20b3b

Browse files
committed
Make Linux Nix CI bootstrap safer
Signed-off-by: Nick Sweeting <git@sweeting.me>
1 parent 27c12fb commit 0d20b3b

2 files changed

Lines changed: 42 additions & 27 deletions

File tree

.github/workflows/tests.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,6 @@ jobs:
209209
if: runner.os != 'Linux'
210210
uses: DeterminateSystems/nix-installer-action@v22
211211

212-
- name: Ensure Nix daemon is running on Linux
213-
if: runner.os == 'Linux'
214-
run: |
215-
sudo systemctl daemon-reload
216-
sudo systemctl reset-failed nix-daemon.socket || true
217-
sudo systemctl reset-failed nix-daemon.service || true
218-
sudo systemctl start nix-daemon.socket
219-
sudo systemctl start nix-daemon.service || true
220-
sudo systemctl --no-pager --full status nix-daemon.socket
221-
sudo systemctl --no-pager --full status nix-daemon.service || true
222-
nix --version
223-
224212
- name: Sanitize PATH after Nix install
225213
shell: bash
226214
run: |

abxpkg/binprovider_nix.py

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,18 @@ def default_install_handler(
296296
timeout=timeout,
297297
)
298298
proc_output = format_subprocess_output(proc.stdout, proc.stderr)
299+
systemctl_bin = next(
300+
(
301+
str(path)
302+
for path in (Path("/usr/bin/systemctl"), Path("/bin/systemctl"))
303+
if path.is_file()
304+
),
305+
None,
306+
)
299307
if (
300308
proc.returncode != 0
301309
and os.uname().sysname == "Linux"
310+
and systemctl_bin is not None
302311
and Path("/run/systemd/system").is_dir()
303312
and (
304313
"cannot connect to socket at '/nix/var/nix/daemon-socket/socket'"
@@ -309,30 +318,30 @@ def default_install_handler(
309318
):
310319
self.exec(
311320
bin_name="sudo",
312-
cmd=["systemctl", "daemon-reload"],
321+
cmd=[systemctl_bin, "daemon-reload"],
313322
timeout=timeout,
314323
)
315324
self.exec(
316325
bin_name="sudo",
317-
cmd=["systemctl", "reset-failed", "nix-daemon.socket"],
326+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.socket"],
318327
timeout=timeout,
319328
quiet=True,
320329
)
321330
self.exec(
322331
bin_name="sudo",
323-
cmd=["systemctl", "reset-failed", "nix-daemon.service"],
332+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.service"],
324333
timeout=timeout,
325334
quiet=True,
326335
)
327336
self.exec(
328337
bin_name="sudo",
329-
cmd=["systemctl", "start", "nix-daemon.socket"],
338+
cmd=[systemctl_bin, "start", "nix-daemon.socket"],
330339
timeout=timeout,
331340
quiet=True,
332341
)
333342
self.exec(
334343
bin_name="sudo",
335-
cmd=["systemctl", "start", "nix-daemon.service"],
344+
cmd=[systemctl_bin, "start", "nix-daemon.service"],
336345
timeout=timeout,
337346
quiet=True,
338347
)
@@ -440,9 +449,18 @@ def default_update_handler(
440449
timeout=timeout,
441450
)
442451
proc_output = format_subprocess_output(proc.stdout, proc.stderr)
452+
systemctl_bin = next(
453+
(
454+
str(path)
455+
for path in (Path("/usr/bin/systemctl"), Path("/bin/systemctl"))
456+
if path.is_file()
457+
),
458+
None,
459+
)
443460
if (
444461
proc.returncode != 0
445462
and os.uname().sysname == "Linux"
463+
and systemctl_bin is not None
446464
and Path("/run/systemd/system").is_dir()
447465
and (
448466
"cannot connect to socket at '/nix/var/nix/daemon-socket/socket'"
@@ -453,30 +471,30 @@ def default_update_handler(
453471
):
454472
self.exec(
455473
bin_name="sudo",
456-
cmd=["systemctl", "daemon-reload"],
474+
cmd=[systemctl_bin, "daemon-reload"],
457475
timeout=timeout,
458476
)
459477
self.exec(
460478
bin_name="sudo",
461-
cmd=["systemctl", "reset-failed", "nix-daemon.socket"],
479+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.socket"],
462480
timeout=timeout,
463481
quiet=True,
464482
)
465483
self.exec(
466484
bin_name="sudo",
467-
cmd=["systemctl", "reset-failed", "nix-daemon.service"],
485+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.service"],
468486
timeout=timeout,
469487
quiet=True,
470488
)
471489
self.exec(
472490
bin_name="sudo",
473-
cmd=["systemctl", "start", "nix-daemon.socket"],
491+
cmd=[systemctl_bin, "start", "nix-daemon.socket"],
474492
timeout=timeout,
475493
quiet=True,
476494
)
477495
self.exec(
478496
bin_name="sudo",
479-
cmd=["systemctl", "start", "nix-daemon.service"],
497+
cmd=[systemctl_bin, "start", "nix-daemon.service"],
480498
timeout=timeout,
481499
quiet=True,
482500
)
@@ -584,9 +602,18 @@ def default_uninstall_handler(
584602
timeout=timeout,
585603
)
586604
proc_output = format_subprocess_output(proc.stdout, proc.stderr)
605+
systemctl_bin = next(
606+
(
607+
str(path)
608+
for path in (Path("/usr/bin/systemctl"), Path("/bin/systemctl"))
609+
if path.is_file()
610+
),
611+
None,
612+
)
587613
if (
588614
proc.returncode not in (0, 1)
589615
and os.uname().sysname == "Linux"
616+
and systemctl_bin is not None
590617
and Path("/run/systemd/system").is_dir()
591618
and (
592619
"cannot connect to socket at '/nix/var/nix/daemon-socket/socket'"
@@ -597,30 +624,30 @@ def default_uninstall_handler(
597624
):
598625
self.exec(
599626
bin_name="sudo",
600-
cmd=["systemctl", "daemon-reload"],
627+
cmd=[systemctl_bin, "daemon-reload"],
601628
timeout=timeout,
602629
)
603630
self.exec(
604631
bin_name="sudo",
605-
cmd=["systemctl", "reset-failed", "nix-daemon.socket"],
632+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.socket"],
606633
timeout=timeout,
607634
quiet=True,
608635
)
609636
self.exec(
610637
bin_name="sudo",
611-
cmd=["systemctl", "reset-failed", "nix-daemon.service"],
638+
cmd=[systemctl_bin, "reset-failed", "nix-daemon.service"],
612639
timeout=timeout,
613640
quiet=True,
614641
)
615642
self.exec(
616643
bin_name="sudo",
617-
cmd=["systemctl", "start", "nix-daemon.socket"],
644+
cmd=[systemctl_bin, "start", "nix-daemon.socket"],
618645
timeout=timeout,
619646
quiet=True,
620647
)
621648
self.exec(
622649
bin_name="sudo",
623-
cmd=["systemctl", "start", "nix-daemon.service"],
650+
cmd=[systemctl_bin, "start", "nix-daemon.service"],
624651
timeout=timeout,
625652
quiet=True,
626653
)

0 commit comments

Comments
 (0)