diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7e177f6..528a80a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ docs/_book # TODO: where does this rule come from? test/ +.direnv \ No newline at end of file diff --git a/README.md b/README.md index e5f838a..745b857 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # reCoreD-UI -Web UI for CoreDNS \ No newline at end of file +Web UI for CoreDNS diff --git a/TODO b/TODO new file mode 100644 index 0000000..e3c08ea --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +- [] Nix Module +- [] RBAC \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..1db400a --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..020a49c --- /dev/null +++ b/flake.nix @@ -0,0 +1,96 @@ +{ + nixConfig = rec { + experimental-features = [ "nix-command" "flakes" ]; + + substituters = [ + # Replace official cache with a mirror located in China + # + # Feel free to remove this line if you are not in China + "https://mirrors.ustc.edu.cn/nix-channels/store" + "https://mirrors.ustc.edu.cn/nix-channels/store" # 中科大 + "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" #清华 + "https://mirrors.bfsu.edu.cn/nix-channels/store" # 北外 + "https://mirror.sjtu.edu.cn/nix-channels/store" #交大 + #"https://cache.nixos.org" + ]; + trusted-substituters = substituters; + trusted-users = [ + "coder" + ]; + }; + + inputs = { + naersk.url = "github:nix-community/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils, naersk }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + naersk-lib = pkgs.callPackage naersk { }; + in + { + defaultPackage = naersk-lib.buildPackage { + src = ./.; + buildInputs = with pkgs; [ + pkg-config + openssl + ]; + }; + + devShell = with pkgs; mkShell { + buildInputs = [ + go + npm + ]; + }; + + nixosModule = { config, pkgs, lib, ... }: with lib; + let + cfg = config.services.recored-ui; + in + { + options.services.hangitbot = { + enable = mkEnableOption "reCoreD-UI 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"; + }; + + groupBanned = mkOption { + type = types.listOf types.int; + default = [ ]; + description = lib.mdDoc "GroupID blacklisted"; + }; + + extraOptions = mkOption { + type = types.str; + description = lib.mdDoc "Extra option for bot."; + default = ""; + }; + }; + + config = + let + args = "${cfg.extraOptions} ${if cfg?tgUri then "--api-uri ${escapeShellArg cfg.tgUri}" else ""} ${if cfg?groupBanned then concatStringsSep " " (lists.concatMap (group: ["-b ${group}"]) cfg.groupBanned) else ""}"; + in + mkIf cfg.enable { + systemd.services.hangitbot = { + wantedBy = [ "multi-uesr.target" ]; + serviceconfig.ExecStart = "${pkgs.hangitbot}/bin/hangitbot ${args} ${escapeShellArg cfg.token}"; + }; + }; + }; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..77db547 --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix