This repository has no description
2.5 kB
87 lines
1# this seems to work fine, downsides are, all state is owned by syncthing and could be read by the guests syncthing
2
3
4{ config, lib, pkgs, ... }:
5
6let
7
8 cname = "green-plain";
9
10in {
11 imports = [
12 <stockholm/lass/2configs/container-networking.nix>
13 <stockholm/lass/2configs/syncthing.nix>
14 ];
15
16 services.syncthing.declarative.folders."/var/lib/containers/${cname}/var/state" = {
17 devices = [ "icarus" "skynet" "littleT" "shodan" "mors" "morpheus" ];
18 ignorePerms = false;
19 };
20
21 krebs.permown."/var/lib/containers/${cname}/var/state" = {
22 file-mode = "u+rw";
23 directory-mode = "u+rwx";
24 owner = "syncthing";
25 keepGoing = true;
26 };
27
28 systemd.services."container@${cname}".reloadIfChanged = mkForce false;
29 containers.${cname} = {
30 config = { ... }: {
31 environment.systemPackages = [
32 pkgs.git
33 pkgs.rxvt-unicode-unwrapped.terminfo
34 ];
35 services.openssh.enable = true;
36 users.users.root.openssh.authorizedKeys.keys = [
37 config.krebs.users.lass.pubkey
38 ];
39 system.activationScripts.fuse = {
40 text = ''
41 ${pkgs.coreutils}/bin/mknod /dev/fuse c 10 229
42 '';
43 deps = [];
44 };
45 };
46 allowedDevices = [
47 { modifier = "rwm"; node = "/dev/fuse"; }
48 ];
49 autoStart = false;
50 enableTun = true;
51 privateNetwork = true;
52 hostAddress = "10.233.2.15"; # TODO find way to automatically calculate IPs
53 localAddress = "10.233.2.16"; # TODO find way to automatically calculate IPs
54 };
55
56 environment.systemPackages = [
57 (pkgs.writeDashBin "start-${cname}" ''
58 set -euf
59 set -x
60
61 mkdir -p /var/lib/containers/${cname}/var/state
62
63 STATE=$(${pkgs.nixos-container}/bin/nixos-container status ${cname})
64 if [ "$STATE" = 'down' ]; then
65 ${pkgs.nixos-container}/bin/nixos-container start ${cname}
66 fi
67
68 ${pkgs.nixos-container}/bin/nixos-container run ${cname} -- ${pkgs.writeDash "deploy-${cname}" ''
69 set -x
70
71 mkdir -p /var/state/var_src
72 ln -sfTr /var/state/var_src /var/src
73 touch /etc/NIXOS
74 ''}
75
76 if [ -h /var/lib/containers/${cname}/var/src/nixos-config ] && (! ping -c1 -q -w5 ${cname}.r); then
77 ${pkgs.nixos-container}/bin/nixos-container run ${cname} -- nixos-rebuild -I /var/src switch
78 fi
79 '')
80 (pkgs.writeDashBin "stop-${cname}" ''
81 set -euf
82
83 ${pkgs.nixos-container}/bin/nixos-container stop ${cname}
84 '')
85 ];
86}
87