From d439e559ef6692a0ef37c8f6f3341476ce529bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 20 Jan 2020 12:30:37 +0100 Subject: [PATCH 1/2] maintainers: add marijanp --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index 20596519e011..a70a3b1bf694 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -5630,6 +5630,12 @@ email = "markus@wotringer.de"; name = "Markus Wotringer"; }; + marijanp = { + name = "Marijan Petričević"; + email = "marijan.petricevic94@gmail.com"; + github = "marijanp"; + githubId = 13599169; + }; marius851000 = { email = "mariusdavid@laposte.net"; name = "Marius David"; From f56089ded5e3895d9fbd82bfbdff79b761e42118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marijan=20Petri=C4=8Devi=C4=87?= Date: Mon, 20 Jan 2020 12:34:57 +0100 Subject: [PATCH 2/2] nixos/hledger-web: init module and test --- nixos/modules/module-list.nix | 1 + .../modules/services/web-apps/hledger-web.nix | 77 +++++++++++++++++++ nixos/tests/all-tests.nix | 1 + nixos/tests/hledger-web.nix | 53 +++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 nixos/modules/services/web-apps/hledger-web.nix create mode 100644 nixos/tests/hledger-web.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index c7a8f6b2f7c3..7586ae41bbb0 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -876,6 +876,7 @@ ./services/web-apps/gotify-server.nix ./services/web-apps/grocy.nix ./services/web-apps/hedgedoc.nix + ./services/web-apps/hledger-web.nix ./services/web-apps/icingaweb2/icingaweb2.nix ./services/web-apps/icingaweb2/module-monitoring.nix ./services/web-apps/ihatemoney diff --git a/nixos/modules/services/web-apps/hledger-web.nix b/nixos/modules/services/web-apps/hledger-web.nix new file mode 100644 index 000000000000..43fc4daa177f --- /dev/null +++ b/nixos/modules/services/web-apps/hledger-web.nix @@ -0,0 +1,77 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.services.hledger-web; +in { + options.services.hledger-web = { + + enable = mkEnableOption "hledger-web service"; + + serveApi = mkEnableOption "Serve only the JSON web API, without the web UI."; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = '' + Address to listen on. + ''; + }; + + port = mkOption { + type = types.port; + default = 5000; + example = "80"; + description = '' + Port to listen on. + ''; + }; + + capabilities = mkOption { + type = types.commas; + default = "view"; + description = '' + Enable the view, add, and/or manage capabilities. E.g. view,add + ''; + }; + + journalFile = mkOption { + type = types.path; + example = "/home/hledger/.hledger.journal"; + description = '' + Input journal file. + ''; + }; + + baseUrl = mkOption { + type = with types; nullOr str; + default = null; + example = "https://example.org"; + description = '' + Base URL, when sharing over a network. + ''; + }; + }; + + config = mkIf cfg.enable { + systemd.services.hledger-web = { + description = "hledger-web - web-app for the hledger accounting tool."; + documentation = [ https://hledger.org/hledger-web.html ]; + wantedBy = [ "multi-user.target" ]; + after = [ "networking.target" ]; + serviceConfig = { + ExecStart = '' + ${pkgs.hledger-web}/bin/hledger-web \ + --host=${cfg.host} \ + --port=${toString cfg.port} \ + --file=${cfg.journalFile} \ + "--capabilities=${cfg.capabilities}" \ + ${optionalString (cfg.baseUrl != null) "--base-url=${cfg.baseUrl}"} \ + ${optionalString (cfg.serveApi) "--serve-api"} + ''; + Restart = "always"; + }; + }; + }; + + meta.maintainers = with lib.maintainers; [ marijanp ]; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 05fd5c4822a7..d267ddeb4cf4 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -155,6 +155,7 @@ in # not on other platforms. hibernate = handleTestOn ["x86_64-linux"] ./hibernate.nix {}; hitch = handleTest ./hitch {}; + hledger-web = handleTest ./hledger-web.nix {}; hocker-fetchdocker = handleTest ./hocker-fetchdocker {}; home-assistant = handleTest ./home-assistant.nix {}; hostname = handleTest ./hostname.nix {}; diff --git a/nixos/tests/hledger-web.nix b/nixos/tests/hledger-web.nix new file mode 100644 index 000000000000..378d819437db --- /dev/null +++ b/nixos/tests/hledger-web.nix @@ -0,0 +1,53 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: +let + journal = pkgs.writeText "test.journal" '' + 2010/01/10 Loan + assets:cash 500$ + income:loan -500$ + 2010/01/10 NixOS Foundation donation + expenses:donation 250$ + assets:cash -250$ + ''; +in +rec { + name = "hledger-web"; + meta.maintainers = with lib.maintainers; [ marijanp ]; + + nodes = { + server = { config, pkgs, ... }: rec { + services.hledger-web = { + host = "127.0.0.1"; + port = 5000; + enable = true; + journalFile = journal; + }; + networking.firewall.allowedTCPPorts = [ services.hledger-web.port ]; + }; + apiserver = { config, pkgs, ... }: rec { + services.hledger-web = { + host = "127.0.0.1"; + port = 5000; + enable = true; + serveApi = true; + journalFile = journal; + }; + networking.firewall.allowedTCPPorts = [ services.hledger-web.port ]; + }; + }; + + testScript = '' + start_all() + + server.wait_for_unit("hledger-web.service") + server.wait_for_open_port(5000) + with subtest("Check if web UI is accessible"): + page = server.succeed("curl -L http://127.0.0.1:5000") + assert "test.journal" in page + + apiserver.wait_for_unit("hledger-web.service") + apiserver.wait_for_open_port(5000) + with subtest("Check if the JSON API is served"): + transactions = apiserver.succeed("curl -L http://127.0.0.1:5000/transactions") + assert "NixOS Foundation donation" in transactions + ''; +})