diff --git a/Dockerfile b/Dockerfile index 65e1b25..2468d61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,9 @@ FROM alpine as build ENV RUSTFLAGS="-C target-feature=-crt-static" WORKDIR /usr/src/saysthbot COPY . . -RUN apk add --no-cache rustup openssl-dev build-base && rustup-init -y --default-toolchain nightly && source ${HOME}/.cargo/env && cargo build --release +RUN apk add --no-cache rustup openssl-dev build-base && \ + rustup-init -y --default-toolchain nightly && \ + source ${HOME}/.cargo/env && cargo build --release FROM alpine diff --git a/flake.nix b/flake.nix index 19ab244..55dd20b 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,7 @@ openssl ]; }; + devShell = with pkgs; mkShell { buildInputs = [ cargo @@ -53,5 +54,41 @@ ]; RUST_SRC_PATH = rustPlatform.rustLibSrc; }; + + nixosModule = {config, pkgs, lib, ...}: with lib; + let + cfg = config.services.hangitbot; + in { + options.services.hangitbot = { + enable = mkEnableOption "hangitbot service"; + + token = mkOption { + type = types.str; + example = "12345678:AAAAAAAAAAAAAAAAAAAAAAAAATOKEN"; + description = lib.mdDoc "Telegram bot token"; + }; + + tgUri = mkOption { + type = types.str; + default = "https://api.telegram.org"; + example = "https://api.telegram.org"; + description = lib.mdDoc "Custom telegram api URI"; + }; + + extraOptions = mkOption { + type = types.str; + description = lib.mdDoc "Extra option for bot."; + }; + }; + + config = let + args = "${cfg.extraOptions} ${if isString cfg.tgUri then "--api-uri ${escapeShellArg cfg.tgUri}" else ""}"; + in mkIf cfg.enable { + systemd.services.hangitbot = { + wantedBy = ["multi-uesr.target"]; + serviceconfig.ExecStart = "${pkgs.hangitbot}/bin/hangitbot ${args} ${escapeShellArg cfg.token}"; + }; + }; + }; }); }