about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-04-21 22:33:32 +0800
committerPeter Hoeg <peter@hoeg.com>2018-04-23 16:53:13 +0800
commitb886faa6b60eb67bc9c09484673998924083c12b (patch)
tree5fbbf80d7e453ce0431e0e12a229ef80e5970fb4
parent4cd88807d8434efdc3fb666767098e2b3ee0b812 (diff)
downloadnixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar.gz
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar.bz2
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar.lz
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar.xz
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.tar.zst
nixlib-b886faa6b60eb67bc9c09484673998924083c12b.zip
home-assistant: use remarshal to convert configuration to YAML
HA doesn't mind the configuration being JSON instead of YAML but since YAML is
the official language, use that as it allows users to easily exchange config
data with other parties in the community.
-rw-r--r--nixos/modules/services/misc/home-assistant.nix6
-rw-r--r--nixos/tests/home-assistant.nix6
2 files changed, 7 insertions, 5 deletions
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix
index 07b14bb67643..b9a972967792 100644
--- a/nixos/modules/services/misc/home-assistant.nix
+++ b/nixos/modules/services/misc/home-assistant.nix
@@ -134,8 +134,10 @@ in {
       description = "Home Assistant";
       after = [ "network.target" ];
       preStart = lib.optionalString (cfg.config != null) ''
-        rm -f ${cfg.configDir}/configuration.yaml
-        ln -s ${configFile} ${cfg.configDir}/configuration.yaml
+        config=${cfg.configDir}/configuration.yaml
+        rm -f $config
+        ${pkgs.remarshal}/bin/json2yaml -i ${configFile} -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 2e45dc78471f..4ebccb7ab868 100644
--- a/nixos/tests/home-assistant.nix
+++ b/nixos/tests/home-assistant.nix
@@ -51,9 +51,9 @@ in {
     startAll;
     $hass->waitForUnit("home-assistant.service");
 
-    # Since config is specified using a Nix attribute set,
-    # configuration.yaml is a link to the Nix store
-    $hass->succeed("test -L ${configDir}/configuration.yaml");
+    # The config is specified using a Nix attribute set,
+    # but then converted from JSON to YAML
+    $hass->succeed("test -f ${configDir}/configuration.yaml");
 
     # Check that Home Assistant's web interface and API can be reached
     $hass->waitForOpenPort(8123);