summaryrefslogtreecommitdiffstats
path: root/lass/2configs/green-hosts/plain-bindfs.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lass/2configs/green-hosts/plain-bindfs.nix')
-rw-r--r--lass/2configs/green-hosts/plain-bindfs.nix90
1 files changed, 90 insertions, 0 deletions
diff --git a/lass/2configs/green-hosts/plain-bindfs.nix b/lass/2configs/green-hosts/plain-bindfs.nix
new file mode 100644
index 000000000..81d8f20c2
--- /dev/null
+++ b/lass/2configs/green-hosts/plain-bindfs.nix
@@ -0,0 +1,90 @@
+# this seems to work, sadly there are no inotify events on the state directory because bindfs hides them,
+
+{ config, lib, pkgs, ... }:
+with import <stockholm/lib>;
+
+let
+
+ cname = "green-plain";
+
+in {
+ imports = [
+ <stockholm/lass/2configs/container-networking.nix>
+ <stockholm/lass/2configs/syncthing.nix>
+ ];
+
+ programs.fuse.userAllowOther = true;
+
+ services.syncthing.declarative.folders."/var/lib/containers/${cname}/var/state" = {
+ devices = [ "icarus" "skynet" "littleT" "shodan" "mors" "morpheus" ];
+ ignorePerms = false;
+ };
+
+ lass.bindfs."/var/lib/containers/${cname}/var/state" = {
+ source = "/var/lib/containers/${cname}/var/state";
+ options = [
+ "-M ${toString config.users.users.syncthing.uid} -u root -g root"
+ ];
+ };
+
+
+ systemd.services."container@${cname}".reloadIfChanged = mkForce false;
+ containers.${cname} = {
+ config = { ... }: {
+ environment.systemPackages = [
+ pkgs.git
+ pkgs.rxvt-unicode-unwrapped.terminfo
+ ];
+ services.openssh.enable = true;
+ users.users.root.openssh.authorizedKeys.keys = [
+ config.krebs.users.lass.pubkey
+ ];
+ system.activationScripts.fuse = {
+ text = ''
+ ${pkgs.coreutils}/bin/mknod /dev/fuse c 10 229
+ '';
+ deps = [];
+ };
+ };
+ allowedDevices = [
+ { modifier = "rwm"; node = "/dev/fuse"; }
+ ];
+ autoStart = false;
+ enableTun = true;
+ privateNetwork = true;
+ hostAddress = "10.233.2.15"; # TODO find way to automatically calculate IPs
+ localAddress = "10.233.2.16"; # TODO find way to automatically calculate IPs
+ };
+
+ environment.systemPackages = [
+ (pkgs.writeDashBin "start-${cname}" ''
+ set -euf
+ set -x
+
+ mkdir -p /var/lib/containers/${cname}/var/state
+
+ STATE=$(${pkgs.nixos-container}/bin/nixos-container status ${cname})
+ if [ "$STATE" = 'down' ]; then
+ ${pkgs.nixos-container}/bin/nixos-container start ${cname}
+ fi
+
+ ${pkgs.nixos-container}/bin/nixos-container run ${cname} -- ${pkgs.writeDash "deploy-${cname}" ''
+ set -x
+
+ mkdir -p /var/state/var_src
+ ln -sfTr /var/state/var_src /var/src
+ touch /etc/NIXOS
+ ''}
+
+ if [ -h /var/lib/containers/${cname}/var/src/nixos-config ] && (! ping -c1 -q -w5 ${cname}.r); then
+ ${pkgs.nixos-container}/bin/nixos-container run ${cname} -- nixos-rebuild -I /var/src switch
+ fi
+ '')
+ (pkgs.writeDashBin "stop-${cname}" ''
+ set -euf
+
+ ${pkgs.nixos-container}/bin/nixos-container stop ${cname}
+ '')
+ ];
+}
+