Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix flake #322

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
discordo*

# Visual Studio Code
.vscode/
.vscode/

result
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}


62 changes: 62 additions & 0 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
42 changes: 42 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}