diff --git a/nix_flake/flake.nix b/nix_flake/flake.nix index 0a687b8..e429505 100644 --- a/nix_flake/flake.nix +++ b/nix_flake/flake.nix @@ -42,6 +42,7 @@ # NixOS Modules nixosModules = { quickpeepSearch = import ./modules/quickpeepSearch.nix self; + quickpeepRaker = import ./modules/quickpeepRaker.nix self; }; # `nix run` diff --git a/nix_flake/modules/quickpeepRaker.nix b/nix_flake/modules/quickpeepRaker.nix new file mode 100644 index 0000000..2e00a2c --- /dev/null +++ b/nix_flake/modules/quickpeepRaker.nix @@ -0,0 +1,88 @@ +flake: {config, pkgs, lib, ...}: + +let + cfg = config.services.quickpeepRaker; + inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) quickpeep; +in + +with lib; + +{ + options = { + services.quickpeepRaker = { + enable = mkOption { + default = false; + type = with types; bool; + description = '' + Start the QuickPeep Raker. + ''; + }; + + user = mkOption { + default = "quickpeep"; + type = with types; uniq str; + description = '' + Name of the user. + ''; + }; + +# metricsBind = mkOption { +# default = null; +# example = "127.0.0.1:1234"; +# type = with types; nullOr str; +# description = '' +# Host and port upon which to bind the Prometheus/OpenMetrics interface. +# ''; +# }; + + configPath = mkOption { + type = with types; path; + description = '' + Config path to use, in RON format. + ''; + }; + + concurrency = mkOption { + type = types.int; + default = 8; + description = '' + Number of concurrent fetches to allow. + ''; + }; + + sleepers = mkOption { + type = types.int; + default = 56; + description = '' + An additional number of tasks to permit in the sleeping state. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + users.users."${cfg.user}" = { + description = "QuickPeep User"; + isSystemUser = true; + group = "${cfg.user}"; + }; + users.groups."${cfg.user}" = {}; + + systemd.services.quickpeepRaker = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + description = "Rakes websites and converts them to an indexable format."; + + environment = { + QUICKPEEP_CONFIG = cfg.configPath; + }; + serviceConfig = { + # TODO disable automatic restart? + # TODO start it on a timer to ensure it picks up updates to stuff..? + Type = "simple"; + User = "${cfg.user}"; + ExecStart = ''${quickpeep}/bin/qp-raker --config ${cfg.configPath} --concurrency ${builtins.toString cfg.concurrency} --sleepers ${builtins.toString cfg.sleepers}''; + }; + }; + }; +}