Personal Nix setup

Add mqtt server

Changed files
+67
modules
+20
modules/automation/default.nix
···
+
{ lib, helpers, ... }:
+
+
with lib; {
+
options.modules.automation = {
+
enable = mkOption {
+
default = false;
+
example = true;
+
description = "Whether to enable Home Automation options.";
+
type = types.bool;
+
};
+
};
+
+
config.modules.automation = {
+
enable = if helpers.isLinux then (mkDefault false) else (mkForce false);
+
};
+
} // helpers.linuxAttrs {
+
imports = [
+
./mqtt.nix
+
];
+
}
+46
modules/automation/mqtt.nix
···
+
{ lib, config, ... }:
+
+
with lib;
+
let
+
cfg = config.modules.automation;
+
in {
+
options.modules.automation.mqtt = {
+
enable = mkOption {
+
default = cfg.enable;
+
example = true;
+
description = "Whether to enable the mqtt mosquitto broker.";
+
type = types.bool;
+
};
+
};
+
+
config = mkIf cfg.mqtt.enable {
+
age.secrets = let
+
owner = config.users.users.mosquitto.name;
+
group = config.users.users.mosquitto.group;
+
in {
+
"mqtt.crt" = {
+
inherit owner group;
+
file = ./certs/mqtt.crt.age;
+
};
+
"mqtt.key" = {
+
inherit owner group;
+
file = ./certs/mqtt.key.age;
+
};
+
};
+
+
services.mosquitto = {
+
enable = true;
+
listeners = [
+
{
+
port = 1883;
+
settings = {
+
cafile = ../base/certs/ca.crt;
+
certfile = config.age.secrets."mqtt.crt".path;
+
keyfile = config.age.secrets."mqtt.key".path;
+
require_certificate = true;
+
};
+
}
+
];
+
};
+
};
+
}
+1
modules/default.nix
···
./nvim
./router
./server
+
./automation
];
}