From bbda84ca261397086f866ece115c4ec9111d4d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 16 Apr 2024 10:51:59 +0200 Subject: Try to improve the code --- nixos/modules/bcg.nix | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'nixos/modules/bcg.nix') diff --git a/nixos/modules/bcg.nix b/nixos/modules/bcg.nix index 626a67f..3146c15 100644 --- a/nixos/modules/bcg.nix +++ b/nixos/modules/bcg.nix @@ -4,13 +4,10 @@ pkgs, ... }: - -with lib; - -let +with lib; let cfg = config.services.bcg; configFile = (pkgs.formats.yaml {}).generate "bcg.conf.yaml" ( - filterAttrsRecursive (n: v: v != null) { + filterAttrsRecursive (_: v: v != null) { inherit (cfg) device name mqtt; retain_node_messages = cfg.retainNodeMessages; qos_node_messages = cfg.qosNodeMessages; @@ -21,16 +18,15 @@ let automatic_rename_nodes = cfg.automaticRenameNodes; } ); -in -{ +in { options = { services.bcg = { enable = mkEnableOption "BigClown gateway"; - package = mkPackageOption pkgs [ "python3Packages" "bcg" ] { }; + package = mkPackageOption pkgs ["python3Packages" "bcg"] {}; environmentFiles = mkOption { type = types.listOf types.path; default = []; - example = [ "/run/keys/bcg.env" ]; + example = ["/run/keys/bcg.env"]; description = '' File to load as environment file. Environment variables from this file will be interpolated into the config file using envsubst with this @@ -148,21 +144,22 @@ in systemd.services.bcg = let envConfig = cfg.environmentFiles != []; - finalConfig = if envConfig - then "$RUNTIME_DIRECTORY/bcg.config.yaml" - else configFile; + finalConfig = + if envConfig + then "$RUNTIME_DIRECTORY/bcg.config.yaml" + else configFile; in { description = "BigClown Gateway"; - wantedBy = [ "multi-user.target" ]; - wants = [ "network-online.target" ] ++ lib.optional config.services.mosquitto.enable "mosquitto.service"; - after = [ "network-online.target" ]; + wantedBy = ["multi-user.target"]; + wants = ["network-online.target"] ++ lib.optional config.services.mosquitto.enable "mosquitto.service"; + after = ["network-online.target"]; preStart = '' umask 077 ${pkgs.envsubst}/bin/envsubst -i "${configFile}" -o "${finalConfig}" - ''; + ''; serviceConfig = { EnvironmentFile = cfg.environmentFiles; - ExecStart="${cfg.package}/bin/bcg -c ${finalConfig} -v ${cfg.verbose}"; + ExecStart = "${cfg.package}/bin/bcg -c ${finalConfig} -v ${cfg.verbose}"; RuntimeDirectory = "bcg"; }; }; -- cgit v1.2.3