diff --git a/.gitignore b/.gitignore index ca87ce37..5b021b64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ discordo* # Visual Studio Code -.vscode/ \ No newline at end of file +.vscode/ + +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..513eff46 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1714076141, + "narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..63572359 --- /dev/null +++ b/flake.nix @@ -0,0 +1,34 @@ +{ + description = "A lightweight, secure, and feature-rich Discord terminal client."; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs, ... }: + let + + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forSupportedSystems = f: + builtins.listToAttrs (builtins.map + (system: + { + name = system; + value = f system (import nixpkgs { inherit system; }); + }) + supportedSystems); + + in + { + packages = forSupportedSystems (system: pkgs: { + default = pkgs.callPackage ./nix/package.nix { }; + }); + homeManagerModules.default = import ./nix/hm-module.nix self; + }; +} + + diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 00000000..bde3c892 --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,62 @@ +self: { options, config, lib, pkgs, ... }: +let + settingsFormat = pkgs.formats.toml { }; +in +{ + options.programs.discordo = { + enable = lib.mkEnableOption "discordo"; + package = lib.mkOption { + type = lib.types.package; + default = self.packages.${pkgs.system}.default; + description = "The discordo package to use."; + }; + + settings = lib.mkOption { + type = settingsFormat.type; + description = '' + Configuration for discordo. + See https://github.com/ayn2op/discordo?tab=readme-ov-file#configuration + for available options and default values. + ''; + default = { }; + }; + + tokenCommand = lib.mkOption { + type = with lib.types; nullOr str; + description = '' + If not null, wraps discordo with -token set to the output of tokenCommand. + Useful if you want token authentication instead of email & password. + + Note that since the wrapper is made using writeShellApplication, this command will + will be checked by ShellCheck. + ''; + default = null; + defaultText = '' + # password-store method + "''${lib.getExe pass} discordo-token" + + # sops method + cat /run/secrets/discordo-token + ''; + }; + }; + config = lib.mkIf config.programs.discordo.enable { + home.packages = with config.programs.discordo; [ + ( + if tokenCommand == null then package + else + pkgs.writeShellApplication { + name = "discordo"; + runtimeInputs = [ package ]; + text = '' + discordo -token "$(${tokenCommand})" "$@" + ''; + } + ) + ]; + + xdg.configFile."discordo/config.toml".source = settingsFormat.generate + "discordo-config.toml" + config.programs.discordo.settings; + }; +} diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 00000000..29720eaf --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,42 @@ +{ buildGo122Module +, lib +, makeWrapper +, xsel +, wl-clipboard +, guiSupport ? true +, xorgClipboardSupport ? guiSupport +, waylandClipboardSupport ? guiSupport +}: +let + anyClipboardSupport = xorgClipboardSupport || waylandClipboardSupport; +in +buildGo122Module { + pname = "discordo"; + version = "unstable-2024-04-28"; + + src = ./..; + vendorHash = "sha256-hSrGN3NHPpp5601l4KcmNHVYOGWfLjFeWWr9g11nM3I="; + # doCheck = false; + + nativeBuildInputs = lib.optional anyClipboardSupport makeWrapper; + + postInstall = + let + clipboardPkgs = + lib.optional xorgClipboardSupport xsel + ++ lib.optional waylandClipboardSupport wl-clipboard; + in + lib.optionalString anyClipboardSupport '' + wrapProgram $out/bin/discordo \ + --prefix PATH : ${lib.makeBinPath clipboardPkgs} + ''; + + meta = { + description = "A lightweight, secure, and feature-rich Discord terminal client"; + homepage = "https://github.com/ayn2op/discordo"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.arian-d ]; + mainProgram = "discordo"; + }; +} +