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