Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shows my custom hack to ensure deployed NixOps machines use my custom substitutor already for the first `nixops deploy`
diff --git a/nixops/deployment.py b/nixops/deployment.py
index 1341a27..6df2fd6 100644
--- a/nixops/deployment.py
+++ b/nixops/deployment.py
@@ -2,7 +2,7 @@
import sys
import os.path
-import subprocess
+import subprocess32 as subprocess
import json
import string
import tempfile
@@ -740,6 +740,11 @@ class Deployment(object):
# FIXME: should check which systemd services
# failed to start after the reboot.
+ if res == 0:
+ res = m.run_command("systemctl isolate multi-user.target")
+ if res != 0:
+ raise Exception("unable to start multi-user.target")
+
if res == 0:
m.success("activation finished successfully")
@@ -975,6 +980,10 @@ class Deployment(object):
r.wait_for_ssh(check=check)
r.generate_vpn_key()
+ # Change binary-caches (nix < 2) / substituters (nix >= 2) to the ones the user wants
+ r.log("setting custom nix.conf options")
+ r.run_command("if [ ! -f /etc/nix/nix.conf ]; then mkdir -p /etc/nix && echo 'binary-caches = http://nixos-cache.example.com/ http://cache.nixos.org/\\nsubstituters = http://nixos-cache.example.com/ http://cache.nixos.org/\\nbuild-max-jobs = 5' > /etc/nix/nix.conf; else cp /etc/nix/nix.conf /tmp/nix.conf && perl -p -i -e 's@^binary-caches.*$@binary-caches = http://nixos-cache.example.com/ http://cache.nixos.org/@g' /tmp/nix.conf && perl -p -i -e 's@^substituters.*$@substituters = http://nixos-cache.example.com/ http://cache.nixos.org/@g' /tmp/nix.conf && perl -p -i -e 's@^build-max-jobs.*$@build-max-jobs = 5@g' /tmp/nix.conf && perl -p -i -e 's@^binary-cache-public-keys.*$@binary-cache-public-keys = examplecom-nix-binary-cache-signing-key:TiYm+ouXxHq1yu3YyjVBseCwjj8uOE8AWPF1wDo5JbI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=@g' /tmp/nix.conf && mv /tmp/nix.conf /etc/nix/nix.conf; fi")
+
except:
r._errored = True
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.