Want to contribute? Fork me on Codeberg.org!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.2 KiB

{
description = "Miscellaneous utility APIs hosted on jichan.org";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, rust-overlay }:
let
overlays = [ (import rust-overlay) ];
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system overlays;
};
rustSettings = with pkgs; {
src = ./.;
nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl ];
cargoHash = nixpkgs.lib.fakeHash;
};
meta = with nixpkgs.lib; {
homepage = "https://jichan.org";
license = [ licenses.gpl3 ];
platforms = [ system ];
maintainers = with maintainers; [ elnudev ];
};
in {
devShells.${system}.default = with pkgs; mkShell {
packages = [
(pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
})
bacon
];
inputsFrom = with self.packages.${system}; [ tatoeba images ];
};
packages.${system} = {
tatoeba = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "tatoeba";
version = "0.1.0";
buildAndTestSubdir = "tatoeba";
cargoHash = "sha256-/mtl2kes7KmT3Vq+M/kpezhRTKLju3ZRXHFf2Zblczo=";
meta = meta // {
description = "A proxy of the Tatoeba API with no CORS restrictions.";
};
});
images = pkgs.rustPlatform.buildRustPackage (rustSettings // {
pname = "images";
version = "0.1.0";
buildAndTestSubdir = "images";
cargoHash = "sha256-sxge+4WuT8iEVihiqvUAdS+n6U+NzEhfJ0p7lc+uLHE=";
meta = meta // {
description = "An API for fetching images of a query, sourced from Microsoft Bing.";
};
});
};
nixosModules.default = { config, ... }: let
lib = nixpkgs.lib;
in {
# tatoeba
options.services.tatoeba = {
enable = lib.mkEnableOption (lib.mdDoc "tatoeba service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.tatoeba;
defaultText = "pkgs.tatoeba";
description = lib.mdDoc ''
The tatoeba package that should be used.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 3001;
description = lib.mdDoc ''
The port at which to run.
'';
};
};
config.systemd.services.tatoeba = let
cfg = config.services.tatoeba;
pkg = self.packages.${system}.tatoeba;
in lib.mkIf cfg.enable {
description = pkg.meta.description;
after = [ "network.target" ];
wantedBy = [ "network.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/tatoeba --port ${builtins.toString cfg.port}
'';
Restart = "always";
DynamicUser = true;
};
};
# images
options.services.images = {
enable = lib.mkEnableOption (lib.mdDoc "images service");
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${system}.images;
defaultText = "pkgs.images";
description = lib.mdDoc ''
The images package that should be used.
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 3002;
description = lib.mdDoc ''
The port at which to run.
'';
};
};
config.systemd.services.images = let
cfg = config.services.images;
pkg = self.packages.${system}.images;
in lib.mkIf cfg.enable {
description = pkg.meta.description;
after = [ "network.target" ];
wantedBy = [ "network.target" ];
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/images --port ${builtins.toString cfg.port}
'';
Restart = "always";
DynamicUser = true;
};
};
};
};
}