summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorRobert Schütz <robert.schuetz@stud.uni-heidelberg.de>2019-02-03 12:45:52 +0100
committerRobert Schütz <robert.schuetz@stud.uni-heidelberg.de>2019-02-03 13:08:11 +0100
commitf85453f060b4756a3d55c2d3a6563be19f41dfe6 (patch)
treeb331a7d98c10abe04073dc41789321ca6264326f /nixos
parentf908f6c9827288cdd0dda84d28738d300377a8b2 (diff)
downloadnixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar.gz
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar.bz2
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar.lz
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar.xz
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.tar.zst
nixpkgs-f85453f060b4756a3d55c2d3a6563be19f41dfe6.zip
nixos/home-assistant: add configWritable option
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/misc/home-assistant.nix32
-rw-r--r--nixos/tests/home-assistant.nix6
2 files changed, 33 insertions, 5 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix
index 628dd7c39b1..4eabda1d418 100644
--- a/nixos/modules/services/misc/home-assistant.nix
+++ b/nixos/modules/services/misc/home-assistant.nix
@@ -110,6 +110,17 @@ in {
       '';
     };
 
+    configWritable = mkOption {
+      default = false;
+      type = types.bool;
+      description = ''
+        Whether to make <filename>configuration.yaml</filename> writable.
+        This only has an effect if <option>config</option> is set.
+        This will allow you to edit it from Home Assistant's web interface.
+        However, bear in mind that it will be overwritten at every start of the service.
+      '';
+    };
+
     lovelaceConfig = mkOption {
       default = null;
       type = with types; nullOr attrs;
@@ -135,6 +146,17 @@ in {
       '';
     };
 
+    lovelaceConfigWritable = mkOption {
+      default = false;
+      type = types.bool;
+      description = ''
+        Whether to make <filename>ui-lovelace.yaml</filename> writable.
+        This only has an effect if <option>lovelaceConfig</option> is set.
+        This will allow you to edit it from Home Assistant's web interface.
+        However, bear in mind that it will be overwritten at every start of the service.
+      '';
+    };
+
     package = mkOption {
       default = pkgs.home-assistant;
       defaultText = "pkgs.home-assistant";
@@ -180,13 +202,17 @@ in {
     systemd.services.home-assistant = {
       description = "Home Assistant";
       after = [ "network.target" ];
-      preStart = optionalString (cfg.config != null) ''
+      preStart = optionalString (cfg.config != null) (if cfg.configWritable then ''
+        cp --no-preserve=mode ${configFile} "${cfg.configDir}/configuration.yaml"
+      '' else ''
         rm -f "${cfg.configDir}/configuration.yaml"
         ln -s ${configFile} "${cfg.configDir}/configuration.yaml"
-      '' + optionalString (cfg.lovelaceConfig != null) ''
+      '') + optionalString (cfg.lovelaceConfig != null) (if cfg.lovelaceConfigWritable then ''
+        cp --no-preserve=mode ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
+      '' else ''
         rm -f "${cfg.configDir}/ui-lovelace.yaml"
         ln -s ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
-      '';
+      '');
       serviceConfig = {
         ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
         User = "hass";
diff --git a/nixos/tests/home-assistant.nix b/nixos/tests/home-assistant.nix
index 9e97ed4c47e..00a0e82fedc 100644
--- a/nixos/tests/home-assistant.nix
+++ b/nixos/tests/home-assistant.nix
@@ -61,6 +61,7 @@ in {
               } ];
             } ];
           };
+          lovelaceConfigWritable = true;
         };
       };
   };
@@ -70,9 +71,10 @@ in {
     $hass->waitForUnit("home-assistant.service");
 
     # The config is specified using a Nix attribute set,
-    # but then converted from JSON to YAML
+    # converted from JSON to YAML, and linked to the config dir
     $hass->succeed("test -L ${configDir}/configuration.yaml");
-    $hass->succeed("test -L ${configDir}/ui-lovelace.yaml");
+    # The lovelace config is copied because lovelaceConfigWritable = true
+    $hass->succeed("test -f ${configDir}/ui-lovelace.yaml");
 
     # Check that Home Assistant's web interface and API can be reached
     $hass->waitForOpenPort(8123);