1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.homer;
9 settingsFormat = pkgs.formats.yaml { };
10 configFile = settingsFormat.generate "homer-config.yml" cfg.settings;
11in
12{
13 options.services.homer = {
14 enable = lib.mkEnableOption ''
15 A dead simple static HOMepage for your servER to keep your services on hand, from a simple yaml configuration file.
16 '';
17
18 virtualHost = {
19 nginx.enable = lib.mkEnableOption "a virtualhost to serve homer through nginx";
20 caddy.enable = lib.mkEnableOption "a virtualhost to serve homer through caddy";
21
22 domain = lib.mkOption {
23 description = ''
24 Domain to use for the virtual host.
25
26 This can be used to change nginx options like
27 ```nix
28 services.nginx.virtualHosts."$\{config.services.homer.virtualHost.domain}".listen = [ ... ]
29 ```
30 or
31 ```nix
32 services.nginx.virtualHosts."example.com".listen = [ ... ]
33 ```
34 '';
35 type = lib.types.str;
36 };
37 };
38
39 package = lib.mkPackageOption pkgs "homer" { };
40
41 settings = lib.mkOption {
42 default = { };
43 description = ''
44 Settings serialized into `config.yml` before build.
45 If left empty, the default configuration shipped with the package will be used instead.
46 For more information, see the [official documentation](https://github.com/bastienwirtz/homer/blob/main/docs/configuration.md).
47
48 Note that the full configuration will be written to the nix store as world readable, which may include secrets such as [api-keys](https://github.com/bastienwirtz/homer/blob/main/docs/customservices.md).
49
50 To add files such as icons or backgrounds, you can reference them in line such as
51 ```nix
52 icon = "$\{./icon.png}";
53 ```
54 This will add the file to the nix store upon build, referencing it by file path as expected by Homer.
55 '';
56 example = ''
57 {
58 title = "App dashboard";
59 subtitle = "Homer";
60 logo = "assets/logo.png";
61 header = true;
62 footer = ${"''"}
63 <p>Created with <span class="has-text-danger">❤️</span> with
64 <a href="https://bulma.io/">bulma</a>,
65 <a href="https://vuejs.org/">vuejs</a> &
66 <a href="https://fontawesome.com/">font awesome</a> //
67 Fork me on <a href="https://github.com/bastienwirtz/homer">
68 <i class="fab fa-github-alt"></i></a></p>
69 ${"''"};
70 columns = "3";
71 connectivityCheck = true;
72
73 proxy = {
74 useCredentials = false;
75 headers = {
76 Test = "Example";
77 Test1 = "Example1";
78 };
79 };
80
81 defaults = {
82 layout = "columns";
83 colorTheme = "auto";
84 };
85
86 theme = "default";
87
88 message = {
89 style = "is-warning";
90 title = "Optional message!";
91 icon = "fa fa-exclamation-triangle";
92 content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
93 };
94
95 links = [
96 {
97 name = "Link 1";
98 icon = "fab fa-github";
99 url = "https://github.com/bastienwirtz/homer";
100 target = "_blank";
101 }
102 {
103 name = "link 2";
104 icon = "fas fa-book";
105 url = "https://github.com/bastienwirtz/homer";
106 }
107 ];
108
109 services = [
110 {
111 name = "Application";
112 icon = "fas fa-code-branch";
113 items = [
114 {
115 name = "Awesome app";
116 logo = "assets/tools/sample.png";
117 subtitle = "Bookmark example";
118 tag = "app";
119 keywords = "self hosted reddit";
120 url = "https://www.reddit.com/r/selfhosted/";
121 target = "_blank";
122 }
123 {
124 name = "Another one";
125 logo = "assets/tools/sample2.png";
126 subtitle = "Another application";
127 tag = "app";
128 tagstyle = "is-success";
129 url = "#";
130 }
131 ];
132 }
133 {
134 name = "Other group";
135 icon = "fas fa-heartbeat";
136 items = [
137 {
138 name = "Pi-hole";
139 logo = "assets/tools/sample.png";
140 tag = "other";
141 url = "http://192.168.0.151/admin";
142 type = "PiHole";
143 target = "_blank";
144 }
145 ];
146 }
147 ];
148 }
149
150 '';
151 inherit (pkgs.formats.yaml { }) type;
152 };
153 };
154
155 config = lib.mkIf cfg.enable {
156 services.nginx = lib.mkIf cfg.virtualHost.nginx.enable {
157 enable = true;
158 virtualHosts."${cfg.virtualHost.domain}" = {
159 locations."/" = {
160 root = cfg.package;
161 tryFiles = "$uri /index.html";
162 };
163 locations."= /assets/config.yml" = {
164 alias = configFile;
165 };
166 };
167 };
168 services.caddy = lib.mkIf cfg.virtualHost.caddy.enable {
169 enable = true;
170 virtualHosts."${cfg.virtualHost.domain}".extraConfig = ''
171 root * ${cfg.package}
172 file_server
173 handle_path /assets/config.yml {
174 root * ${configFile}
175 file_server
176 }
177 '';
178 };
179 };
180
181 meta.maintainers = [
182 lib.maintainers.stunkymonkey
183 ];
184}