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
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 {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
esphomeImports = mkOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
homeImports = mkOption {
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
|
|
@ -27,12 +30,14 @@ with lib;
|
|||
nixosImports = mkDefault (map (path: toString path) [
|
||||
(root + "/nixos/systems/HN.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) [
|
||||
(root + "/darwin/systems/HN.nix")
|
||||
(root + "/darwin/systems/HN/darwin.nix")
|
||||
(root + "/trusted/darwin/systems/HN/darwin.nix")
|
||||
]);
|
||||
homeImports = [];
|
||||
users = mkDefault (singleton "kat");
|
||||
|
|
@ -42,6 +47,13 @@ with lib;
|
|||
profiles = meta.nixos;
|
||||
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 {
|
||||
nixosImports = config.network.importing.darwinImports;
|
||||
profiles = meta.darwin;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{ pkgs, inputs, lib, meta, config, ... }:
|
||||
|
||||
/*
|
||||
This module:
|
||||
* Makes hosts nixosModules.
|
||||
* Manages module imports and specialArgs.
|
||||
* Builds network.nodes.
|
||||
*/
|
||||
This module:
|
||||
* Makes hosts nixosModules.
|
||||
* Manages module imports and specialArgs.
|
||||
* Builds network.nodes.
|
||||
*/
|
||||
|
||||
with lib;
|
||||
|
||||
|
|
@ -39,91 +39,137 @@ with lib;
|
|||
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;
|
||||
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 =
|
||||
let
|
||||
nixosModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||
options = {
|
||||
nixpkgs.crossOverlays = mkOption {
|
||||
type = types.listOf types.unspecified;
|
||||
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);
|
||||
};
|
||||
nixosModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||
options = {
|
||||
nixpkgs.crossOverlays = mkOption {
|
||||
type = types.listOf types.unspecified;
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
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;
|
||||
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);
|
||||
};
|
||||
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 {
|
||||
type = types.attrsOf nixosType;
|
||||
default = { };
|
||||
};
|
||||
nodes.darwin =
|
||||
let
|
||||
darwinModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||
config = {
|
||||
_module.args.pkgs = pkgs;
|
||||
nixpkgs = {
|
||||
system = mkDefault pkgs.system;
|
||||
};
|
||||
darwinModule = { name, config, meta, modulesPath, lib, ... }: with lib; {
|
||||
config = {
|
||||
_module.args.pkgs = pkgs;
|
||||
nixpkgs = {
|
||||
system = mkDefault pkgs.system;
|
||||
};
|
||||
};
|
||||
darwinType =
|
||||
let
|
||||
baseModules = import (config.network.darwin.modulesPath + "/module-list.nix");
|
||||
flakeModule = (config.network.darwin.modulesPath + "/system/flake-overrides.nix");
|
||||
in
|
||||
types.submoduleWith {
|
||||
modules = baseModules
|
||||
++ singleton darwinModule
|
||||
++ singleton flakeModule
|
||||
++ config.network.darwin.extraModules;
|
||||
};
|
||||
darwinType =
|
||||
let
|
||||
baseModules = import (config.network.darwin.modulesPath + "/module-list.nix");
|
||||
flakeModule = (config.network.darwin.modulesPath + "/system/flake-overrides.nix");
|
||||
in
|
||||
types.submoduleWith {
|
||||
modules = baseModules
|
||||
++ singleton darwinModule
|
||||
++ singleton flakeModule
|
||||
++ config.network.darwin.extraModules;
|
||||
|
||||
specialArgs = {
|
||||
inherit baseModules;
|
||||
inherit (config.network.darwin) modulesPath;
|
||||
} // config.network.darwin.specialArgs;
|
||||
};
|
||||
in
|
||||
specialArgs = {
|
||||
inherit baseModules;
|
||||
inherit (config.network.darwin) modulesPath;
|
||||
} // config.network.darwin.specialArgs;
|
||||
};
|
||||
in
|
||||
mkOption {
|
||||
type = types.attrsOf darwinType;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
config.network = {
|
||||
esphome = {
|
||||
extraModules = [
|
||||
];
|
||||
specialArgs = {
|
||||
inherit (config.network) nodes;
|
||||
inherit inputs meta;
|
||||
};
|
||||
};
|
||||
darwin = {
|
||||
extraModules = [
|
||||
inputs.home-manager.darwinModules.home-manager
|
||||
meta.modules.darwin
|
||||
meta.modules.system
|
||||
meta.system
|
||||
meta.modules.darwin
|
||||
meta.modules.system
|
||||
meta.system
|
||||
];
|
||||
specialArgs = {
|
||||
inherit (config.network) nodes;
|
||||
|
|
@ -133,10 +179,10 @@ with lib;
|
|||
nixos = {
|
||||
extraModules = [
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
meta.modules.nixos
|
||||
meta.modules.system
|
||||
meta.nixos.network
|
||||
meta.system
|
||||
meta.modules.nixos
|
||||
meta.modules.system
|
||||
meta.nixos.network
|
||||
meta.system
|
||||
];
|
||||
specialArgs = {
|
||||
inherit (config.network) nodes;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue