summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorFrederik Rietdijk <freddyrietdijk@fridh.nl>2018-02-01 08:44:48 +0000
committerGitHub <noreply@github.com>2018-02-01 08:44:48 +0000
commitd30735f889c49e66c2a69c40a782eece24d4eb2c (patch)
tree5fe486f227c55d769b3eaf3066cda9b1ab865653 /nixos/modules
parentc7885866e4e6284af4cdc1b7803512a5d707c4a3 (diff)
parent0604c078a8a61faaf179908551dc6ffe82f75b8b (diff)
downloadnixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar.gz
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar.bz2
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar.lz
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar.xz
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.tar.zst
nixlib-d30735f889c49e66c2a69c40a782eece24d4eb2c.zip
Merge pull request #34188 from dotlambda/home-assistant
home-assistant: init at 0.62.1
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/home-assistant.nix90
3 files changed, 93 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index 415be580e974..28ed10a5ece6 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -302,6 +302,7 @@
       kodi = 283;
       restya-board = 284;
       mighttpd2 = 285;
+      hass = 286;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
@@ -572,6 +573,7 @@
       kodi = 283;
       restya-board = 284;
       mighttpd2 = 285;
+      hass = 286;
 
       # When adding a gid, make sure it doesn't match an existing
       # uid. Users and groups with the same name should have equal
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 1942cca23d6e..2ec8b28c3fc4 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -315,6 +315,7 @@
   ./services/misc/gogs.nix
   ./services/misc/gollum.nix
   ./services/misc/gpsd.nix
+  ./services/misc/home-assistant.nix
   ./services/misc/ihaskell.nix
   ./services/misc/irkerd.nix
   ./services/misc/jackett.nix
diff --git a/nixos/modules/services/misc/home-assistant.nix b/nixos/modules/services/misc/home-assistant.nix
new file mode 100644
index 000000000000..bc463d3e670c
--- /dev/null
+++ b/nixos/modules/services/misc/home-assistant.nix
@@ -0,0 +1,90 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.home-assistant;
+
+  configFile = pkgs.writeText "configuration.yaml" (builtins.toJSON cfg.config);
+in {
+  meta.maintainers = with maintainers; [ dotlambda ];
+
+  options.services.home-assistant = {
+    enable = mkEnableOption "Home Assistant";
+
+    configDir = mkOption {
+      default = "/var/lib/hass";
+      type = types.path;
+      description = "The config directory, where your <filename>configuration.yaml</filename> is located.";
+    };
+
+    config = mkOption {
+      default = null;
+      type = with types; nullOr attrs;
+      example = literalExample ''
+        {
+          homeassistant = {
+            name = "Home";
+            time_zone = "UTC";
+          };
+          frontend = { };
+          http = { };
+        }
+      '';
+      description = ''
+        Your <filename>configuration.yaml</filename> as a Nix attribute set.
+        Beware that setting this option will delete your previous <filename>configuration.yaml</filename>.
+      '';
+    };
+
+    package = mkOption {
+      default = pkgs.home-assistant;
+      defaultText = "pkgs.home-assistant";
+      type = types.package;
+      example = literalExample ''
+        pkgs.home-assistant.override {
+          extraPackages = ps: with ps; [ colorlog ];
+        }
+      '';
+      description = ''
+        Home Assistant package to use.
+        Most Home Assistant components require additional dependencies,
+        which are best specified by overriding <literal>pkgs.home-assistant</literal>.
+        You can find the dependencies by searching for failed imports in your log or by looking at this list:
+        <link xlink:href="https://github.com/home-assistant/home-assistant/blob/master/requirements_all.txt"/>
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.home-assistant = {
+      description = "Home Assistant";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" ];
+      preStart = lib.optionalString (cfg.config != null) ''
+        rm -f ${cfg.configDir}/configuration.yaml
+        ln -s ${configFile} ${cfg.configDir}/configuration.yaml
+      '';
+      serviceConfig = {
+        ExecStart = ''
+          ${cfg.package}/bin/hass --config "${cfg.configDir}"
+        '';
+        User = "hass";
+        Group = "hass";
+        Restart = "on-failure";
+        ProtectSystem = "strict";
+        ReadWritePaths = "${cfg.configDir}";
+        PrivateTmp = true;
+      };
+    };
+
+    users.extraUsers.hass = {
+      home = cfg.configDir;
+      createHome = true;
+      group = "hass";
+      uid = config.ids.uids.hass;
+    };
+
+    users.extraGroups.hass.gid = config.ids.gids.hass;
+  };
+}