update workflow

This commit is contained in:
Sense T 2024-01-08 13:03:12 +08:00
parent cce1c1f059
commit dde441bf9f
2 changed files with 40 additions and 1 deletions

View File

@ -3,7 +3,9 @@ FROM alpine as build
ENV RUSTFLAGS="-C target-feature=-crt-static" ENV RUSTFLAGS="-C target-feature=-crt-static"
WORKDIR /usr/src/saysthbot WORKDIR /usr/src/saysthbot
COPY . . 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 FROM alpine

View File

@ -39,6 +39,7 @@
openssl openssl
]; ];
}; };
devShell = with pkgs; mkShell { devShell = with pkgs; mkShell {
buildInputs = [ buildInputs = [
cargo cargo
@ -53,5 +54,41 @@
]; ];
RUST_SRC_PATH = rustPlatform.rustLibSrc; 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}";
};
};
};
}); });
} }