mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
feat(esphome): init
This commit is contained in:
parent
26aa770508
commit
d266bdb450
8 changed files with 204 additions and 73 deletions
|
|
@ -60,6 +60,9 @@
|
||||||
"bitwarden"
|
"bitwarden"
|
||||||
"telegram"
|
"telegram"
|
||||||
"deluge"
|
"deluge"
|
||||||
|
"alt-tab"
|
||||||
|
"kicad"
|
||||||
|
"disk-inventory-x"
|
||||||
"element"
|
"element"
|
||||||
"discord"
|
"discord"
|
||||||
"firefox"
|
"firefox"
|
||||||
|
|
|
||||||
54
esphome/bedroom-sensor.nix
Normal file
54
esphome/bedroom-sensor.nix
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
{ config, ... }: {
|
||||||
|
api = {
|
||||||
|
password = "!secret api_password";
|
||||||
|
};
|
||||||
|
esp8266 = {
|
||||||
|
board = "d1_mini";
|
||||||
|
};
|
||||||
|
wifi = {
|
||||||
|
ssid = "Gensokyo";
|
||||||
|
password = "!secret wifi_password";
|
||||||
|
};
|
||||||
|
i2c = {
|
||||||
|
sda = "D2";
|
||||||
|
scl = "D1";
|
||||||
|
scan = true;
|
||||||
|
};
|
||||||
|
logger = {
|
||||||
|
level = "DEBUG";
|
||||||
|
};
|
||||||
|
ota = {
|
||||||
|
safe_mode = true;
|
||||||
|
password = "!secret ota_password";
|
||||||
|
};
|
||||||
|
sensor = [
|
||||||
|
{
|
||||||
|
platform = "dht";
|
||||||
|
model = "dht22";
|
||||||
|
update_interval = "60s";
|
||||||
|
pin = "D0";
|
||||||
|
temperature = {
|
||||||
|
name = "Bedroom Temperature";
|
||||||
|
id = "bedtemp";
|
||||||
|
};
|
||||||
|
humidity = {
|
||||||
|
name = "Bedroom Humidity";
|
||||||
|
id = "bedhum";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{
|
||||||
|
platform = "ccs811";
|
||||||
|
update_interval = "60s";
|
||||||
|
address = "0x5A";
|
||||||
|
temperature = "bedtemp";
|
||||||
|
humidity = "bedhum";
|
||||||
|
baseline = "0x2BBB";
|
||||||
|
eco2 = {
|
||||||
|
name = "Bedroom eCO2";
|
||||||
|
};
|
||||||
|
tvoc = {
|
||||||
|
name = "Bedroom Total Volatile Organic Compound";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
2
modules/esphome/genesis.nix
Normal file
2
modules/esphome/genesis.nix
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
{ config, ... }: {
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,9 @@ with lib;
|
||||||
darwinImports = mkOption {
|
darwinImports = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
};
|
};
|
||||||
|
esphomeImports = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
homeImports = mkOption {
|
homeImports = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
};
|
};
|
||||||
|
|
@ -27,12 +30,14 @@ with lib;
|
||||||
nixosImports = mkDefault (map (path: toString path) [
|
nixosImports = mkDefault (map (path: toString path) [
|
||||||
(root + "/nixos/systems/HN.nix")
|
(root + "/nixos/systems/HN.nix")
|
||||||
(root + "/nixos/systems/HN/nixos.nix")
|
(root + "/nixos/systems/HN/nixos.nix")
|
||||||
(root + "/trusted/nixos/systems/HN/nixos.nix")
|
]);
|
||||||
|
esphomeImports = mkDefault (map (path: toString path) [
|
||||||
|
(root + "/esphome/HN.nix")
|
||||||
|
(root + "/esphome/HN/esphome.nix")
|
||||||
]);
|
]);
|
||||||
darwinImports = mkDefault (map (path: toString path) [
|
darwinImports = mkDefault (map (path: toString path) [
|
||||||
(root + "/darwin/systems/HN.nix")
|
(root + "/darwin/systems/HN.nix")
|
||||||
(root + "/darwin/systems/HN/darwin.nix")
|
(root + "/darwin/systems/HN/darwin.nix")
|
||||||
(root + "/trusted/darwin/systems/HN/darwin.nix")
|
|
||||||
]);
|
]);
|
||||||
homeImports = [];
|
homeImports = [];
|
||||||
users = mkDefault (singleton "kat");
|
users = mkDefault (singleton "kat");
|
||||||
|
|
@ -42,6 +47,13 @@ with lib;
|
||||||
profiles = meta.nixos;
|
profiles = meta.nixos;
|
||||||
inherit hostName;
|
inherit hostName;
|
||||||
};
|
};
|
||||||
|
lib.kw.esphomeImport = hostName: lib.nodeImport {
|
||||||
|
nixosImports = config.network.importing.esphomeImports;
|
||||||
|
homeImports = [];
|
||||||
|
users = [];
|
||||||
|
profiles = { base = { }; };
|
||||||
|
inherit hostName;
|
||||||
|
};
|
||||||
lib.kw.darwinImport = hostName: lib.nodeImport {
|
lib.kw.darwinImport = hostName: lib.nodeImport {
|
||||||
nixosImports = config.network.importing.darwinImports;
|
nixosImports = config.network.importing.darwinImports;
|
||||||
profiles = meta.darwin;
|
profiles = meta.darwin;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{ pkgs, inputs, lib, meta, config, ... }:
|
{ pkgs, inputs, lib, meta, config, ... }:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This module:
|
This module:
|
||||||
* Makes hosts nixosModules.
|
* Makes hosts nixosModules.
|
||||||
* Manages module imports and specialArgs.
|
* Manages module imports and specialArgs.
|
||||||
* Builds network.nodes.
|
* Builds network.nodes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
|
|
@ -39,91 +39,137 @@ with lib;
|
||||||
default = toString (inputs.darwin + "/modules");
|
default = toString (inputs.darwin + "/modules");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nodes.all = mkOption {
|
esphome = {
|
||||||
|
extraModules = mkOption {
|
||||||
|
type = types.listOf types.unspecified;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
specialArgs = mkOption {
|
||||||
|
type = types.attrsOf types.unspecified;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
union = mkOption {
|
||||||
type = types.attrsOf types.unspecified;
|
type = types.attrsOf types.unspecified;
|
||||||
default = config.network.nodes.nixos // config.network.nodes.darwin;
|
default = config.network.nodes.nixos // config.network.nodes.darwin // config.network.nodes.esphome;
|
||||||
|
};
|
||||||
|
nodes.esphome = let
|
||||||
|
esphomeModule = { name, config, meta, lib, ... }: with lib;
|
||||||
|
let
|
||||||
|
settings = config.settings;
|
||||||
|
closureConfig = pkgs.writeText "${settings.esphome.name}.json" builtins.toJSON settings;
|
||||||
|
closure = pkgs.runCommand "${settings.esphome.name}" {} ''
|
||||||
|
${pkgs.esphome}/bin/esphome compile ${closureConfig}
|
||||||
|
mv .esphome/build/${settings.esphome.name}/.pioenvs/${settings.esphome.name}/firmware.bin $out
|
||||||
|
'';
|
||||||
|
in {
|
||||||
|
options.out = mkOption {
|
||||||
|
type = types.unspecified;
|
||||||
|
default = closure;
|
||||||
|
};
|
||||||
|
options.settings = mkOption {
|
||||||
|
type = types.unspecified;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
esphomeType = types.submoduleWith {
|
||||||
|
modules = [
|
||||||
|
esphomeModule
|
||||||
|
] ++ config.network.esphome.extraModules;
|
||||||
|
inherit (config.network.esphome) specialArgs;
|
||||||
|
};
|
||||||
|
in mkOption {
|
||||||
|
type = types.attrsOf esphomeType;
|
||||||
|
default = { };
|
||||||
};
|
};
|
||||||
nodes.nixos =
|
nodes.nixos =
|
||||||
let
|
let
|
||||||
nixosModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
nixosModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||||
options = {
|
options = {
|
||||||
nixpkgs.crossOverlays = mkOption {
|
nixpkgs.crossOverlays = mkOption {
|
||||||
type = types.listOf types.unspecified;
|
type = types.listOf types.unspecified;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
};
|
|
||||||
};
|
|
||||||
config = {
|
|
||||||
nixpkgs = {
|
|
||||||
system = mkDefault "x86_64-linux";
|
|
||||||
pkgs =
|
|
||||||
let
|
|
||||||
pkgsReval = import pkgs.path {
|
|
||||||
inherit (config.nixpkgs) localSystem crossSystem crossOverlays;
|
|
||||||
inherit (pkgs) overlays config;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
mkDefault (if config.nixpkgs.config == pkgs.config && config.nixpkgs.system == pkgs.targetPlatform.system then pkgs else pkgsReval);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixosType =
|
config = {
|
||||||
let
|
nixpkgs = {
|
||||||
baseModules = import (config.network.nixos.modulesPath + "/module-list.nix");
|
system = mkDefault "x86_64-linux";
|
||||||
in
|
pkgs =
|
||||||
types.submoduleWith {
|
let
|
||||||
modules = baseModules
|
pkgsReval = import pkgs.path {
|
||||||
++ singleton nixosModule
|
inherit (config.nixpkgs) localSystem crossSystem crossOverlays;
|
||||||
++ config.network.nixos.extraModules;
|
inherit (pkgs) overlays config;
|
||||||
|
};
|
||||||
specialArgs = {
|
in
|
||||||
inherit baseModules;
|
mkDefault (if config.nixpkgs.config == pkgs.config && config.nixpkgs.system == pkgs.targetPlatform.system then pkgs else pkgsReval);
|
||||||
inherit (config.network.nixos) modulesPath;
|
|
||||||
} // config.network.nixos.specialArgs;
|
|
||||||
};
|
};
|
||||||
in
|
};
|
||||||
|
};
|
||||||
|
nixosType =
|
||||||
|
let
|
||||||
|
baseModules = import (config.network.nixos.modulesPath + "/module-list.nix");
|
||||||
|
in
|
||||||
|
types.submoduleWith {
|
||||||
|
modules = baseModules
|
||||||
|
++ singleton nixosModule
|
||||||
|
++ config.network.nixos.extraModules;
|
||||||
|
|
||||||
|
specialArgs = {
|
||||||
|
inherit baseModules;
|
||||||
|
inherit (config.network.nixos) modulesPath;
|
||||||
|
} // config.network.nixos.specialArgs;
|
||||||
|
};
|
||||||
|
in
|
||||||
mkOption {
|
mkOption {
|
||||||
type = types.attrsOf nixosType;
|
type = types.attrsOf nixosType;
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
nodes.darwin =
|
nodes.darwin =
|
||||||
let
|
let
|
||||||
darwinModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
darwinModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||||
config = {
|
config = {
|
||||||
_module.args.pkgs = pkgs;
|
_module.args.pkgs = pkgs;
|
||||||
nixpkgs = {
|
nixpkgs = {
|
||||||
system = mkDefault pkgs.system;
|
system = mkDefault pkgs.system;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
darwinType =
|
};
|
||||||
let
|
darwinType =
|
||||||
baseModules = import (config.network.darwin.modulesPath + "/module-list.nix");
|
let
|
||||||
flakeModule = (config.network.darwin.modulesPath + "/system/flake-overrides.nix");
|
baseModules = import (config.network.darwin.modulesPath + "/module-list.nix");
|
||||||
in
|
flakeModule = (config.network.darwin.modulesPath + "/system/flake-overrides.nix");
|
||||||
types.submoduleWith {
|
in
|
||||||
modules = baseModules
|
types.submoduleWith {
|
||||||
++ singleton darwinModule
|
modules = baseModules
|
||||||
++ singleton flakeModule
|
++ singleton darwinModule
|
||||||
++ config.network.darwin.extraModules;
|
++ singleton flakeModule
|
||||||
|
++ config.network.darwin.extraModules;
|
||||||
|
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit baseModules;
|
inherit baseModules;
|
||||||
inherit (config.network.darwin) modulesPath;
|
inherit (config.network.darwin) modulesPath;
|
||||||
} // config.network.darwin.specialArgs;
|
} // config.network.darwin.specialArgs;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
mkOption {
|
mkOption {
|
||||||
type = types.attrsOf darwinType;
|
type = types.attrsOf darwinType;
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config.network = {
|
config.network = {
|
||||||
|
esphome = {
|
||||||
|
extraModules = [
|
||||||
|
];
|
||||||
|
specialArgs = {
|
||||||
|
inherit (config.network) nodes;
|
||||||
|
inherit inputs meta;
|
||||||
|
};
|
||||||
|
};
|
||||||
darwin = {
|
darwin = {
|
||||||
extraModules = [
|
extraModules = [
|
||||||
inputs.home-manager.darwinModules.home-manager
|
inputs.home-manager.darwinModules.home-manager
|
||||||
meta.modules.darwin
|
meta.modules.darwin
|
||||||
meta.modules.system
|
meta.modules.system
|
||||||
meta.system
|
meta.system
|
||||||
];
|
];
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit (config.network) nodes;
|
inherit (config.network) nodes;
|
||||||
|
|
@ -133,10 +179,10 @@ with lib;
|
||||||
nixos = {
|
nixos = {
|
||||||
extraModules = [
|
extraModules = [
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
meta.modules.nixos
|
meta.modules.nixos
|
||||||
meta.modules.system
|
meta.modules.system
|
||||||
meta.nixos.network
|
meta.nixos.network
|
||||||
meta.system
|
meta.system
|
||||||
];
|
];
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit (config.network) nodes;
|
inherit (config.network) nodes;
|
||||||
|
|
|
||||||
1
nixos/systems/tewi/configuration.json
Normal file
1
nixos/systems/tewi/configuration.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"automation":"automations.yaml","config":null,"counter":null,"dhcp":null,"device_tracker":[{"platform":"luci","host":"192.168.1.1","username":"root","password":"suitable-anemia-boggle","new_device_defaults":{"track_new_devices":true}}],"energy":null,"frontend":{"themes":"themes"},"group":"groups.yaml","google_assistant":{"project_id":"integration-9e79d","service_account":"integration-9e79d-a60665a0b920.json"},"http":{"cors_allowed_origins":["https://google.com","https://www.home-assistant.io"],"use_x_forwarded_for":true,"trusted_proxies":["127.0.0.0/24","200::/7"]},"history":null,"image":null,"input_boolean":null,"input_datetime":null,"input_number":null,"input_select":null,"input_text":null,"logbook":null,"logger":{"default":"info"},"map":null,"media_source":null,"mobile_app":null,"my":null,"person":null,"scene":"scenes.yaml","script":"scripts.yaml","ssdp":null,"switch":[{"platform":"wake_on_lan","mac":"00:D8:61:C7:F4:9D"}],"stream":null,"sun":null,"system_health":null,"tag":null,"template":null,"timer":null,"webhook":null,"wake_on_lan":null,"zeroconf":null,"zone":null,"recorder":{"auto_purge":true,"purge_keep_days":14,"commit_interval":1,"exclude":{"domains":["automation","updater"],"entity_globs":["sensor.weather_*","sensor.date_*"],"entities":["sun.sun","sensor.last_boot","sensor.date","sensor.time"],"event_types":["call_service"]}},"tts":[{"platform":"google_translate","service_name":"google_say"}],"homeassistant":{"packages":"packages","customize":"customize.yaml","external_url":"https://home.kittywit.ch"}}
|
||||||
15
outputs.nix
15
outputs.nix
|
|
@ -122,6 +122,18 @@
|
||||||
nixfiles = tree.impure;
|
nixfiles = tree.impure;
|
||||||
|
|
||||||
eval = let
|
eval = let
|
||||||
|
esphomeNodes = (map
|
||||||
|
(node: {
|
||||||
|
network.nodes.esphome.${node} = {
|
||||||
|
settings = {
|
||||||
|
imports = config.lib.kw.esphomeImport node;
|
||||||
|
esphome = {
|
||||||
|
name = node;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
(lib.attrNames nixfiles.esphome));
|
||||||
nixosNodes = (map
|
nixosNodes = (map
|
||||||
(node: {
|
(node: {
|
||||||
network.nodes.nixos.${node} = {
|
network.nodes.nixos.${node} = {
|
||||||
|
|
@ -147,7 +159,8 @@
|
||||||
++ lib.singleton nixfiles.modules.meta
|
++ lib.singleton nixfiles.modules.meta
|
||||||
++ lib.attrValues nixfiles.targets
|
++ lib.attrValues nixfiles.targets
|
||||||
++ nixosNodes
|
++ nixosNodes
|
||||||
++ darwinNodes;
|
++ darwinNodes
|
||||||
|
++ esphomeNodes;
|
||||||
|
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit root tree;
|
inherit root tree;
|
||||||
|
|
|
||||||
2
tf
2
tf
|
|
@ -1 +1 @@
|
||||||
Subproject commit 19085b061685d726090c2b5fdc3afe536ad43dd7
|
Subproject commit 856827e23fd7f1ef1d07dea9c5be26c0a0f7dee8
|
||||||
Loading…
Add table
Add a link
Reference in a new issue