diff --git a/flake.nix b/flake.nix index 8bcb794..03a0003 100644 --- a/flake.nix +++ b/flake.nix @@ -6,20 +6,29 @@ flake-utils.url = "github:numtide/flake-utils"; nix-filter.url = "github:numtide/nix-filter"; gomod2nix = { - url = "github:nix-community/gomod2nix"; - inputs.nixpkgs.follows = "nixpkgs"; + url = "github:nix-community/gomod2nix"; + inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = { self, nixpkgs, flake-utils, gomod2nix, nix-filter }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + flake-utils, + gomod2nix, + nix-filter, + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = import nixpkgs { - inherit system; - overlays = [ gomod2nix.overlays.default ]; + inherit system; + overlays = [ gomod2nix.overlays.default ]; }; in - with pkgs; { + with pkgs; + rec { devShells.default = mkShell { name = "watgbridge-dev"; @@ -34,6 +43,11 @@ hardeningDisable = [ "fortify" ]; }; + apps.default = { + type = "app"; + program = "${packages.default}/bin/watgbridge"; + }; + packages = rec { watgbridge = (pkgs.callPackage ./nix/pkgs/watgbridge-dev.nix { inherit nix-filter; }); default = watgbridge; @@ -43,14 +57,13 @@ watgbridge = (pkgs.callPackage ./nix/pkgs/watgbridge-dev.nix { inherit nix-filter; }); }; - nixosModules.default = import ./nix/modules/nixos self; - homeManagerModules.default = import ./nix/modules/home-manager self; - } ); nixConfig = { extra-substituters = [ "https://watgbridge.cachix.org" ]; - extra-trusted-public-keys = [ "watgbridge.cachix.org-1:KSfgmbSBvXQTpUnoCj21vST7zgwpy3SbNfk0/nesR1Y=" ]; + extra-trusted-public-keys = [ + "watgbridge.cachix.org-1:KSfgmbSBvXQTpUnoCj21vST7zgwpy3SbNfk0/nesR1Y=" + ]; }; } diff --git a/nix/modules/commonOptions.nix b/nix/modules/commonOptions.nix deleted file mode 100644 index fae606f..0000000 --- a/nix/modules/commonOptions.nix +++ /dev/null @@ -1,92 +0,0 @@ -{ - lib, - package, -}: let - inherit (lib) mkEnableOption mkOption types; -in { - enable = mkEnableOption "WaTgBridge services"; - - commonSettings.package = mkOption { - type = types.package; - default = package; - }; - - commonSettings.maxRuntime = mkOption { - type = types.nullOr types.str; - default = "1d"; - }; - - commonSettings.requires = mkOption { - type = types.nullOr (types.listOf types.str); - default = null; - }; - - instances = mkOption { - type = types.attrsOf(types.submodule { - options = { - - enable = mkEnableOption "Enable the instance"; - - name = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - The name of the instance. The corresponding systemd service will be called `watgbridge-.service`. - - By default, the key of the instance in the attrset will be used. - ''; - }; - - package = mkOption { - type = types.nullOr types.package; - default = null; - description = '' - The WaTgBridge package to use for the instance. - - By default the common package defined will be used. - ''; - }; - - configPath = mkOption { - type = types.nullOr (types.either (types.str types.path)); - default = null; - description = '' - The path to the config file that will be loaded by WaTgBridge. - - By default, WaTgBridge loads config from config.yaml in the current working directory. - ''; - }; - - workingDirectory = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - The directory from which the WaTgBridge binary will be executed. - - If not provided, it will use systemd's default working directory. - ''; - }; - - maxRuntime = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - Max time in seconds (according to systemd's units) after which the service will be automatically restarted. - - If not provided, it will use the common setting (which is 1d, i.e. 1 day). - ''; - }; - - requires = mkOption { - type = types.nullOf (types.listOf types.str); - default = null; - description = '' - The systemd services to wait for before starting watbridge. "network.target" is added to the module itself. This option is meant to be used for stuff like Telegram Bot API service. - - If not provided, it will use the common setting - ''; - }; - }; - }); - }; -} diff --git a/nix/modules/home-manager/default.nix b/nix/modules/home-manager/default.nix deleted file mode 100644 index 190c78b..0000000 --- a/nix/modules/home-manager/default.nix +++ /dev/null @@ -1,74 +0,0 @@ -self: { - lib, - config, - pkgs, - ... -}: let - inherit (pkgs.stdenv.hostPlatform) system; - inherit (lib) mapAttrs' mkIf; - cfg = config.services.watgbridge; - - package = self.packages."${system}".watgbridge; -in { - options = { - services.watgbridge = import ../commonOptions.nix { inherit lib package; }; - }; - - config = mkIf cfg.enable { - home.packages = [ cfg.package ]; - - systemd.user.services = mapAttrs' (key: settings: let - - instanceName = ( - if settings.name != null then - "watgbridge-${settings.name}" - else - "watgbridge-${key}" - ); - watgbridgePackage = ( - if settings.package != null then - settings.package - else - cfg.commonSettings.package - ); - - maxRuntime = ( - if settings.maxRuntime != null then - settings.maxRuntime - else - cfg.commonSettings.maxRuntime - ); - - requires = ( - if settings.requires != null then - settings.requires - else - cfg.commonSettings.requires - ); - - in { - - name = instanceName; - - value = mkIf settings.enable { - Unit = { - Description = "WaTgBridge service for '${instanceName}'"; - Documentation = "https://github.com/akshettrj/watbridge"; - After = [ "network.target" ]; - } // lib.optionalAttrs (requires != null) { - Requires = requires; - }; - - Service = { - ExecStart = ''${watgbridgePackage}/bin/watbridge'' lib.optionalString (settings.configPath != null) '' "${settings.configPath}"''; - Restart = "on-failure"; - } // lib.optionalAttrs maxRuntime != null { - RuntimeMaxSec = maxRuntime; - }; - - Install = { WantedBy = ["default.target"]; }; - }; - - }) cfg.instances; - }; -} diff --git a/nix/modules/nixos/default.nix b/nix/modules/nixos/default.nix deleted file mode 100644 index 55bc167..0000000 --- a/nix/modules/nixos/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -self: { - lib, - config, - pkgs, - ... -}: let - inherit (pkgs.stdenv.hostPlatform) system; - inherit (lib) mkIf; - cfg = config.services.watgbridge; - - package = self.packages."${system}".watgbridge; -in { - options = { - services.watgbridge = import ../commonOptions.nix { inherit lib package; }; - }; - - config = mkIf cfg.enable { - assertions = [{ - assertion = false; - message = "The NixOS module is not complete yet. Use home-manager module for now if possible."; - }]; - - environment.systemPackages = [ cfg.package ]; - }; -} diff --git a/nix/pkgs/watgbridge-dev.nix b/nix/pkgs/watgbridge-dev.nix index 9b3989f..f0f1b90 100644 --- a/nix/pkgs/watgbridge-dev.nix +++ b/nix/pkgs/watgbridge-dev.nix @@ -1,10 +1,7 @@ -{ lib -, buildGoApplication -, enableFfmpeg ? true -, enableLibWebPTools ? true -, ffmpeg -, libwebp -, nix-filter +{ + lib, + buildGoApplication, + nix-filter, }: let @@ -28,22 +25,19 @@ let ]; }; -in buildGoApplication rec { +in +buildGoApplication rec { pname = "watgbridge"; - version = "1.10.1"; + version = "1.11.0"; pwd = localSrc; src = localSrc; - buildInputs = [ - ] ++ lib.optionals enableFfmpeg [ - ffmpeg - ] ++ lib.optionals enableLibWebPTools [ - libwebp + ldflags = [ + "-s" + "-w" ]; - ldflags = [ "-s" "-w" ]; - meta = with lib; rec { description = "A bridge between WhatsApp and Telegram written in Golang"; homepage = "https://github.com/watgbridge/watgbridge";