|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + ... |
| 6 | +}: |
| 7 | + |
| 8 | +let |
| 9 | + cfg = config.services.lubelogger; |
| 10 | +in |
| 11 | +{ |
| 12 | + meta.maintainers = with lib.maintainers; [ |
| 13 | + bct |
| 14 | + lyndeno |
| 15 | + ]; |
| 16 | + |
| 17 | + options = { |
| 18 | + services.lubelogger = { |
| 19 | + enable = lib.mkEnableOption "LubeLogger, a self-hosted, open-source, web-based vehicle maintenance and fuel milage tracker"; |
| 20 | + |
| 21 | + package = lib.mkPackageOption pkgs "lubelogger" { }; |
| 22 | + |
| 23 | + dataDir = lib.mkOption { |
| 24 | + description = "Path to LubeLogger config and metadata inside of `/var/lib/`."; |
| 25 | + default = "lubelogger"; |
| 26 | + type = lib.types.str; |
| 27 | + }; |
| 28 | + |
| 29 | + port = lib.mkOption { |
| 30 | + description = "The TCP port LubeLogger will listen on."; |
| 31 | + default = 5000; |
| 32 | + type = lib.types.port; |
| 33 | + }; |
| 34 | + |
| 35 | + user = lib.mkOption { |
| 36 | + description = "User account under which LubeLogger runs."; |
| 37 | + default = "lubelogger"; |
| 38 | + type = lib.types.str; |
| 39 | + }; |
| 40 | + |
| 41 | + group = lib.mkOption { |
| 42 | + description = "Group under which LubeLogger runs."; |
| 43 | + default = "lubelogger"; |
| 44 | + type = lib.types.str; |
| 45 | + }; |
| 46 | + |
| 47 | + openFirewall = lib.mkOption { |
| 48 | + description = "Open ports in the firewall for the LubeLogger web interface."; |
| 49 | + default = false; |
| 50 | + type = lib.types.bool; |
| 51 | + }; |
| 52 | + |
| 53 | + settings = lib.mkOption { |
| 54 | + type = with lib.types; attrsOf str; |
| 55 | + default = { }; |
| 56 | + example = { |
| 57 | + LUBELOGGER_ALLOWED_FILE_EXTENSIONS = ""; |
| 58 | + LUBELOGGER_LOGO_URL = ""; |
| 59 | + }; |
| 60 | + description = '' |
| 61 | + Additional configuration for LubeLogger, see <https://docs.lubelogger.com/Environment%20Variables> for supported values. |
| 62 | + ''; |
| 63 | + }; |
| 64 | + |
| 65 | + environmentFile = lib.mkOption { |
| 66 | + type = lib.types.nullOr lib.types.path; |
| 67 | + default = null; |
| 68 | + example = "/run/secrets/lubelogger"; |
| 69 | + description = '' |
| 70 | + Path to a file containing extra LubeLogger config options in the systemd `EnvironmentFile` format. |
| 71 | + Refer to the [documentation] for supported options. |
| 72 | +
|
| 73 | + [documentation]: https://docs.lubelogger.com/Advanced/Environment%20Variables |
| 74 | +
|
| 75 | + This can be used to pass secrets to LubeLogger without putting them in the Nix store. |
| 76 | +
|
| 77 | + For example, to set an SMTP password, point `environmentFile` at a file containing: |
| 78 | + ``` |
| 79 | + MailConfig__Password=<pass> |
| 80 | + ``` |
| 81 | + ''; |
| 82 | + }; |
| 83 | + }; |
| 84 | + }; |
| 85 | + |
| 86 | + config = lib.mkIf cfg.enable { |
| 87 | + systemd.services.lubelogger = { |
| 88 | + description = "LubeLogger"; |
| 89 | + |
| 90 | + after = [ "network.target" ]; |
| 91 | + wantedBy = [ "multi-user.target" ]; |
| 92 | + |
| 93 | + environment = { |
| 94 | + Kestrel__Endpoints__Http__Url = "http://localhost:${toString cfg.port}"; |
| 95 | + } |
| 96 | + // cfg.settings; |
| 97 | + |
| 98 | + serviceConfig = { |
| 99 | + Type = "simple"; |
| 100 | + User = cfg.user; |
| 101 | + Group = cfg.group; |
| 102 | + StateDirectory = cfg.dataDir; |
| 103 | + WorkingDirectory = "/var/lib/${cfg.dataDir}"; |
| 104 | + ExecStart = lib.getExe cfg.package; |
| 105 | + EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; |
| 106 | + Restart = "on-failure"; |
| 107 | + |
| 108 | + CapabilityBoundingSet = [ "" ]; |
| 109 | + DeviceAllow = [ "" ]; |
| 110 | + PrivateDevices = true; |
| 111 | + PrivateTmp = true; |
| 112 | + ProtectHome = true; |
| 113 | + RestrictAddressFamilies = [ |
| 114 | + "AF_UNIX" |
| 115 | + "AF_INET" |
| 116 | + "AF_INET6" |
| 117 | + ]; |
| 118 | + RestrictNamespaces = true; |
| 119 | + }; |
| 120 | + }; |
| 121 | + |
| 122 | + users.users = lib.mkIf (cfg.user == "lubelogger") { |
| 123 | + lubelogger = { |
| 124 | + isSystemUser = true; |
| 125 | + group = cfg.group; |
| 126 | + home = "/var/lib/${cfg.dataDir}"; |
| 127 | + }; |
| 128 | + }; |
| 129 | + |
| 130 | + users.groups = lib.mkIf (cfg.group == "lubelogger") { lubelogger = { }; }; |
| 131 | + |
| 132 | + networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; }; |
| 133 | + }; |
| 134 | +} |
0 commit comments