diff options
author | Karel Kočí <cynerd@email.cz> | 2024-04-16 10:18:26 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2024-04-16 10:18:26 +0200 |
commit | 2fcf002e3abff092eafd098fadafa15ea579aae4 (patch) | |
tree | 7d5c1617ff3867313c5a373fdd7f2c4ae4c06495 | |
parent | e9fcc90c41dbccbb18c7b7314096b854b21ee02a (diff) | |
download | nixos-personal-2fcf002e3abff092eafd098fadafa15ea579aae4.tar.gz nixos-personal-2fcf002e3abff092eafd098fadafa15ea579aae4.tar.bz2 nixos-personal-2fcf002e3abff092eafd098fadafa15ea579aae4.zip |
Move from i3blocks to waybar and use fixed bcg
-rw-r--r-- | flake.lock | 39 | ||||
-rw-r--r-- | flake.nix | 3 | ||||
-rw-r--r-- | nixos/modules/bcg.nix | 170 | ||||
-rw-r--r-- | nixos/modules/default.nix | 8 | ||||
-rw-r--r-- | nixos/modules/desktop.nix | 6 |
5 files changed, 201 insertions, 25 deletions
@@ -65,11 +65,11 @@ "systems": "systems_3" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -259,11 +259,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1712843601, - "narHash": "sha256-rP6jyldorUthnWWhnMMC+Zlrm5jopoAddbJaV76tiS8=", + "lastModified": 1713117084, + "narHash": "sha256-uxmw58V8HyjKcDNfQi2QDL1WqhCvOxadR+aOwMSlH+0=", "owner": "cynerd", "repo": "nixdeploy", - "rev": "0ce1fa81bddfd7b32661222d5d2afe9b6d03cc1c", + "rev": "6a74fdf370b1a6d3b9636ea4c8c5a61f9e20f3ca", "type": "gitlab" }, "original": { @@ -274,11 +274,11 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1712760404, - "narHash": "sha256-4zhaEW1nB+nGbCNMjOggWeY5nXs/H0Y71q0+h+jdxoU=", + "lastModified": 1712909959, + "narHash": "sha256-7/5ubuwdEbQ7Z+Vqd4u0mM5L2VMNDsBh54visp27CtQ=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "e1c4bac14beb8c409d0534382cf967171706b9d9", + "rev": "f58b25254be441cd2a9b4b444ed83f1e51244f1f", "type": "github" }, "original": { @@ -318,11 +318,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1708469763, - "narHash": "sha256-wCJljz6nQdCAnfTx+3i4fWteB3TnVEq95z6d6LhwVKs=", + "lastModified": 1712883908, + "narHash": "sha256-icE1IJE9fHcbDfJ0+qWoDdcBXUoZCcIJxME4lMHwvSM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5eeded8e3518579daa13887297efa79f5be74b41", + "rev": "a0c9e3aee1000ac2bfb0e5b98c94c946a5d180a9", "type": "github" }, "original": { @@ -332,18 +332,17 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1712821377, - "narHash": "sha256-Ecicszr4B4ZsL5dLnYGDNVO4J1Qc+1NYedm3frzCxvQ=", - "owner": "cynerd", + "lastModified": 1712963716, + "narHash": "sha256-WKm9CvgCldeIVvRz87iOMi8CFVB1apJlkUT4GGvA0iM=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "d764d77b96b77a02575d70f2e815a19db518756e", + "rev": "cfd6b5fc90b15709b780a5a1619695a88505a176", "type": "github" }, "original": { - "owner": "cynerd", - "ref": "bcg-fix-unstable", - "repo": "nixpkgs", - "type": "github" + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" } }, "nixpkgs_4": { @@ -2,8 +2,7 @@ description = "Cynerd's personal flake"; inputs = { - #nixpkgs.url = "nixpkgs/nixos-unstable"; - nixpkgs.url = "github:cynerd/nixpkgs/bcg-fix-unstable"; + nixpkgs.url = "nixpkgs/nixos-unstable"; nixos-hardware.url = "nixos-hardware"; nixdeploy.url = "gitlab:cynerd/nixdeploy"; personal-secret.url = "git+ssh://git@cynerd.cz/nixos-personal-secret"; diff --git a/nixos/modules/bcg.nix b/nixos/modules/bcg.nix new file mode 100644 index 0000000..626a67f --- /dev/null +++ b/nixos/modules/bcg.nix @@ -0,0 +1,170 @@ +{ + config, + lib, + pkgs, + ... +}: + +with lib; + +let + cfg = config.services.bcg; + configFile = (pkgs.formats.yaml {}).generate "bcg.conf.yaml" ( + filterAttrsRecursive (n: v: v != null) { + inherit (cfg) device name mqtt; + retain_node_messages = cfg.retainNodeMessages; + qos_node_messages = cfg.qosNodeMessages; + base_topic_prefix = cfg.baseTopicPrefix; + automatic_remove_kit_from_names = cfg.automaticRemoveKitFromNames; + automatic_rename_kit_nodes = cfg.automaticRenameKitNodes; + automatic_rename_generic_nodes = cfg.automaticRenameGenericNodes; + automatic_rename_nodes = cfg.automaticRenameNodes; + } + ); +in +{ + options = { + services.bcg = { + enable = mkEnableOption "BigClown gateway"; + package = mkPackageOption pkgs [ "python3Packages" "bcg" ] { }; + environmentFiles = mkOption { + type = types.listOf types.path; + default = []; + 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 + syntax: `$ENVIRONMENT` or `''${VARIABLE}`. + This is useful to avoid putting secrets into the nix store. + ''; + }; + verbose = mkOption { + type = types.enum ["CRITICAL" "ERROR" "WARNING" "INFO" "DEBUG"]; + default = "WARNING"; + description = "Verbosity level."; + }; + device = mkOption { + type = types.str; + description = "Device name to configure gateway to use."; + }; + name = mkOption { + type = with types; nullOr str; + default = null; + description = '' + Name for the device. + + Supported variables: + * `{ip}` IP address + * `{id}` The ID of the connected usb-dongle or core-module + + `null` can be used for automatic detection from gateway firmware. + ''; + }; + mqtt = { + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = "Host where MQTT server is running."; + }; + port = mkOption { + type = types.port; + default = 1883; + description = "Port of MQTT server."; + }; + username = mkOption { + type = with types; nullOr str; + default = null; + description = "MQTT server access username."; + }; + password = mkOption { + type = with types; nullOr str; + default = null; + description = "MQTT server access password."; + }; + cafile = mkOption { + type = with types; nullOr str; + default = null; + description = "Certificate Authority file for MQTT server access."; + }; + certfile = mkOption { + type = with types; nullOr str; + default = null; + description = "Certificate file for MQTT server access."; + }; + keyfile = mkOption { + type = with types; nullOr str; + default = null; + description = "Key file for MQTT server access."; + }; + }; + retainNodeMessages = mkOption { + type = types.bool; + default = false; + description = "Specify that node messages should be retaied in MQTT broker."; + }; + qosNodeMessages = mkOption { + type = types.int; + default = 1; + description = "Set the guarantee of MQTT message delivery."; + }; + baseTopicPrefix = mkOption { + type = types.str; + default = ""; + description = "Topic prefix added to all MQTT messages."; + }; + automaticRemoveKitFromNames = mkOption { + type = types.bool; + default = true; + description = "Automatically remove kits."; + }; + automaticRenameKitNodes = mkOption { + type = types.bool; + default = true; + description = "Automatically rename kit's nodes."; + }; + automaticRenameGenericNodes = mkOption { + type = types.bool; + default = true; + description = "Automatically rename generic nodes."; + }; + automaticRenameNodes = mkOption { + type = types.bool; + default = true; + description = "Automatically rename all nodes."; + }; + rename = mkOption { + type = with types; attrsOf str; + default = {}; + description = "Rename nodes to different name."; + }; + }; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + python3Packages.bcg + python3Packages.bch + ]; + + systemd.services.bcg = let + envConfig = cfg.environmentFiles != []; + 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" ]; + 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}"; + RuntimeDirectory = "bcg"; + }; + }; + }; +} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index c47228b..90a4b58 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -13,4 +13,10 @@ v == "regular" && n != "default.nix" && hasSuffix ".nix" n ) (readDir ./.)); in - modules // {default.imports = attrValues modules ++ default_modules;} + modules + // { + default = { + imports = attrValues modules ++ default_modules; + disabledModules = [ "services/misc/bcg.nix" ]; + }; + } diff --git a/nixos/modules/desktop.nix b/nixos/modules/desktop.nix index 87f18e8..2e67730 100644 --- a/nixos/modules/desktop.nix +++ b/nixos/modules/desktop.nix @@ -4,7 +4,7 @@ pkgs, ... }: let - inherit (lib) mkOption mkIf types optionals; + inherit (lib) mkOption mkIf mkDefault types optionals; cnf = config.cynerd.desktop; in { options = { @@ -32,11 +32,11 @@ in { gnome.dconf-editor glib gsettings-desktop-schemas - i3blocks sysstat wofi rofimoji wev + waybar swaybackground myswaylock @@ -226,6 +226,8 @@ in { ]; }; + services.upower.enable = mkDefault cnf.laptop; + services.avahi.enable = true; services.samba-wsdd = { enable = true; |