package: { config, lib, pkgs, ... }: { options.services.lego-monitoring = { enable = lib.mkEnableOption "lego-monitoring service."; nonSecretConfigOption = lib.mkOption { type = lib.types.str; default = "defaultValue"; description = "An example non-secret config option."; }; configOptionSecretPath = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; description = "Path to an example secret config option."; }; }; config = let cfg = config.services.lego-monitoring; json = pkgs.formats.json {}; serviceConfigFile = json.generate "config.json" { non_secret_config_option = cfg.nonSecretConfigOption; config_option_secret_path = cfg.configOptionSecretPath; }; in lib.mkIf cfg.enable { systemd.services.lego-monitoring = { name = "lego-monitoring.service"; description = "Lego-monitoring service"; script = "${package}/bin/service -c ${serviceConfigFile}"; wantedBy = [ "multi-user.target" ]; }; }; }