···
···
self.nixosModules.spindle
24
-
inheritPath = false;
27
-
mountNixProfile = false;
25
+
virtualisation.vmVariant.virtualisation = {
26
+
host.pkgs = import nixpkgs {system = hostSystem;};
···
52
+
sharedDirectories = {
53
+
# We can't use the 9p mounts directly for most of these
54
+
# as SQLite is incompatible with them. So instead we
55
+
# mount the shared directories to a different location
56
+
# and copy the contents around on service start/stop.
58
+
source = "$TANGLED_VM_DATA_DIR/knot";
59
+
target = "/mnt/knot-data";
62
+
source = "$TANGLED_VM_DATA_DIR/spindle";
63
+
target = "/mnt/spindle-data";
66
+
source = "$TANGLED_VM_DATA_DIR/spindle-logs";
67
+
target = "/var/log/spindle";
services.getty.autologinUser = "root";
environment.systemPackages = with pkgs; [curl vim git sqlite litecli];
57
-
systemd.tmpfiles.rules = let
58
-
u = config.services.tangled-knot.gitUser;
59
-
g = config.services.tangled-knot.gitUser;
61
-
"d /var/lib/knot 0770 ${u} ${g} - -" # Create the directory first
62
-
"f+ /var/lib/knot/secret 0660 ${u} ${g} - KNOT_SERVER_SECRET=${envVar "TANGLED_VM_KNOT_SECRET"}"
services.tangled-knot = {
motd = "Welcome to the development knot!\n";
68
-
secretFile = "/var/lib/knot/secret";
77
+
secretFile = builtins.toFile "knot-secret" ("KNOT_SERVER_SECRET=" + (envVar "TANGLED_VM_KNOT_SECRET"));
hostname = "localhost:6000";
listenAddr = "0.0.0.0:6000";
···
95
+
# So we don't have to deal with permission clashing between
96
+
# blank disk VMs and existing state
97
+
users.${config.services.tangled-knot.gitUser}.uid = 666;
98
+
groups.${config.services.tangled-knot.gitUser}.gid = 666;
100
+
# TODO: separate spindle user
102
+
systemd.services = let
103
+
mkDataSyncScripts = source: target: {
104
+
enableStrictShellChecks = true;
106
+
preStart = lib.mkBefore ''
108
+
${lib.getExe pkgs.rsync} -a ${source}/ ${target}
111
+
postStop = lib.mkAfter ''
112
+
${lib.getExe pkgs.rsync} -a ${target}/ ${source}
115
+
serviceConfig.PermissionsStartOnly = true;
118
+
knot = mkDataSyncScripts "/mnt/knot-data" config.services.tangled-knot.stateDir;
119
+
spindle = mkDataSyncScripts "/mnt/spindle-data" (builtins.dirOf config.services.tangled-spindle.server.dbPath);