From 4cff6cd191f14d3409fbeffbdf74116c7129f257 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Fri, 27 Dec 2024 18:36:37 +0100 Subject: [PATCH 1/2] nixos/homer: init --- .../manual/release-notes/rl-2505.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/web-apps/homer.nix | 184 ++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 nixos/modules/services/web-apps/homer.nix diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 5e5713e8fd78..caabcdaeef39 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -63,6 +63,8 @@ - [Kimai](https://www.kimai.org/), a web-based multi-user time-tracking application. Available as [services.kimai](options.html#opt-services.kimai). +- [Homer](https://homer-demo.netlify.app/), a very simple static homepage for your server. Available as [services.homer](options.html#opt-services.homer). + - [Omnom](https://github.com/asciimoo/omnom), a webpage bookmarking and snapshotting service. Available as [services.omnom](options.html#opt-services.omnom.enable). - [Yggdrasil-Jumper](https://github.com/one-d-wide/yggdrasil-jumper) is an independent project that aims to transparently reduce latency of a connection over Yggdrasil network, utilizing NAT traversal to automatically bypass intermediary nodes. diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index dd5b09d91610..f54772e0e3a9 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1497,6 +1497,7 @@ ./services/web-apps/hedgedoc.nix ./services/web-apps/hledger-web.nix ./services/web-apps/homebox.nix + ./services/web-apps/homer.nix ./services/web-apps/honk.nix ./services/web-apps/icingaweb2/icingaweb2.nix ./services/web-apps/icingaweb2/module-monitoring.nix diff --git a/nixos/modules/services/web-apps/homer.nix b/nixos/modules/services/web-apps/homer.nix new file mode 100644 index 000000000000..28936bf57be0 --- /dev/null +++ b/nixos/modules/services/web-apps/homer.nix @@ -0,0 +1,184 @@ +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.services.homer; + settingsFormat = pkgs.formats.yaml { }; + configFile = settingsFormat.generate "homer-config.yml" cfg.settings; +in +{ + options.services.homer = { + enable = lib.mkEnableOption '' + A dead simple static HOMepage for your servER to keep your services on hand, from a simple yaml configuration file. + ''; + + virtualHost = { + nginx.enable = lib.mkEnableOption "a virtualhost to serve homer through nginx"; + caddy.enable = lib.mkEnableOption "a virtualhost to serve homer through caddy"; + + domain = lib.mkOption { + description = '' + Domain to use for the virtual host. + + This can be used to change nginx options like + ```nix + services.nginx.virtualHosts."$\{config.services.homer.virtualHost.domain}".listen = [ ... ] + ``` + or + ```nix + services.nginx.virtualHosts."example.com".listen = [ ... ] + ``` + ''; + type = lib.types.str; + }; + }; + + package = lib.mkPackageOption pkgs "homer" { }; + + settings = lib.mkOption { + default = { }; + description = '' + Settings serialized into `config.yml` before build. + If left empty, the default configuration shipped with the package will be used instead. + For more information, see the [official documentation](https://github.com/bastienwirtz/homer/blob/main/docs/configuration.md). + + 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). + + To add files such as icons or backgrounds, you can reference them in line such as + ```nix + icon = "$\{./icon.png}"; + ``` + This will add the file to the nix store upon build, referencing it by file path as expected by Homer. + ''; + example = '' + { + title = "App dashboard"; + subtitle = "Homer"; + logo = "assets/logo.png"; + header = true; + footer = ${"''"} +

Created with ❤️ with + bulma, + vuejs & + font awesome // + Fork me on +

+ ${"''"}; + columns = "3"; + connectivityCheck = true; + + proxy = { + useCredentials = false; + headers = { + Test = "Example"; + Test1 = "Example1"; + }; + }; + + defaults = { + layout = "columns"; + colorTheme = "auto"; + }; + + theme = "default"; + + message = { + style = "is-warning"; + title = "Optional message!"; + icon = "fa fa-exclamation-triangle"; + content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."; + }; + + links = [ + { + name = "Link 1"; + icon = "fab fa-github"; + url = "https://github.com/bastienwirtz/homer"; + target = "_blank"; + } + { + name = "link 2"; + icon = "fas fa-book"; + url = "https://github.com/bastienwirtz/homer"; + } + ]; + + services = [ + { + name = "Application"; + icon = "fas fa-code-branch"; + items = [ + { + name = "Awesome app"; + logo = "assets/tools/sample.png"; + subtitle = "Bookmark example"; + tag = "app"; + keywords = "self hosted reddit"; + url = "https://www.reddit.com/r/selfhosted/"; + target = "_blank"; + } + { + name = "Another one"; + logo = "assets/tools/sample2.png"; + subtitle = "Another application"; + tag = "app"; + tagstyle = "is-success"; + url = "#"; + } + ]; + } + { + name = "Other group"; + icon = "fas fa-heartbeat"; + items = [ + { + name = "Pi-hole"; + logo = "assets/tools/sample.png"; + tag = "other"; + url = "http://192.168.0.151/admin"; + type = "PiHole"; + target = "_blank"; + } + ]; + } + ]; + } + + ''; + inherit (pkgs.formats.yaml { }) type; + }; + }; + + config = lib.mkIf cfg.enable { + services.nginx = lib.mkIf cfg.virtualHost.nginx.enable { + enable = true; + virtualHosts."${cfg.virtualHost.domain}" = { + locations."/" = { + root = cfg.package; + tryFiles = "$uri /index.html"; + }; + locations."= /assets/config.yml" = { + alias = configFile; + }; + }; + }; + services.caddy = lib.mkIf cfg.virtualHost.caddy.enable { + enable = true; + virtualHosts."${cfg.virtualHost.domain}".extraConfig = '' + root * ${cfg.package} + file_server + handle_path /assets/config.yml { + root * ${configFile} + file_server + } + ''; + }; + }; + + meta.maintainers = [ + lib.maintainers.stunkymonkey + ]; +} From e1b59f78a99cebc1f3860040239da46dc59e226b Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Fri, 27 Dec 2024 18:36:59 +0100 Subject: [PATCH 2/2] nixos/homer: add tests --- nixos/tests/all-tests.nix | 1 + nixos/tests/homer/caddy.nix | 30 ++++++++++++++++++++++++++++++ nixos/tests/homer/default.nix | 6 ++++++ nixos/tests/homer/nginx.nix | 30 ++++++++++++++++++++++++++++++ pkgs/by-name/ho/homer/package.nix | 8 +++++++- 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/homer/caddy.nix create mode 100644 nixos/tests/homer/default.nix create mode 100644 nixos/tests/homer/nginx.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 384371033c72..e82c99f56b51 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -436,6 +436,7 @@ in { hedgedoc = handleTest ./hedgedoc.nix {}; herbstluftwm = handleTest ./herbstluftwm.nix {}; homebox = handleTest ./homebox.nix {}; + homer = handleTest ./homer {}; homepage-dashboard = handleTest ./homepage-dashboard.nix {}; honk = runTest ./honk.nix; installed-tests = pkgs.recurseIntoAttrs (handleTest ./installed-tests {}); diff --git a/nixos/tests/homer/caddy.nix b/nixos/tests/homer/caddy.nix new file mode 100644 index 000000000000..18a37cbc20ca --- /dev/null +++ b/nixos/tests/homer/caddy.nix @@ -0,0 +1,30 @@ +import ../make-test-python.nix ( + { lib, ... }: + + { + name = "homer-caddy"; + meta.maintainers = with lib.maintainers; [ stunkymonkey ]; + + nodes.machine = + { pkgs, ... }: + { + services.homer = { + enable = true; + virtualHost = { + caddy.enable = true; + domain = "localhost:80"; + }; + settings = { + title = "testing"; + }; + }; + }; + + testScript = '' + machine.wait_for_unit("caddy.service") + machine.wait_for_open_port(80) + machine.succeed("curl --fail --show-error --silent http://localhost:80/ | grep 'Homer'") + machine.succeed("curl --fail --show-error --silent http://localhost:80/assets/config.yml | grep 'title: testing'") + ''; + } +) diff --git a/nixos/tests/homer/default.nix b/nixos/tests/homer/default.nix new file mode 100644 index 000000000000..fee30e520c7f --- /dev/null +++ b/nixos/tests/homer/default.nix @@ -0,0 +1,6 @@ +{ system, pkgs, ... }: + +{ + caddy = import ./caddy.nix { inherit system pkgs; }; + nginx = import ./nginx.nix { inherit system pkgs; }; +} diff --git a/nixos/tests/homer/nginx.nix b/nixos/tests/homer/nginx.nix new file mode 100644 index 000000000000..39dd0c2c52ac --- /dev/null +++ b/nixos/tests/homer/nginx.nix @@ -0,0 +1,30 @@ +import ../make-test-python.nix ( + { lib, ... }: + + { + name = "homer-nginx"; + meta.maintainers = with lib.maintainers; [ stunkymonkey ]; + + nodes.machine = + { pkgs, ... }: + { + services.homer = { + enable = true; + virtualHost = { + nginx.enable = true; + domain = "localhost"; + }; + settings = { + title = "testing"; + }; + }; + }; + + testScript = '' + machine.wait_for_unit("nginx.service") + machine.wait_for_open_port(80) + machine.succeed("curl --fail --show-error --silent http://localhost:80/ | grep 'Homer'") + machine.succeed("curl --fail --show-error --silent http://localhost:80/assets/config.yml | grep 'title: testing'") + ''; + } +) diff --git a/pkgs/by-name/ho/homer/package.nix b/pkgs/by-name/ho/homer/package.nix index 50fe5bf1fc59..7d104aa46ff0 100644 --- a/pkgs/by-name/ho/homer/package.nix +++ b/pkgs/by-name/ho/homer/package.nix @@ -6,6 +6,7 @@ nodejs, dart-sass, nix-update-script, + nixosTests, }: stdenvNoCC.mkDerivation rec { pname = "homer"; @@ -54,7 +55,12 @@ stdenvNoCC.mkDerivation rec { runHook postInstall ''; - passthru.updateScript = nix-update-script { }; + passthru = { + updateScript = nix-update-script { }; + tests = { + inherit (nixosTests.homer) caddy nginx; + }; + }; meta = with lib; { description = "A very simple static homepage for your server.";