summaryrefslogtreecommitdiff
path: root/hosts/vidhar/printing/default.nix
blob: 55c55b3742da0650194aa8def99c01fec9f508ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{ config, lib, ... }:

with lib;

let
  containerConfig = config.containers.printing.config;
in {
  config = {
    containers.printing = {
      privateNetwork = true;
      ephemeral = true;
      autoStart = true;
      hostAddress = "10.141.5.0";
      hostAddress6 = "2a03:4000:52:ada:5::";
      localAddress = "10.141.5.1";
      localAddress6 = "2a03:4000:52:ada:5::1";
      interfaces = [ "printer" ];
      config = let
        hostConfig = config;
      in { ... }: {
        config = {
          services = {
            kea = {
              dhcp4 = {
                enable = true;
                settings = {
                  valid-lifetime = 4000;
                  rebind-timer = 2000;
                  renew-timer = 1000;

                  interfaces-config = {
                    interfaces = [ "printer" ];
                  };

                  lease-database = {
                    name = "/var/lib/kea/dhcp4.leases";
                    persist = true;
                    type = "memfile";
                  };

                  subnet4 = [
                    { subnet = "10.141.3.0/24";
                      option-data = [
                        { name = "domain-name-servers";
                          data = "10.141.5.0";
                        }
                        { name = "ntp-servers";
                          data = "10.141.5.0";
                        }
                        { name = "broadcast-address";
                          data = "10.141.3.255";
                        }
                        { name = "routers";
                          data = "10.141.3.1";
                        }
                        { name = "domain-name";
                          data = "yggdrasil";
                        }
                        { name = "domain-search";
                          data = "printer.yggdrasil, yggdrasil";
                        }
                      ];
                      pools = [ { pool = "10.141.3.128 - 10.141.3.254"; } ];
                      reservations = [
                        { hostname = "printer";
                          hw-address = "30:cd:a7:b0:55:8d";
                          ip-address = "10.141.3.2";
                        }
                      ];
                    }
                  ];
                };
              };
            };

            printing = {
              enable = true;
              listenAddresses = [
                "*:631"
              ];
              logLevel = "all";
              extraConf = mkForce ''
                ServerName printing
                ServerAlias 10.141.5.1 2a03:4000:52:ada:5::1 printing.vidhar.yggdrasil printing.vidhar.lan.yggdrasil

                DefaultEncryption Never

                <Location />
                  Order allow,deny
                  Allow from 10.0.0.0/8
                  Satisfy any
                </Location>

                <Location /admin>
                  Order allow,deny
                  Allow from 10.0.0.0/8
                  Satisfy any
                </Location>

                <Location /admin/conf>
                  Order allow,deny
                  Allow from 10.0.0.0/8
                  Satisfy any
                </Location>

                <Policy default>
                  <Limit Send-Document Send-URI Hold-Job Release-Job Restart-Job Purge-Jobs Set-Job-Attributes Create-Job-Subscription Renew-Subscription Cancel-Subscription Get-Notifications Reprocess-Job Cancel-Current-Job Suspend-Current-Job Resume-Job CUPS-Move-Job>
                    Order allow,deny
                    Allow from 10.0.0.0/8
                    Satisfy any
                  </Limit>

                  <Limit Pause-Printer Resume-Printer Set-Printer-Attributes Enable-Printer Disable-Printer Pause-Printer-After-Current-Job Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer Activate-Printer Restart-Printer Shutdown-Printer Startup-Printer Promote-Job Schedule-Job-After CUPS-Add-Printer CUPS-Delete-Printer CUPS-Add-Class CUPS-Delete-Class CUPS-Accept-Jobs CUPS-Reject-Jobs CUPS-Set-Default>
                    Order allow,deny
                    Allow from 10.0.0.0/8
                    Satisfy any
                  </Limit>

                  <Limit Cancel-Job CUPS-Authenticate-Job>
                    Order allow,deny
                    Allow from 10.0.0.0/8
                    Satisfy any
                  </Limit>

                  <Limit All>
                    Order allow,deny
                    Allow from 10.0.0.0/8
                    Satisfy any
                  </Limit>
                </Policy>
              '';
            };

            resolved.enable = false;
          };

          networking = {
            firewall.enable = false;
            nftables = {
              enable = true;
              rulesetFile = ./ruleset.nft;
            };

            useDHCP = false;
            useNetworkd = true;

            interfaces."printer" = {
              ipv4.addresses = [
                { address = "10.141.3.1"; prefixLength = 24; }
              ];
            };
          };

          environment.etc."resolv.conf".text = ''
            nameserver ${hostConfig.containers.printing.hostAddress6}
          '';

          system.stateVersion = hostConfig.system.stateVersion;
        };
      };
    };

    networking = {
      vlans.printer = {
        id = 5;
        interface = "eno2";
      };
    };
  };
}