about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorRobert Schütz <robert.schuetz@stud.uni-heidelberg.de>2019-01-24 15:52:05 +0100
committerRobert Schütz <robert.schuetz@stud.uni-heidelberg.de>2019-01-29 08:56:51 +0100
commit7cc7c5374c1bbad10774d81d81e644662b06acb8 (patch)
treea6e87332abc612324f91e2311d02f3862817bd9f /nixos
parent6cb6b90f1a67f0513fa34c3db880684e6ae533a6 (diff)
downloadnixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar.gz
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar.bz2
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar.lz
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar.xz
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.tar.zst
nixlib-7cc7c5374c1bbad10774d81d81e644662b06acb8.zip
nixos/home-assistant: add lovelaceConfig option
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/home-assistant.nix41
-rw-r--r--nixos/tests/home-assistant.nix11
2 files changed, 49 insertions, 3 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix
index 2e9aa33aeeee..48271eeacc38 100644
--- a/nixos/modules/services/misc/home-assistant.nix
+++ b/nixos/modules/services/misc/home-assistant.nix
@@ -8,7 +8,10 @@ let
   # cfg.config != null can be assumed here
   configFile = pkgs.writeText "configuration.json"
     (builtins.toJSON (if cfg.applyDefaultConfig then
-    (lib.recursiveUpdate defaultConfig cfg.config) else cfg.config));
+    (recursiveUpdate defaultConfig cfg.config) else cfg.config));
+
+  lovelaceConfigFile = pkgs.writeText "ui-lovelace.json"
+    (builtins.toJSON cfg.lovelaceConfig);
 
   availableComponents = pkgs.home-assistant.availableComponents;
 
@@ -45,6 +48,8 @@ let
   defaultConfig = {
     homeassistant.time_zone = config.time.timeZone;
     http.server_port = (toString cfg.port);
+  } // optionalAttrs (cfg.lovelaceConfig != null) {
+    lovelace.mode = "yaml";
   };
 
 in {
@@ -99,6 +104,31 @@ in {
       '';
     };
 
+    lovelaceConfig = mkOption {
+      default = null;
+      type = with types; nullOr attrs;
+      # from https://www.home-assistant.io/lovelace/yaml-mode/
+      example = literalExample ''
+        {
+          title = "My Awesome Home";
+          views = [ {
+            title = "Example";
+            cards = [ {
+              type = "markdown";
+              title = "Lovelace";
+              content = "Welcome to your **Lovelace UI**.";
+            } ];
+          } ];
+        }
+      '';
+      description = ''
+        Your <filename>ui-lovelace.yaml</filename> as a Nix attribute set.
+        Setting this option will automatically add
+        <literal>lovelace.mode = "yaml";</literal> to your <option>config</option>.
+        Beware that setting this option will delete your previous <filename>ui-lovelace.yaml</filename>
+      '';
+    };
+
     package = mkOption {
       default = pkgs.home-assistant;
       defaultText = "pkgs.home-assistant";
@@ -144,11 +174,16 @@ in {
     systemd.services.home-assistant = {
       description = "Home Assistant";
       after = [ "network.target" ];
-      preStart = lib.optionalString (cfg.config != null) ''
-        config=${cfg.configDir}/configuration.yaml
+      preStart = optionalString (cfg.config != null) ''
+        config="${cfg.configDir}/configuration.yaml"
         rm -f $config
         ${pkgs.remarshal}/bin/json2yaml -i ${configFile} -o $config
         chmod 444 $config
+      '' + optionalString (cfg.lovelaceConfig != null) ''
+        config="${cfg.configDir}/ui-lovelace.yaml"
+        rm -f $config
+        ${pkgs.remarshal}/bin/json2yaml -i ${lovelaceConfigFile} -o $config
+        chmod 444 $config
       '';
       serviceConfig = {
         ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix
index 73c1e71eb516..6e8eda30e766 100644
--- a/nixos/tests/home-assistant.nix
+++ b/nixos/tests/home-assistant.nix
@@ -50,6 +50,17 @@ in {
               }
             ];
           };
+          lovelaceConfig = {
+            title = "My Awesome Home";
+            views = [ {
+              title = "Example";
+              cards = [ {
+                type = "markdown";
+                title = "Lovelace";
+                content = "Welcome to your **Lovelace UI**.";
+              } ];
+            } ];
+          };
         };
       };
   };