2023-05-05 19:00:50 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.tinyproxy;
|
|
|
|
mkValueStringTinyproxy = with lib; v:
|
|
|
|
if true == v then "yes"
|
|
|
|
else if false == v then "no"
|
2024-02-15 12:22:16 +00:00
|
|
|
else if types.path.check v then ''"${v}"''
|
2023-05-05 19:00:50 +00:00
|
|
|
else generators.mkValueStringDefault {} v;
|
|
|
|
mkKeyValueTinyproxy = {
|
|
|
|
mkValueString ? mkValueStringDefault {}
|
|
|
|
}: sep: k: v:
|
|
|
|
if null == v then ""
|
|
|
|
else "${lib.strings.escape [sep] k}${sep}${mkValueString v}";
|
|
|
|
|
|
|
|
settingsFormat = (pkgs.formats.keyValue {
|
|
|
|
mkKeyValue = mkKeyValueTinyproxy {
|
|
|
|
mkValueString = mkValueStringTinyproxy;
|
|
|
|
} " ";
|
|
|
|
listsAsDuplicateKeys= true;
|
|
|
|
});
|
|
|
|
configFile = settingsFormat.generate "tinyproxy.conf" cfg.settings;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.tinyproxy = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "Tinyproxy daemon";
|
2023-11-30 18:03:14 +00:00
|
|
|
package = mkPackageOption pkgs "tinyproxy" {};
|
2023-05-05 19:00:50 +00:00
|
|
|
settings = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Configuration for [tinyproxy](https://tinyproxy.github.io/).";
|
2023-05-05 19:00:50 +00:00
|
|
|
default = { };
|
|
|
|
example = literalExpression ''{
|
|
|
|
Port 8888;
|
|
|
|
Listen 127.0.0.1;
|
|
|
|
Timeout 600;
|
|
|
|
Allow 127.0.0.1;
|
|
|
|
Anonymous = ['"Host"' '"Authorization"'];
|
|
|
|
ReversePath = '"/example/" "http://www.example.com/"';
|
|
|
|
}'';
|
|
|
|
type = types.submodule ({name, ...}: {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
options = {
|
|
|
|
Listen = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-05-05 19:00:50 +00:00
|
|
|
Specify which address to listen to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
Port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8888;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-05-05 19:00:50 +00:00
|
|
|
Specify which port to listen to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
Anonymous = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-05-05 19:00:50 +00:00
|
|
|
If an `Anonymous` keyword is present, then anonymous proxying is enabled. The headers listed with `Anonymous` are allowed through, while all others are denied. If no Anonymous keyword is present, then all headers are allowed through. You must include quotes around the headers.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
Filter = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-05-05 19:00:50 +00:00
|
|
|
Tinyproxy supports filtering of web sites based on URLs or domains. This option specifies the location of the file containing the filter rules, one rule per line.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.tinyproxy = {
|
|
|
|
description = "TinyProxy daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "tinyproxy";
|
|
|
|
Group = "tinyproxy";
|
|
|
|
Type = "simple";
|
2023-12-13 10:50:27 +00:00
|
|
|
ExecStart = "${getExe cfg.package} -d -c ${configFile}";
|
2023-05-05 19:00:50 +00:00
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -SIGHUP $MAINPID";
|
|
|
|
KillSignal = "SIGINT";
|
|
|
|
TimeoutStopSec = "30s";
|
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.tinyproxy = {
|
|
|
|
group = "tinyproxy";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
users.groups.tinyproxy = {};
|
|
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ tcheronneau ];
|
|
|
|
}
|