mirror of
https://github.com/mat-1/metasearch2.git
synced 2025-08-02 15:26:04 +00:00
spread the Nix infection (#18)
* flake-utils -> flake-parts * add nixos module * expose metasearch settings * nix fmt * fix enable option * add openFirewall option * nits * add logging option
This commit is contained in:
parent
bb6a1353dc
commit
9a2a00bce9
3 changed files with 120 additions and 42 deletions
37
flake.lock
generated
37
flake.lock
generated
|
@ -15,21 +15,23 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
"nixpkgs-lib": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1726560853,
|
||||
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
|
||||
"lastModified": 1733312601,
|
||||
"narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
|
@ -52,24 +54,9 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"crane": "crane",
|
||||
"flake-utils": "flake-utils",
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
50
flake.nix
50
flake.nix
|
@ -6,14 +6,27 @@
|
|||
|
||||
crane.url = "github:ipetkov/crane";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
flake-parts = {
|
||||
url = "github:hercules-ci/flake-parts";
|
||||
inputs.nixpkgs-lib.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, crane, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
outputs = inputs @ {
|
||||
self,
|
||||
crane,
|
||||
flake-parts,
|
||||
...
|
||||
}:
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
systems = ["x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux"];
|
||||
flake.nixosModules.default = import ./module.nix self;
|
||||
|
||||
perSystem = {
|
||||
pkgs,
|
||||
system,
|
||||
...
|
||||
}: let
|
||||
craneLib = crane.mkLib pkgs;
|
||||
|
||||
assetFilter = path: _type: (pkgs.lib.strings.hasPrefix (toString ./src/web/assets) path);
|
||||
|
@ -34,27 +47,29 @@
|
|||
];
|
||||
};
|
||||
|
||||
metasearch2 = craneLib.buildPackage (commonArgs // {
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
metasearch2 = craneLib.buildPackage (commonArgs
|
||||
// {
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
# Additional environment variables or build phases/hooks can be set
|
||||
# here *without* rebuilding all dependency crates
|
||||
# MY_CUSTOM_VAR = "some value";
|
||||
});
|
||||
in {
|
||||
formatter = pkgs.alejandra;
|
||||
|
||||
# Additional environment variables or build phases/hooks can be set
|
||||
# here *without* rebuilding all dependency crates
|
||||
# MY_CUSTOM_VAR = "some value";
|
||||
});
|
||||
in
|
||||
{
|
||||
checks = {
|
||||
inherit metasearch2;
|
||||
};
|
||||
|
||||
packages.default = metasearch2;
|
||||
|
||||
apps.default = flake-utils.lib.mkApp {
|
||||
drv = metasearch2;
|
||||
apps.default = {
|
||||
type = "app";
|
||||
program = "${self.packages.${system}.default}/bin/metasearch";
|
||||
};
|
||||
|
||||
devShells.default = craneLib.devShell {
|
||||
# Inherit inputs from checks.
|
||||
checks = self.checks.${system};
|
||||
|
||||
# Additional dev-shell environment variables can be set directly
|
||||
|
@ -65,5 +80,6 @@
|
|||
# pkgs.ripgrep
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
75
module.nix
Normal file
75
module.nix
Normal file
|
@ -0,0 +1,75 @@
|
|||
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];
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue