]> Git — Sourcephile - julm/julm-nix.git/blob - nixos/profiles/openvpn/calyx.nix
nix: update nixpkgs
[julm/julm-nix.git] / nixos / profiles / openvpn / calyx.nix
1 { pkgs, lib, config, ... }:
2 let
3 netns = "calyx";
4 inherit (config.services) openvpn;
5 apiUrl = "https://api.calyx.net:4430/3/cert";
6 ca = pkgs.fetchurl
7 {
8 url = "https://calyx.net/ca.crt";
9 hash = "sha256-NKLkpjjeGMN07htuWydBMQ03ytxF9CLm8SLNl3IPPGc=";
10 curlOptsList = [ "-k" ];
11 } + "";
12 key-cert = "/run/openvpn-${netns}/key+cert.pem";
13 in
14 {
15 services.openvpn.servers.${netns} = {
16 inherit netns;
17 settings = {
18 remote =
19 # new-york
20 [ "162.247.73.193" ] ++
21 [ ];
22 remote-random = true;
23 port = "443";
24 proto = "tcp";
25 inherit ca;
26 key = key-cert;
27 cert = key-cert;
28
29 auth = "SHA1";
30 cipher = "AES-128-CBC";
31 client = true;
32 dev = "ov-${netns}";
33 dev-type = "tun";
34 keepalive = "10 30";
35 nobind = true;
36 persist-key = true;
37 persist-tun = true;
38 remote-cert-tls = "server";
39 reneg-sec = 0;
40 script-security = 2;
41 tls-cipher = "TLS-DHE-RSA-WITH-AES-128-CBC-SHA";
42 tls-client = true;
43 tun-ipv6 = true;
44 up-restart = true;
45 verb = 3;
46 };
47 };
48 systemd.services."openvpn-${netns}" = {
49 after = [ "network-online.target" ];
50 preStart = ''
51 (
52 set -ex
53 ${pkgs.curl}/bin/curl -X POST --cacert ${ca} -o ${key-cert} -Ls ${apiUrl}
54 chmod 700 ${key-cert}
55 )
56 '';
57 serviceConfig = {
58 RuntimeDirectory = [ "openvpn-${netns}" ];
59 RuntimeDirectoryMode = "0700";
60 };
61 };
62 networking.nftables.ruleset = ''
63 table inet filter {
64 chain output-net {
65 skuid root tcp dport https counter accept comment "OpenVPN Calyx"
66 skuid root tcp dport 4430 counter accept comment "OpenVPN Calyx (API)"
67 }
68 }
69 '';
70 services.netns.namespaces.${netns} = {
71 nftables = lib.mkBefore ''
72 include "${../networking/nftables.txt}"
73 '';
74 };
75 }