summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2021-08-06 16:20:44 +0200
committerQuentin Aristote <quentin@aristote.fr>2021-08-06 16:20:44 +0200
commit210d4e7c2e7102355e8ef92681800157faa57d16 (patch)
treec1c599a66e34cc86056c094c438fe742ae41c03e /modules
initial commit
Diffstat (limited to 'modules')
-rw-r--r--modules/default.nix7
-rw-r--r--modules/filtron.nix87
2 files changed, 94 insertions, 0 deletions
diff --git a/modules/default.nix b/modules/default.nix
new file mode 100644
index 0000000..d09a8c0
--- /dev/null
+++ b/modules/default.nix
@@ -0,0 +1,7 @@
+{ ... }:
+
+{
+ imports = [
+ ./filtron.nix
+ ];
+}
diff --git a/modules/filtron.nix b/modules/filtron.nix
new file mode 100644
index 0000000..55374a7
--- /dev/null
+++ b/modules/filtron.nix
@@ -0,0 +1,87 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+ cfg = config.services.filtron;
+ addressType = types.submodule {
+ options = {
+ address = mkOption {
+ type = types.str;
+ default = "127.0.0.1";
+ };
+ port = mkOption { type = types.port; };
+ };
+ };
+in {
+ options.services.filtron = {
+ enable = mkEnableOption { name = "filtron"; };
+ package = mkOption {
+ type = types.package;
+ default = pkgs.personal.filtron;
+ defaultText = literalExample "pkgs.personal.filtron";
+ description = ''
+ The package containing the filtron executable.
+ '';
+ };
+ api = mkOption {
+ type = addressType;
+ default = { address = "localhost"; port = 4005; };
+ description = ''
+ API listen address and port.
+ '';
+ };
+ listen = mkOption {
+ type = addressType;
+ default = { port = 4004; };
+ description = ''
+ Proxy listen address and port.
+ '';
+ };
+ target = mkOption {
+ type = addressType;
+ default = { port = 8888; };
+ description = ''
+ Target address and port for reverse proxy.
+ '';
+ };
+ rules = mkOption {
+ type = with types; listOf (attrsOf anything);
+ description = ''
+ Rule list.
+ '';
+ };
+ readBufferSize = mkOption {
+ type = types.int;
+ default = 16384;
+ description = ''
+ Size of the buffer used for reading.
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ users.users.filtron = {
+ description = "Filtron daemon user";
+ group = "filtron";
+ isSystemUser = true;
+ };
+ users.groups.filtron = { };
+
+ systemd.services.filtron = {
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+ description = "Start a filtron instance.";
+ serviceConfig = {
+ User = "filtron";
+ ExecStart = with builtins; ''
+ ${cfg.package}/bin/filtron \
+ -rules ${toFile "filtron-rules.json" (toJSON cfg.rules)} \
+ -api "${cfg.api.address}:${toString cfg.api.port}" \
+ -listen "${cfg.listen.address}:${toString cfg.listen.port}" \
+ -target "${cfg.target.address}:${toString cfg.target.port}" \
+ -read-buffer-size ${toString cfg.readBufferSize}
+ '';
+ };
+ };
+ };
+}