refactor(esphome): only delete files that finish with -nix.yaml
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
6d759fd9a3
commit
8edc73cd41
1 changed files with 12 additions and 18 deletions
|
@ -6,7 +6,7 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) converge getExe mkOption types;
|
inherit (lib) converge getExe mkOption types;
|
||||||
inherit (lib.modules) mkForce mkIf;
|
inherit (lib.modules) mkForce mkIf;
|
||||||
inherit (lib.lists) elem optionals;
|
inherit (lib.lists) elem;
|
||||||
inherit (lib.strings) concatMapStringsSep optionalString;
|
inherit (lib.strings) concatMapStringsSep optionalString;
|
||||||
inherit (lib.attrsets) mapAttrsToList filterAttrsRecursive optionalAttrs;
|
inherit (lib.attrsets) mapAttrsToList filterAttrsRecursive optionalAttrs;
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
format = pkgs.formats.yaml {};
|
format = pkgs.formats.yaml {};
|
||||||
|
|
||||||
# Adapted from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/home-automation/home-assistant.nix
|
# Adapted from https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/home-automation/home-assistant.nix
|
||||||
mkESPConf = name: cfg: let
|
mkESPConf = n: cfg: let
|
||||||
filteredConfig = converge (filterAttrsRecursive (_: v: ! elem v [null])) cfg;
|
filteredConfig = converge (filterAttrsRecursive (_: v: ! elem v [null])) cfg;
|
||||||
in {
|
in rec {
|
||||||
name = "${name}.yaml";
|
name = "${n}-nix.yaml";
|
||||||
file = pkgs.runCommandLocal "${name}.yaml" {} ''
|
file = pkgs.runCommandLocal name {} ''
|
||||||
cp ${format.generate name 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
|
||||||
|
@ -39,11 +39,6 @@ in {
|
||||||
default = null;
|
default = null;
|
||||||
type = types.nullOr types.path;
|
type = types.nullOr types.path;
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteUnmanaged = mkOption {
|
|
||||||
default = true;
|
|
||||||
type = types.bool;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
@ -99,11 +94,17 @@ in {
|
||||||
ExecStartPre = getExe (pkgs.writeShellApplication {
|
ExecStartPre = getExe (pkgs.writeShellApplication {
|
||||||
name = "esphome-exec-start-pre";
|
name = "esphome-exec-start-pre";
|
||||||
|
|
||||||
runtimeInputs = optionals cfg.deleteUnmanaged [
|
runtimeInputs = [
|
||||||
pkgs.findutils
|
pkgs.findutils
|
||||||
];
|
];
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
|
shopt -s nullglob
|
||||||
|
|
||||||
|
for file in ${stateDir}/*-nix.yaml; do
|
||||||
|
rm "$file"
|
||||||
|
done
|
||||||
|
|
||||||
${optionalString
|
${optionalString
|
||||||
(cfg.secretsFile != null)
|
(cfg.secretsFile != null)
|
||||||
# bash
|
# bash
|
||||||
|
@ -111,13 +112,6 @@ in {
|
||||||
cp -f "$(realpath "${cfg.secretsFile}")" ${stateDir}/secrets.yaml
|
cp -f "$(realpath "${cfg.secretsFile}")" ${stateDir}/secrets.yaml
|
||||||
''}
|
''}
|
||||||
|
|
||||||
${optionalString
|
|
||||||
cfg.deleteUnmanaged
|
|
||||||
# bash
|
|
||||||
''
|
|
||||||
find ${stateDir} -name "*.yaml" ! -name "secrets.yaml" -delete
|
|
||||||
''}
|
|
||||||
|
|
||||||
${concatMapStringsSep
|
${concatMapStringsSep
|
||||||
"\n"
|
"\n"
|
||||||
(dev:
|
(dev:
|
||||||
|
|
Loading…
Add table
Reference in a new issue