all repos — nixfiles @ 8b80c0eb8a71774d72e86d3ebe2b638fb0c7c2eb

System and user configuration, managed by nix and home-manager

user/settings/theme.nix (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
{
  pkgs,
  lib,
  ...
}:
let
  inherit (pkgs.stdenv) isDarwin;
  # (hard constants)
  ppi = 72;
  dpi = 96;
  mustFloat = x: x * 1.0;
  px-pt = px: (mustFloat px) * ppi / dpi;
in
{
  # hard to find the right documentation page
  # https://nix-community.github.io/stylix/options/platforms/home_manager.html
  stylix = {
    enable = true;

    # actually refers to tinted-themes (https://github.com/tinted-theming/schemes)
    # but only in the base16 variants (TODO update nixpkgs)
    base16Scheme = "${pkgs.base16-schemes}/share/themes/atelier-dune-light.yaml";

    fonts = {
      sansSerif = lib.mkIf isDarwin {
        name = "SF Pro";
      };
      monospace = {
        name = "Berkeley Mono";
      };

      sizes = {
        applications = px-pt 15;
        # desktop
        # popups
        # terminal
      };
    };

    targets = {
      fish.enable = false;
      fzf.colors.enable = false;
      zed = {
        inputs.enable = false;
        fonts.override = {
          sansSerif.name = ".ZedSans";
        };
      };
      nixvim = {
        enable = true;
        plugin = "mini.base16";
      };
      emacs = {
        colors.enable = false;
        fonts.override.sizes.terminal = 15;
      };
    };
  };

  home.packages = with pkgs; [
    theme-sh
  ];

  programs.fzf = {
    defaultOptions = [
      "--color=16"
    ];
    colors = {
      fg = "-1";
      "fg+" = "-1";
      bg = "-1";
      "bg+" = "-1";
      gutter = "8";
      pointer = "-1";
      header = "1";
      border = "6";
      hl = "3";
      "hl+" = "11";
      info = "2";
      prompt = "14";
      marker = "21";
      spinner = "21";
      scrollbar = "dim";
    };
  };

  home.sessionVariables = {
    CLICOLOR = "1";
    LSCOLORS = "gxfxcxdxDxegedabagacad"; # for macOS's ls
    THEME_LIGHT = "atelier-dune-light";
    THEME_DARK = "atelier-dune";
  };

  programs.fish = {
    shellAliases.theme = "theme.sh";

    loginShellInit = ''
      if test -e $XDG_CONFIG_HOME/.theme_history
          theme.sh (theme.sh -l | tail -n1)
      else
          theme.sh $THEME_LIGHT
      end
    '';
    interactiveShellInit = ''
      bind ctrl-o toggle-light-dark
    '';
  };

  programs.zed-editor = {
    extensions = [ "flexoki-themes" ];
    userSettings.theme = {
      light = "Flexoki Light";
      dark = "Flexoki Dark";
    };
  };

  programs.emacs =
    let
      pname = "flexoki-themes";
      light-mode-theme = "flexoki-themes-light";
      dark-mode-theme = "flexoki-themes-dark";
      config = ''
        ;; (flexoki-themes-use-bold-keywords t)
        ;; (flexoki-themes-use-bold-builtins t)
        ;; (flexoki-themes-use-italic-comments t)
      '';
    in
    {
      extraPackages = epkgs: [
        epkgs.${pname}
      ];

      extraConfig = ''
        (use-package ${pname}
          :if (or (daemonp)
                  window-system)
          :config (progn ${config}))

        (let ((light-mode-theme '${light-mode-theme})
              (dark-mode-theme '${dark-mode-theme}))
          (mapc #'disable-theme custom-enabled-themes)
          (load-theme light-mode-theme :noconfirm :noenable)
          (load-theme dark-mode-theme :noconfirm :noenable)

          (defun my/switch-theme-variant (mode)
            (interactive (list
                          (intern (completing-read "Make it: " '("light" "dark") nil t))))
            (cond
             ((eq mode 'dark)
              (disable-theme light-mode-theme)
              (enable-theme dark-mode-theme))
             ((eq mode 'light)
              (disable-theme dark-mode-theme)
              (enable-theme light-mode-theme)))
            (modify-all-frames-parameters `((ns-appearance ,mode))))

          (defun my/system-appearance ()
            (if (and (eq system-type 'darwin)
                     (string-equal
                      "Dark"
                      (string-trim-right (shell-command-to-string "defaults read -g AppleInterfaceStyle"))))
                'dark
              'light))

          (defun my/match-theme-system-appearance ()
            (interactive)
            (my/switch-theme-variant (my/system-appearance)))

          (my/switch-theme-variant (my/system-appearance))

          (use-package kqueue
            :if (eq window-system 'ns)
            :config (progn
                      (defun my/gp-notify-callback (event)
                        (let* ((filename (elt event 2))
                               (basename (file-name-nondirectory filename)))
                          (when (string-equal basename ".GlobalPreferences.plist")
                            (my/match-theme-system-appearance))))
                      (setq my/kq-watcher-global-preferences
                            (kqueue-add-watch (expand-file-name "~/Library/Preferences/")
                                              '(write)
                                              #'my/gp-notify-callback)))))
      '';
    };
}