main
  1{den, ...}: {
  2  den.aspects.desktop.noctalia = {
  3    persistHome = {config, ...}: {
  4      directories = [
  5        "${config.xdg.state.directory}/noctalia"
  6      ];
  7    };
  8
  9    hjem = {
 10      host,
 11      user,
 12      pkgs,
 13      lib,
 14      ...
 15    }: let
 16      officialPlugins = pkgs.fetchFromGitHub {
 17        owner = "noctalia-dev";
 18        repo = "official-plugins";
 19        rev = "9aec34181e46789b281263942092ac552f661d1a";
 20        hash = "sha256-0LcRrw6iA30dva7ubY7y3aZpOkqfufGvCtWW1V33cnA=";
 21      };
 22      communityPlugins = pkgs.fetchFromGitHub {
 23        owner = "noctalia-dev";
 24        repo = "community-plugins";
 25        rev = "093661f688847ffd7a47d3fdfa39c9b6f63a3a36";
 26        hash = "sha256-DVlvf1bjUia35aOo7M7LKQxTS+xTkF0OpqzJHK3qjWk=";
 27      };
 28
 29      # Adds "hide when offline" and "auto-select online" to the upstream plugin.
 30      phoneConnect = pkgs.runCommand "phone-connect-patched" {} ''
 31        cp -r --no-preserve=mode ${communityPlugins}/phone-connect $out
 32        ${lib.getExe pkgs.patch} -p1 -d $out < ${./plugins/phone-connect/phone-connect.patch}
 33      '';
 34
 35      plugins =
 36        {
 37          "noctalia/kaomoji".src = "${officialPlugins}/kaomoji";
 38        }
 39        // (lib.optionalAttrs
 40          (host.hasAspect den.aspects.desktop.app.kdeconnect)
 41          {
 42            "icefish/phone-connect" = {
 43              src = "${phoneConnect}";
 44              systemDeps = [pkgs.glib.bin pkgs.sshfs];
 45            };
 46          });
 47
 48      pluginDir = pkgs.linkFarm "noctalia-plugins" (
 49        lib.mapAttrsToList
 50        (id: p: {
 51          name = lib.baseNameOf id;
 52          path = p.src;
 53        })
 54        plugins
 55      );
 56    in {
 57      packages =
 58        [pkgs.noctalia]
 59        ++ lib.concatLists (lib.mapAttrsToList (_: p: p.systemDeps or []) plugins);
 60
 61      xdg.config.files."noctalia/config.toml" = {
 62        generator = value: let
 63          rawConfig = (pkgs.formats.toml {}).generate "noctalia-config.toml" value;
 64        in
 65          pkgs.runCommand "noctalia-config-validated.toml" {} ''
 66            ${lib.getExe pkgs.noctalia} config validate ${rawConfig}
 67            cp ${rawConfig} $out
 68          '';
 69        value = {
 70          battery.warning_threshold = 20;
 71          notification.layer = "overlay";
 72          osd = {
 73            background_opacity = 0.9;
 74            position_vertical = "top_right";
 75          };
 76          desktop_widgets.enabled = false;
 77          shell = {
 78            avatar_path = lib.mkIf (user.identity.avatar != null) user.identity.avatar;
 79            lang = "zh_CN.UTF-8";
 80            panel = {
 81              open_near_click_control_center = true;
 82              transparency_mode = "glass";
 83            };
 84          };
 85          plugins = {
 86            enabled = lib.attrNames plugins;
 87            auto_update = "none";
 88            source = [
 89              {
 90                name = "nix";
 91                kind = "path";
 92                location = "${pluginDir}";
 93              }
 94            ];
 95          };
 96          plugin_settings = {
 97            "icefish/phone-connect" = {
 98              language = "zh-Hans";
 99              auto_select_online = true;
100              hide_when_offline = true;
101              show_device_name = true;
102            };
103          };
104          bar = {
105            order = ["default"];
106            default = {
107              background_opacity = 0.9;
108              margin_edge = 8;
109              margin_ends = 8;
110              radius = 14;
111              start = [
112                "launcher"
113                "phone-connect"
114                "privacy"
115                "media"
116              ];
117              center = ["workspaces"];
118              end = [
119                "tray"
120                "notifications"
121                "clipboard"
122                "network"
123                "bluetooth"
124                "volume"
125                "brightness"
126                "battery"
127                "clock"
128                "control-center"
129              ];
130            };
131          };
132          widget = {
133            battery = {
134              display_mode = "graphic";
135              show_label = false;
136            };
137            brightness.show_label = false;
138            clock = {
139              capsule = true;
140              capsule_opacity = 0.9;
141              capsule_padding = 10.0;
142              format = "{:%Y-%m-%d %H:%M}";
143            };
144            control-center = {
145              capsule = true;
146              capsule_opacity = 0.9;
147              custom_image = "${pkgs.nixos-icons}/share/icons/hicolor/64x64/apps/nix-snowflake.png";
148              shortcuts = [
149                {type = "dark_mode";}
150                {type = "wallpaper";}
151                {type = "caffeine";}
152                {type = "notification";}
153              ];
154            };
155            launcher = {
156              capsule = true;
157              capsule_opacity = 0.9;
158            };
159            media = {
160              capsule = true;
161              capsule_opacity = 0.9;
162              hide_when_no_media = true;
163            };
164            network.show_label = false;
165            privacy = {
166              capsule = true;
167              capsule_opacity = 0.9;
168            };
169            tray = {drawer = true;};
170            volume.show_label = false;
171            workspaces.hide_when_empty = true;
172            phone-connect = {
173              capsule = true;
174              type = "icefish/phone-connect:bar";
175            };
176          };
177        };
178      };
179    };
180  };
181
182  den.aspects.desktop.noctalia.themes = {
183    catppuccin = {
184      hjem = {pkgs, ...}: {
185        xdg.config.files."noctalia/config.toml".value = {
186          theme = {
187            source = "builtin";
188            builtin = "Catppuccin";
189          };
190          wallpaper.default = pkgs.nixos-artwork.wallpapers.catppuccin-mocha;
191        };
192      };
193    };
194  };
195}