feat(hass): extend options of services with configFiles
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
56eeb7745c
commit
8bcb9c43ad
6 changed files with 125 additions and 61 deletions
|
@ -1,4 +1,4 @@
|
|||
{pkgs, ...}: {
|
||||
{pkgs, self, ...}: {
|
||||
imports = [
|
||||
./assist.nix
|
||||
./bluetooth.nix
|
||||
|
@ -7,9 +7,9 @@
|
|||
./netdaemon
|
||||
./spotify.nix
|
||||
./timer.nix
|
||||
];
|
||||
|
||||
# TODO: nix: add HA options for custom_sentences and stuff
|
||||
self.nixosModules.ha-plus
|
||||
];
|
||||
|
||||
services.home-assistant = {
|
||||
enable = true;
|
||||
|
|
|
@ -3,31 +3,18 @@
|
|||
dracul-ha-src,
|
||||
material-rounded-theme-src,
|
||||
material-symbols-src,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) concatStringsSep getExe;
|
||||
inherit (pkgs.writers) writeYAML;
|
||||
|
||||
themes = [
|
||||
"${caule-themes-src}/themes/caule-themes-pack-1.yaml"
|
||||
"${dracul-ha-src}/themes/dracul-ha.yaml"
|
||||
"${material-rounded-theme-src}/themes/material_rounded.yaml"
|
||||
];
|
||||
in {
|
||||
systemd.services.home-assistant.preStart = let
|
||||
WorkingDirectory = "/var/lib/hass";
|
||||
in
|
||||
getExe (pkgs.writeShellApplication {
|
||||
name = "ha-themes";
|
||||
text = ''
|
||||
mkdir -p ${WorkingDirectory}/themes
|
||||
cp -f ${concatStringsSep " " themes} ${WorkingDirectory}/themes
|
||||
'';
|
||||
});
|
||||
|
||||
services.home-assistant = {
|
||||
configFiles = {
|
||||
"themes/caule.yaml".source = "${caule-themes-src}/themes/caule-themes-pack-1.yaml";
|
||||
"themes/dracul-ha.yaml".source = "${dracul-ha-src}/themes/dracul-ha.yaml";
|
||||
"themes/material_rounded.yaml".source = "${material-rounded-theme-src}/themes/material_rounded.yaml";
|
||||
};
|
||||
|
||||
customLovelaceModules = builtins.attrValues {
|
||||
inherit
|
||||
(pkgs.home-assistant-custom-lovelace-modules)
|
||||
|
|
|
@ -1,27 +1,9 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
self,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) getExe;
|
||||
inherit (pkgs.writers) writeYAML;
|
||||
in {
|
||||
systemd.services.home-assistant.preStart = let
|
||||
WorkingDirectory = "/var/lib/hass";
|
||||
creds = config.sops.secrets.spotifyd.path;
|
||||
spotify = writeYAML "assist_spotify.yaml" (import ./spotify-sentences.nix);
|
||||
in
|
||||
getExe (pkgs.writeShellApplication {
|
||||
name = "spotify-files";
|
||||
text = ''
|
||||
mkdir -p ${WorkingDirectory}/custom_sentences/en
|
||||
cp -f ${spotify} ${WorkingDirectory}/custom_sentences/en/assist_spotify.yaml
|
||||
cp -f ${creds} ${WorkingDirectory}/.storage/SpotifyWebApiPython_librespot_credentials.json
|
||||
'';
|
||||
});
|
||||
|
||||
}: {
|
||||
services.home-assistant = {
|
||||
customComponents = builtins.attrValues {
|
||||
inherit
|
||||
|
@ -34,6 +16,12 @@ in {
|
|||
"spotify"
|
||||
];
|
||||
|
||||
customSentences."assist_spotify" = import ./spotify-sentences.nix;
|
||||
|
||||
configFiles.
|
||||
".storage/SpotifyWebApiPython_librespot_credentials.json"
|
||||
.source = config.sops.secrets.spotifyd.path;
|
||||
|
||||
config.intent_script = {
|
||||
PlayAlbum = {
|
||||
async_action = "false";
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
# From https://github.com/don86nl/ha_intents/blob/main/config/packages/assist_timers.yaml
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) concatStrings concatStringsSep getExe;
|
||||
inherit (pkgs.writers) writeYAML;
|
||||
{lib, ...}: let
|
||||
inherit (lib) concatStrings concatStringsSep;
|
||||
|
||||
mkTimer = id: {
|
||||
"assist_timer${toString id}" = {
|
||||
|
@ -43,20 +38,9 @@
|
|||
timer_media_location = "/path/to/file.mp3";
|
||||
};
|
||||
in {
|
||||
systemd.services.home-assistant.preStart = let
|
||||
WorkingDirectory = "/var/lib/hass";
|
||||
|
||||
timer = writeYAML "assist_timers.yaml" (import ./timer-sentences.nix);
|
||||
in
|
||||
getExe (pkgs.writeShellApplication {
|
||||
name = "timer-files";
|
||||
text = ''
|
||||
mkdir -p ${WorkingDirectory}/custom_sentences/en
|
||||
cp -f ${timer} ${WorkingDirectory}/custom_sentences/en/assist_timers.yaml
|
||||
'';
|
||||
});
|
||||
|
||||
services.home-assistant = {
|
||||
customSentences."assist_timers" = import ./timer-sentences.nix;
|
||||
|
||||
config = {
|
||||
homeassistant.customize."script.assist_timerstart" = {inherit settings;};
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ self: {
|
|||
desktop = import ./desktop self;
|
||||
docker = import ./docker self.inputs.khepri;
|
||||
esphome-plus = import ./esphome-plus;
|
||||
ha-plus = import ./ha-plus;
|
||||
kmscon = import ./kmscon;
|
||||
nvidia = import ./nvidia;
|
||||
plymouth = import ./plymouth;
|
||||
|
|
104
nixosModules/ha-plus/default.nix
Normal file
104
nixosModules/ha-plus/default.nix
Normal file
|
@ -0,0 +1,104 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) any attrValues concatMapStringsSep getExe mapAttrs' mkDefault mkDerivedConfig mkIf mkOption nameValuePair replaceStrings types;
|
||||
|
||||
cfg = config.services.home-assistant;
|
||||
format = pkgs.formats.yaml {};
|
||||
configFilesList = attrValues cfg.configFiles;
|
||||
in {
|
||||
options.services.home-assistant = {
|
||||
configFiles = mkOption {
|
||||
default = {};
|
||||
description = ''
|
||||
Set of files that have to be linked in the configuration directory.
|
||||
'';
|
||||
|
||||
type = types.attrsOf (types.submodule (
|
||||
{
|
||||
name,
|
||||
config,
|
||||
options,
|
||||
...
|
||||
}: {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether this file should be generated. This
|
||||
option allows specific files to be disabled.
|
||||
'';
|
||||
};
|
||||
|
||||
target = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
Name of symlink (relative to config directory).
|
||||
Defaults to the attribute name.
|
||||
'';
|
||||
};
|
||||
|
||||
text = mkOption {
|
||||
default = null;
|
||||
type = types.nullOr types.lines;
|
||||
description = "Text of the file.";
|
||||
};
|
||||
|
||||
source = mkOption {
|
||||
type = types.path;
|
||||
description = "Path of the source file.";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
target = mkDefault name;
|
||||
source = mkIf (config.text != null) (
|
||||
let
|
||||
name' = "haConf-" + replaceStrings ["/"] ["-"] name;
|
||||
in
|
||||
mkDerivedConfig options.text (pkgs.writeText name')
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
};
|
||||
|
||||
customSentences = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
freeformType = format.type;
|
||||
options.language = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.home-assistant =
|
||||
mkIf (
|
||||
cfg.configFiles != {} && any (c: c.enable) configFilesList
|
||||
) {
|
||||
preStart = let
|
||||
inherit (cfg) configDir;
|
||||
mkLink = configFile: ''
|
||||
mkdir -p ${configDir}/${dirOf configFile.target}
|
||||
cp -rf ${configFile.source} ${configDir}/${configFile.target}
|
||||
'';
|
||||
in
|
||||
getExe (pkgs.writeShellApplication {
|
||||
name = "home-assistant-pre-start";
|
||||
text = concatMapStringsSep "\n" mkLink configFilesList;
|
||||
});
|
||||
};
|
||||
|
||||
services.home-assistant.configFiles = mapAttrs' (n: v:
|
||||
nameValuePair "custom_sentences/${v.language}/${n}.yaml" {
|
||||
source = format.generate n v;
|
||||
})
|
||||
cfg.customSentences;
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue