1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 inherit (lib.types) package str;
9 inherit (lib)
10 mkIf
11 mkOption
12 mkEnableOption
13 mkPackageOption
14 ;
15 cfg = config.services.dashy;
16in
17{
18 options.services.dashy = {
19 enable = mkEnableOption ''
20 Dashy, a highly customizable, easy to use, privacy-respecting dashboard app.
21
22 Note that this builds a static web app as opposed to running a full node server, unlike the default docker image.
23
24 Writing config changes to disk through the UI, triggering a rebuild through the UI and application status checks are
25 unavailable without the node server; Everything else will work fine.
26
27 See the deployment docs for [building from source](https://dashy.to/docs/deployment#build-from-source), [hosting with a CDN](https://dashy.to/docs/deployment#hosting-with-cdn) and [CDN cloud deploy](https://dashy.to/docs/deployment#cdn--cloud-deploy) for more information.
28 '';
29
30 virtualHost = {
31 enableNginx = mkEnableOption "a virtualhost to serve dashy through nginx";
32
33 domain = mkOption {
34 description = ''
35 Domain to use for the virtual host.
36
37 This can be used to change nginx options like
38 ```nix
39 services.nginx.virtualHosts."$\{config.services.dashy.virtualHost.domain}".listen = [ ... ]
40 ```
41 or
42 ```nix
43 services.nginx.virtualHosts."example.com".listen = [ ... ]
44 ```
45 '';
46 type = str;
47 };
48 };
49
50 package = mkPackageOption pkgs "dashy-ui" { };
51
52 finalDrv = mkOption {
53 readOnly = true;
54 default =
55 if cfg.settings != { } then cfg.package.override { inherit (cfg) settings; } else cfg.package;
56 defaultText = ''
57 if cfg.settings != {}
58 then cfg.package.override {inherit (cfg) settings;}
59 else cfg.package;
60 '';
61 type = package;
62 description = ''
63 Final derivation containing the fully built static files
64 '';
65 };
66
67 settings = mkOption {
68 default = { };
69 description = ''
70 Settings serialized into `user-data/conf.yml` before build.
71 If left empty, the default configuration shipped with the package will be used instead.
72
73 Note that the full configuration will be written to the nix store as world readable, which may include secrets such as [password hashes](https://dashy.to/docs/configuring#appconfigauthusers-optional).
74
75 To add files such as icons or backgrounds, you can reference them in line such as
76 ```nix
77 icon = "$\{./icon.png}";
78 ```
79 This will add the file to the nix store upon build, referencing it by file path as expected by Dashy.
80 '';
81 example = ''
82 {
83 appConfig = {
84 cssThemes = [
85 "example-theme-1"
86 "example-theme-2"
87 ];
88 enableFontAwesome = true;
89 fontAwesomeKey = "e9076c7025";
90 theme = "thebe";
91 };
92 pageInfo = {
93 description = "My Awesome Dashboard";
94 navLinks = [
95 {
96 path = "/";
97 title = "Home";
98 }
99 {
100 path = "https://example.com";
101 title = "Example 1";
102 }
103 {
104 path = "https://example.com";
105 title = "Example 2";
106 }
107 ];
108 title = "Dashy";
109 };
110 sections = [
111 {
112 displayData = {
113 collapsed = true;
114 cols = 2;
115 customStyles = "border: 2px dashed red;";
116 itemSize = "large";
117 };
118 items = [
119 {
120 backgroundColor = "#0079ff";
121 color = "#00ffc9";
122 description = "Source code and documentation on GitHub";
123 icon = "fab fa-github";
124 target = "sametab";
125 title = "Source";
126 url = "https://github.com/Lissy93/dashy";
127 }
128 {
129 description = "View currently open issues, or raise a new one";
130 icon = "fas fa-bug";
131 title = "Issues";
132 url = "https://github.com/Lissy93/dashy/issues";
133 }
134 {
135 description = "Live Demo #1";
136 icon = "fas fa-rocket";
137 target = "iframe";
138 title = "Demo 1";
139 url = "https://dashy-demo-1.as93.net";
140 }
141 {
142 description = "Live Demo #2";
143 icon = "favicon";
144 target = "newtab";
145 title = "Demo 2";
146 url = "https://dashy-demo-2.as93.net";
147 }
148 ];
149 name = "Getting Started";
150 }
151 ];
152 }
153 '';
154 inherit (pkgs.formats.json { }) type;
155 };
156 };
157
158 config = mkIf cfg.enable {
159 services.nginx = mkIf cfg.virtualHost.enableNginx {
160 enable = true;
161 virtualHosts."${cfg.virtualHost.domain}" = {
162 locations."/" = {
163 root = cfg.finalDrv;
164 tryFiles = "$uri /index.html ";
165 };
166 };
167 };
168 };
169
170 meta.maintainers = [
171 lib.maintainers.therealgramdalf
172 ];
173}