refactor: moved nixos modules to dendrite pattern
This commit is contained in:
parent
df8dd110ad
commit
0ea11e0236
219 changed files with 4802 additions and 4820 deletions
55
modules/nixos/programs/home-assistant/database.nix
Normal file
55
modules/nixos/programs/home-assistant/database.nix
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
{...}: {
|
||||
flake.nixosModules.home-assistant-database = {
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
options.services.home-assistant = {
|
||||
postgres = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Use PostgreSQL instead of SQLite";
|
||||
};
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "hass";
|
||||
description = "Database user name";
|
||||
};
|
||||
database = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "hass";
|
||||
description = "Database name";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.services.home-assistant.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = !config.services.home-assistant.postgres.enable || config.services.postgresql.enable;
|
||||
message = "PostgreSQL must be enabled when using postgres database for Home Assistant";
|
||||
}
|
||||
];
|
||||
|
||||
services.postgresql.databases.home-assistant = lib.mkIf config.services.home-assistant.postgres.enable {
|
||||
enable = true;
|
||||
user = config.services.home-assistant.postgres.user;
|
||||
database = config.services.home-assistant.postgres.database;
|
||||
};
|
||||
|
||||
services.home-assistant = lib.mkIf config.services.home-assistant.postgres.enable {
|
||||
extraPackages = python3Packages:
|
||||
with python3Packages; [
|
||||
psycopg2
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.home-assistant = lib.mkIf config.services.home-assistant.postgres.enable {
|
||||
requires = [
|
||||
config.systemd.services.postgresql.name
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue