diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 2dadfdf5..d549169a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -204,6 +204,9 @@ Makefile @thiagokokada /modules/programs/newsboat.nix @sumnerevans /tests/modules/programs/newsboat @sumnerevans +/modules/programs/nheko.nix @gvolpe +/tests/modules/programs/nheko @gvolpe + /modules/programs/nix-index.nix @ambroisie /tests/modules/programs/nix-index @ambroisie diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 63855183..882cd8fe 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -675,6 +675,13 @@ in A new module is available: 'editorconfig'. ''; } + + { + time = "2022-09-08T15:41:46+00:00"; + message = '' + A new module is available: 'programs.nheko'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 60d979ea..61f5436b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -124,6 +124,7 @@ let ./programs/neomutt.nix ./programs/neovim.nix ./programs/newsboat.nix + ./programs/nheko.nix ./programs/nix-index.nix ./programs/nnn.nix ./programs/noti.nix diff --git a/modules/programs/nheko.nix b/modules/programs/nheko.nix new file mode 100644 index 00000000..53f67011 --- /dev/null +++ b/modules/programs/nheko.nix @@ -0,0 +1,85 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.nheko; + + iniFmt = pkgs.formats.ini { }; + + configDir = if pkgs.stdenv.hostPlatform.isDarwin then + "Library/Application Support" + else + config.xdg.configHome; + + camelCaseToSnakeCase = + replaceStrings upperChars (map (s: "_${s}") lowerChars); + + inherit (generators) mkKeyValueDefault toINI; + +in { + meta.maintainers = [ maintainers.gvolpe ]; + + options.programs.nheko = { + enable = mkEnableOption "Qt desktop client for Matrix"; + + package = mkPackageOption pkgs "nheko" { }; + + settings = mkOption { + type = iniFmt.type; + default = { }; + example = literalExpression '' + { + general.disableCertificateValidation = false; + auth = { + accessToken = "SECRET"; + deviceId = "MY_DEVICE"; + homeServer = "https://matrix-client.matrix.org:443"; + userId = "@@user:matrix.org"; + }; + settings.scaleFactor = 1.0; + sidebar.width = 416; + user = { + alertOnNotification = true; + animateImagesOnHover = false; + "sidebar\\roomListWidth" = 308; + }; + } + ''; + description = '' + Attribute set of Nheko preferences (converted to an INI file). + + + + For now, it is recommended to run nheko and sign-in before filling in + the configuration settings in this module, as nheko writes the access + token to $XDG_CONFIG_HOME/nheko/nheko.conf the + first time we sign in, and we need that data into these settings for the + correct functionality of the application. + + + + This a temporary inconvenience, however, as nheko has plans to move the + authentication stuff into the local database they currently use. Once + this happens, this will no longer be an issue. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file."${configDir}/nheko/nheko.conf" = mkIf (cfg.settings != { }) { + text = '' + ; Generated by Home Manager. + + ${toINI { + mkKeyValue = k: v: + mkKeyValueDefault { } "=" (camelCaseToSnakeCase k) v; + } cfg.settings} + ''; + }; + }; +} + diff --git a/tests/default.nix b/tests/default.nix index 2a78e110..362adebc 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -94,6 +94,7 @@ import nmt { ./modules/programs/ne ./modules/programs/neomutt ./modules/programs/newsboat + ./modules/programs/nheko ./modules/programs/nix-index ./modules/programs/nnn ./modules/programs/nushell diff --git a/tests/modules/programs/nheko/default.nix b/tests/modules/programs/nheko/default.nix new file mode 100644 index 00000000..573182ed --- /dev/null +++ b/tests/modules/programs/nheko/default.nix @@ -0,0 +1,4 @@ +{ + nheko-empty-settings = ./nheko-empty-settings.nix; + nheko-example-settings = ./nheko-example-settings.nix; +} diff --git a/tests/modules/programs/nheko/nheko-empty-settings.nix b/tests/modules/programs/nheko/nheko-empty-settings.nix new file mode 100644 index 00000000..65538d9e --- /dev/null +++ b/tests/modules/programs/nheko/nheko-empty-settings.nix @@ -0,0 +1,16 @@ +{ pkgs, ... }: + +let + configDir = if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support" + else + "home-files/.config"; +in { + programs.nheko.enable = true; + + test.stubs.nheko = { }; + + nmt.script = '' + assertPathNotExists "${configDir}/nheko/nheko.conf" + ''; +} diff --git a/tests/modules/programs/nheko/nheko-example-settings-expected-config.ini b/tests/modules/programs/nheko/nheko-example-settings-expected-config.ini new file mode 100644 index 00000000..d3a1c5e2 --- /dev/null +++ b/tests/modules/programs/nheko/nheko-example-settings-expected-config.ini @@ -0,0 +1,64 @@ +; Generated by Home Manager. + +[auth] +access_token=MY_ACCESS_TOKEN +device_id=MY_DEVICE +home_server=https://matrix-client.matrix.org:443 +user_id=@@user:matrix.org + +[general] +disable_certificate_validation=false + +[settings] +scale_factor=0.700000 + +[sidebar] +width=416 + +[user] +alert_on_notification=true +animate_images_on_hover=false +automatically_share_keys_with_trusted_users=false +avatar_circles=true +bubbles_enabled=false +decrypt_sidebar=true +desktop_notifications=true +emoji_font_family=Noto Emoji +expose_dbus_api=false +font_family=JetBrainsMonoMedium Nerd Font Mono +font_size=9 +group_view=true +markdown_enabled=true +minor_events=false +mobile_mode=false +muted_tags=global +online_key_backup=false +only_share_keys_with_verified_users=false +open_image_external=false +open_video_external=false +presence=AutomaticPresence +privacy_screen=false +privacy_screen_timeout=0 +read_receipts=true +ringtone=Mute +share_keys_with_trusted_users=true +sidebar\community_list_width=40 +sidebar\room_list_width=308 +small_avatars_enabled=false +sort_by_unread=true +space_notifications=true +theme=dark +timeline\buttons=true +timeline\enlarge_emoji_only_msg=true +timeline\max_width=0 +timeline\message_hover_highlight=false +typing_notifications=true +use_identicon=true +use_stun_server=false +window\start_in_tray=false +window\tray=true + +[window] +height=482 +width=950 + diff --git a/tests/modules/programs/nheko/nheko-example-settings.nix b/tests/modules/programs/nheko/nheko-example-settings.nix new file mode 100644 index 00000000..26599c5a --- /dev/null +++ b/tests/modules/programs/nheko/nheko-example-settings.nix @@ -0,0 +1,84 @@ +{ pkgs, ... }: + +let + configDir = if pkgs.stdenv.isDarwin then + "home-files/Library/Application Support" + else + "home-files/.config"; +in { + programs.nheko = { + enable = true; + + settings = { + general = { disableCertificateValidation = false; }; + + auth = { + accessToken = "MY_ACCESS_TOKEN"; + deviceId = "MY_DEVICE"; + homeServer = "https://matrix-client.matrix.org:443"; + userId = "@@user:matrix.org"; + }; + + sidebar = { width = 416; }; + + settings = { scaleFactor = 0.7; }; + + user = { + alertOnNotification = true; + animateImagesOnHover = false; + automaticallyShareKeysWithTrustedUsers = false; + avatarCircles = true; + bubblesEnabled = false; + decryptSidebar = true; + desktopNotifications = true; + emojiFontFamily = "Noto Emoji"; + exposeDbusApi = false; + fontFamily = "JetBrainsMonoMedium Nerd Font Mono"; + fontSize = 9; + groupView = true; + markdownEnabled = true; + minorEvents = false; + mobileMode = false; + mutedTags = "global"; + onlineKeyBackup = false; + onlyShareKeysWithVerifiedUsers = false; + openImageExternal = false; + openVideoExternal = false; + presence = "AutomaticPresence"; + privacyScreen = false; + privacyScreenTimeout = 0; + readReceipts = true; + ringtone = "Mute"; + shareKeysWithTrustedUsers = true; + smallAvatarsEnabled = false; + "sidebar\\communityListWidth" = 40; + "sidebar\\roomListWidth" = 308; + sortByUnread = true; + spaceNotifications = true; + theme = "dark"; + "timeline\\buttons" = true; + "timeline\\enlargeEmojiOnlyMsg" = true; + "timeline\\maxWidth" = 0; + "timeline\\messageHoverHighlight" = false; + typingNotifications = true; + useIdenticon = true; + useStunServer = false; + "window\\startInTray" = false; + "window\\tray" = true; + }; + + window = { + height = 482; + width = 950; + }; + }; + }; + + test.stubs.nheko = { }; + + nmt.script = '' + assertFileContent \ + "${configDir}/nheko/nheko.conf" \ + ${./nheko-example-settings-expected-config.ini} + ''; +}