mirror of
https://github.com/mat-1/metasearch2.git
synced 2025-08-02 15:26:04 +00:00
* flake-utils -> flake-parts * add nixos module * expose metasearch settings * nix fmt * fix enable option * add openFirewall option * nits * add logging option
75 lines
1.8 KiB
Nix
75 lines
1.8 KiB
Nix
self: {
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}: let
|
|
cfg = config.services.metasearch;
|
|
port =
|
|
if lib.hasAttr "bind" cfg.settings
|
|
then lib.toInt (builtins.elemAt (lib.splitString ":" cfg.settings.bind) 1)
|
|
else 28019;
|
|
|
|
settingArg =
|
|
if cfg.settings != {}
|
|
then " " + pkgs.writers.writeTOML "metasearch.toml" cfg.settings
|
|
else "";
|
|
|
|
loggingArg =
|
|
if !cfg.enableLogging
|
|
then " > /dev/null"
|
|
else "";
|
|
in {
|
|
options.services.metasearch = {
|
|
enable = lib.mkEnableOption "metasearch";
|
|
openFirewall = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = ''
|
|
Open firewall ports used by metasearch.
|
|
'';
|
|
};
|
|
enableLogging = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = false;
|
|
description = ''
|
|
Enable metasearch logging. Does not affect stderr.
|
|
'';
|
|
};
|
|
settings = lib.mkOption {
|
|
type = lib.types.attrs;
|
|
default = {};
|
|
description = ''
|
|
Optional metasearch configuration. If not defined, defaults in `src/config.rs` will be used
|
|
'';
|
|
example = {
|
|
bind = "0.0.0.0:4444";
|
|
ui.show_version_info = true;
|
|
urls = {
|
|
replace = {
|
|
"www.reddit.com" = "old.reddit.com";
|
|
};
|
|
|
|
weight = {
|
|
"quora.com" = 0.1;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
systemd.services.metasearch = {
|
|
wantedBy = ["multi-user.target"];
|
|
after = ["network.target"];
|
|
description = "a cute metasearch engine";
|
|
serviceConfig = {
|
|
ExecStart = "${self.packages.${pkgs.system}.default}/bin/metasearch" + settingArg + loggingArg;
|
|
};
|
|
};
|
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
|
allowedTCPPorts = [port];
|
|
};
|
|
};
|
|
}
|