git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/home-assistant: add configWritable option
commitf85453f060b4756a3d55c2d3a6563be19f41dfe6 authorRobert Schütz <robert.schuetz@stud.uni-heidelberg.de> dateSun 3 Feb 2019, 12:45 (8 years ago) parentf908f6c
2 files changed+33−5
nixos/modules/services/misc/home-assistant.nix+29−3 nixos/tests/home-assistant.nix+4−2
nixos/modules/services/misc/home-assistant.nix+29−3
@@ -110,6 +110,17 @@ in {
110110 '';
111111 };
112112
113+ configWritable = mkOption {
114+ default = false;
115+ type = types.bool;
116+ description = ''
117+ Whether to make <filename>configuration.yaml</filename> writable.
118+ This only has an effect if <option>config</option> is set.
119+ This will allow you to edit it from Home Assistant's web interface.
120+ However, bear in mind that it will be overwritten at every start of the service.
121+ '';
122+ };
123+
113124 lovelaceConfig = mkOption {
114125 default = null;
115126 type = with types; nullOr attrs;
@@ -135,6 +146,17 @@ in {
135146 '';
136147 };
137148
149+ lovelaceConfigWritable = mkOption {
150+ default = false;
151+ type = types.bool;
152+ description = ''
153+ Whether to make <filename>ui-lovelace.yaml</filename> writable.
154+ This only has an effect if <option>lovelaceConfig</option> is set.
155+ This will allow you to edit it from Home Assistant's web interface.
156+ However, bear in mind that it will be overwritten at every start of the service.
157+ '';
158+ };
159+
138160 package = mkOption {
139161 default = pkgs.home-assistant;
140162 defaultText = "pkgs.home-assistant";
@@ -180,13 +202,17 @@ in {
180202 systemd.services.home-assistant = {
181203 description = "Home Assistant";
182204 after = [ "network.target" ];
183− preStart = optionalString (cfg.config != null) ''
205+ preStart = optionalString (cfg.config != null) (if cfg.configWritable then ''
206+ cp --no-preserve=mode ${configFile} "${cfg.configDir}/configuration.yaml"
207+ '' else ''
184208 rm -f "${cfg.configDir}/configuration.yaml"
185209 ln -s ${configFile} "${cfg.configDir}/configuration.yaml"
186− '' + optionalString (cfg.lovelaceConfig != null) ''
210+ '') + optionalString (cfg.lovelaceConfig != null) (if cfg.lovelaceConfigWritable then ''
211+ cp --no-preserve=mode ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
212+ '' else ''
187213 rm -f "${cfg.configDir}/ui-lovelace.yaml"
188214 ln -s ${lovelaceConfigFile} "${cfg.configDir}/ui-lovelace.yaml"
189− '';
215+ '');
190216 serviceConfig = {
191217 ExecStart = "${package}/bin/hass --config '${cfg.configDir}'";
192218 User = "hass";
nixos/tests/home-assistant.nix+4−2
@@ -61,6 +61,7 @@ in {
6161 } ];
6262 } ];
6363 };
64+ lovelaceConfigWritable = true;
6465 };
6566 };
6667 };
@@ -70,9 +71,10 @@ in {
7071 $hass->waitForUnit("home-assistant.service");
7172
7273 # The config is specified using a Nix attribute set,
73− # but then converted from JSON to YAML
74+ # converted from JSON to YAML, and linked to the config dir
7475 $hass->succeed("test -L ${configDir}/configuration.yaml");
75− $hass->succeed("test -L ${configDir}/ui-lovelace.yaml");
76+ # The lovelace config is copied because lovelaceConfigWritable = true
77+ $hass->succeed("test -f ${configDir}/ui-lovelace.yaml");
7678
7779 # Check that Home Assistant's web interface and API can be reached
7880 $hass->waitForOpenPort(8123);