fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.2 KiB81 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.nheko;
8
9  iniFmt = pkgs.formats.ini { };
10
11  configDir = if pkgs.stdenv.hostPlatform.isDarwin then
12    "Library/Application Support"
13  else
14    config.xdg.configHome;
15
16  camelCaseToSnakeCase =
17    replaceStrings upperChars (map (s: "_${s}") lowerChars);
18
19  inherit (generators) mkKeyValueDefault toINI;
20
21in {
22  meta.maintainers = [ maintainers.gvolpe ];
23
24  options.programs.nheko = {
25    enable = mkEnableOption "Qt desktop client for Matrix";
26
27    package = mkPackageOption pkgs "nheko" { };
28
29    settings = mkOption {
30      type = iniFmt.type;
31      default = { };
32      example = literalExpression ''
33        {
34          general.disableCertificateValidation = false;
35          auth = {
36            accessToken = "SECRET";
37            deviceId = "MY_DEVICE";
38            homeServer = "https://matrix-client.matrix.org:443";
39            userId = "@@user:matrix.org";
40          };
41          settings.scaleFactor = 1.0;
42          sidebar.width = 416;
43          user = {
44            alertOnNotification = true;
45            animateImagesOnHover = false;
46            "sidebar\\roomListWidth" = 308;
47          };
48        }
49      '';
50      description = ''
51        Attribute set of Nheko preferences (converted to an INI file).
52
53        For now, it is recommended to run nheko and sign-in before filling in
54        the configuration settings in this module, as nheko writes the access
55        token to {file}`$XDG_CONFIG_HOME/nheko/nheko.conf` the
56        first time we sign in, and we need that data into these settings for the
57        correct functionality of the application.
58
59        This a temporary inconvenience, however, as nheko has plans to move the
60        authentication stuff into the local database they currently use. Once
61        this happens, this will no longer be an issue.
62      '';
63    };
64  };
65
66  config = mkIf cfg.enable {
67    home.packages = [ cfg.package ];
68
69    home.file."${configDir}/nheko/nheko.conf" = mkIf (cfg.settings != { }) {
70      text = ''
71        ; Generated by Home Manager.
72
73        ${toINI {
74          mkKeyValue = k: v:
75            mkKeyValueDefault { } "=" (camelCaseToSnakeCase k) v;
76        } cfg.settings}
77      '';
78    };
79  };
80}
81