9 cfg = config.services.lokinet;
10 dataDir = "/var/lib/lokinet";
11 settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; };
12 configFile = settingsFormat.generate "lokinet.ini" (
13 lib.filterAttrsRecursive (n: v: v != null) cfg.settings
18 options.services.lokinet = {
19 enable = mkEnableOption "Lokinet daemon";
21 package = mkPackageOption pkgs "lokinet" { };
23 useLocally = mkOption {
27 description = "Whether to use Lokinet locally.";
34 freeformType = settingsFormat.type;
40 default = "127.3.2.1";
41 description = "Address to bind to for handling DNS requests.";
46 default = [ "9.9.9.10" ];
52 Upstream resolver(s) to use as fallback for non-loki addresses.
53 Multiple values accepted.
63 Whether to act as an exit node. Beware that this
64 increases demand on the server and may pose liability concerns.
65 Enable at your own risk.
69 exit-node = mkOption {
70 type = nullOr (listOf str);
73 exit-node = [ "example.loki" ]; # maps all exit traffic to example.loki
74 exit-node = [ "example.loki:100.0.0.0/24" ]; # maps 100.0.0.0/24 to example.loki
77 Specify a `.loki` address and an optional ip range to use as an exit broker.
78 See <http://probably.loki/wiki/index.php?title=Exit_Nodes> for
86 example = "snappkey.private";
88 The private key to persist address with. If not specified the address will be ephemeral.
89 This keyfile is generated automatically if the specified file doesn't exist.
96 example = literalExpression ''
100 upstream = [ "1.1.1.1" "8.8.8.8" ];
103 network.exit-node = [ "example.loki" "example2.loki" ];
107 Configuration for Lokinet.
108 Currently, the best way to view the available settings is by
109 generating a config file using `lokinet -g`.
114 config = mkIf cfg.enable {
115 networking.resolvconf.extraConfig = mkIf cfg.useLocally ''
116 name_servers="${cfg.settings.dns.bind}"
119 systemd.services.lokinet = {
120 description = "Lokinet";
122 "network-online.target"
126 "network-online.target"
129 wantedBy = [ "multi-user.target" ];
132 ln -sf ${cfg.package}/share/bootstrap.signed ${dataDir}
133 ${pkgs.coreutils}/bin/install -m 600 ${configFile} ${dataDir}/lokinet.ini
135 ${optionalString (cfg.settings.network.keyfile != null) ''
136 ${pkgs.crudini}/bin/crudini --set ${dataDir}/lokinet.ini network keyfile "${dataDir}/${cfg.settings.network.keyfile}"
142 StateDirectory = "lokinet";
143 AmbientCapabilities = [
145 "CAP_NET_BIND_SERVICE"
147 ExecStart = "${cfg.package}/bin/lokinet ${dataDir}/lokinet.ini";
152 LockPersonality = true;
153 MemoryDenyWriteExecute = true;
154 NoNewPrivileges = true;
156 PrivateMounts = true;
157 ProtectControlGroups = true;
159 ProtectHostname = true;
160 ProtectKernelLogs = true;
161 ProtectKernelModules = true;
162 ProtectKernelTunables = true;
163 ProtectSystem = "strict";
164 ReadWritePaths = "/dev/net/tun";
165 RestrictAddressFamilies = [
171 RestrictNamespaces = true;
172 RestrictRealtime = true;
173 RestrictSUIDSGID = true;
177 environment.systemPackages = [ cfg.package ];