feat(esphome): add secretsFile option

This commit is contained in:
matt1432 2024-09-05 22:42:17 -04:00
commit 9dee168383
5 changed files with 57 additions and 38 deletions
devices/homie/modules/home-assistant
flake.lock
nixosModules/esphome-plus
outputs.nix

View file

@ -53,4 +53,7 @@
port = 6052; port = 6052;
}; };
}; };
# In case tailscale is down
boot.kernel.sysctl."net.ipv4.ip_nonlocal_bind" = 1;
} }

View file

@ -1,5 +1,8 @@
{...}: { {config, ...}: {
services.esphome.firmwareConfigs = { services.esphome = {
secretsFile = config.sops.secrets.esphome.path;
firmwareConfigs = {
"esp1" = { "esp1" = {
packages.remote_package_files = { packages.remote_package_files = {
url = "https://github.com/esphome/firmware"; url = "https://github.com/esphome/firmware";
@ -37,4 +40,5 @@
}; };
}; };
}; };
};
} }

8
flake.lock generated
View file

@ -1757,11 +1757,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1723480554, "lastModified": 1725588406,
"narHash": "sha256-2giqpDLWpVYy5GV87x20GzRAxORGToeaKsWjEOyFB8o=", "narHash": "sha256-yX3/SKEP/AB4IJiV8X008tnOepTla0XeJ9m2d6VoQAQ=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "205779bc5f06840e30e0a90d97baa61e42b6a76a", "rev": "fe8958ac8792da69e7071e69482bc488a65f926f",
"revCount": 73, "revCount": 76,
"type": "git", "type": "git",
"url": "ssh://git@git.nelim.org/matt1432/nixos-secrets" "url": "ssh://git@git.nelim.org/matt1432/nixos-secrets"
}, },

View file

@ -37,7 +37,7 @@
in { in {
name = "${name}.yaml"; name = "${name}.yaml";
file = pkgs.runCommandLocal "${name}.yaml" {} '' file = pkgs.runCommandLocal "${name}.yaml" {} ''
cp ${format.generate "${name}.yaml" filteredConfig} $out cp ${format.generate name filteredConfig} $out
sed -i -e "s/'\!\([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out sed -i -e "s/'\!\([a-z_]\+\) \(.*\)'/\!\1 \2/;s/^\!\!/\!/;" $out
sed -i 's/ {}//g' $out sed -i 's/ {}//g' $out
''; '';
@ -49,6 +49,11 @@ in {
type = with types; attrsOf anything; type = with types; attrsOf anything;
}; };
secretsFile = mkOption {
default = null;
type = types.nullOr types.path;
};
deleteUnmanaged = mkOption { deleteUnmanaged = mkOption {
default = true; default = true;
type = types.bool; type = types.bool;
@ -74,6 +79,8 @@ in {
mkdir -p ${stateDir} mkdir -p ${stateDir}
fi fi
${optionalString (cfg.secretsFile != null) ''cp -f "$(realpath "${cfg.secretsFile}")" ${stateDir}/secrets.yaml''}
${optionalString cfg.deleteUnmanaged ''find ${stateDir} -name "*.yaml" ! -name "secrets.yaml" -delete''} ${optionalString cfg.deleteUnmanaged ''find ${stateDir} -name "*.yaml" ! -name "secrets.yaml" -delete''}
${concatMapStringsSep ${concatMapStringsSep

View file

@ -98,7 +98,12 @@
}; };
# Home-assistant # Home-assistant
homie = mkNixOS {extraModules = [./devices/homie];}; homie = mkNixOS {
extraModules = [
./devices/homie
secrets.nixosModules.homie
];
};
# Cluster # Cluster
thingone = mkNixOS { thingone = mkNixOS {