summaryrefslogtreecommitdiffstats
path: root/lass/2configs/hass
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2022-04-27 22:07:43 +0200
committermakefu <github@syntax-fehler.de>2022-04-27 22:07:43 +0200
commitbdd36774f5e0854553b13433ef85260c6c074b3e (patch)
tree656d0a2755c098a9e69c373a8c4f39fa82cb8d1e /lass/2configs/hass
parentc3adb252afa29f0140f29c935201cfbb100b5697 (diff)
parent92d5eacd6d9e530c4d1ea0dec2652417b0fde78a (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/2configs/hass')
-rw-r--r--lass/2configs/hass/default.nix1
-rw-r--r--lass/2configs/hass/pyscript/.gitignore1
-rw-r--r--lass/2configs/hass/pyscript/default.nix26
-rw-r--r--lass/2configs/hass/pyscript/shell.nix51
4 files changed, 79 insertions, 0 deletions
diff --git a/lass/2configs/hass/default.nix b/lass/2configs/hass/default.nix
index 8f93e0cec..cc8189f51 100644
--- a/lass/2configs/hass/default.nix
+++ b/lass/2configs/hass/default.nix
@@ -19,6 +19,7 @@ let
in {
imports = [
+ ./pyscript
./zigbee.nix
./rooms/bett.nix
./rooms/essen.nix
diff --git a/lass/2configs/hass/pyscript/.gitignore b/lass/2configs/hass/pyscript/.gitignore
new file mode 100644
index 000000000..282debf56
--- /dev/null
+++ b/lass/2configs/hass/pyscript/.gitignore
@@ -0,0 +1 @@
+hass_token
diff --git a/lass/2configs/hass/pyscript/default.nix b/lass/2configs/hass/pyscript/default.nix
new file mode 100644
index 000000000..c56967e4b
--- /dev/null
+++ b/lass/2configs/hass/pyscript/default.nix
@@ -0,0 +1,26 @@
+{ config, lib, pkgs, ... }:
+{
+ systemd.tmpfiles.rules = [
+ "L+ /var/lib/hass/custom_components/pyscript - - - - ${pkgs.fetchzip {
+ url = "https://github.com/custom-components/pyscript/releases/download/1.3.2/hass-custom-pyscript.zip";
+ sha256 = "0cqdjj46s5xp4mqxb0ic790jm1xp3z0zr2n9f7bsfl5zpvdshl8z";
+ stripRoot = false;
+ }}"
+ ];
+
+ services.home-assistant = {
+ package = (pkgs.home-assistant.overrideAttrs (old: {
+ doInstallCheck = false;
+ })).override {
+ extraPackages = pp: [ pp.croniter ];
+ };
+ config.pyscript = {
+ allow_all_imports = true;
+ hass_is_global = true;
+ };
+ };
+
+ networking.firewall.interfaces.retiolum.allowedTCPPortRanges = [
+ { from = 50321; to = 50341; } # for ipython interactive debugging
+ ];
+}
diff --git a/lass/2configs/hass/pyscript/shell.nix b/lass/2configs/hass/pyscript/shell.nix
new file mode 100644
index 000000000..3cfac0275
--- /dev/null
+++ b/lass/2configs/hass/pyscript/shell.nix
@@ -0,0 +1,51 @@
+{ pkgs ? import <nixpkgs> {} }: let
+
+ hass_host = "styx.r";
+ hass_token = builtins.readFile ./hass_token;
+
+ mach-nix = import (builtins.fetchGit {
+ url = "https://github.com/DavHau/mach-nix/";
+ ref = "refs/tags/3.4.0";
+ }) {
+ pkgs = pkgs;
+ };
+ pyenv = mach-nix.mkPython {
+ requirements = ''
+ hass_pyscript_kernel
+ '';
+ };
+ jupyter = import (builtins.fetchGit {
+ url = https://github.com/tweag/jupyterWith;
+ ref = "master";
+ }) {};
+
+ pyscriptKernel = {
+ spec = pkgs.runCommand "pyscript" {} ''
+ mkdir -p $out/kernels/pyscript
+ cp ${kernel_json} $out/kernels/pyscript/kernel.json
+ cp ${pyscript_conf} $out/kernels/pyscript/pyscript.conf
+ '';
+ runtimePackages = [ pyenv ];
+ };
+
+ kernel_json = pkgs.writeText "kernel.json" (builtins.toJSON {
+ argv = [
+ "${pyenv}/bin/python3" "-m" "hass_pyscript_kernel"
+ "-f" "{connection_file}"
+ ];
+ display_name = "hass_pyscript";
+ language = "python";
+ });
+
+ pyscript_conf = pkgs.writeText "pyscript.conf" ''
+ [homeassistant]
+ hass_host = ${hass_host}
+ hass_url = http://''${hass_host}:8123
+ hass_token = ${hass_token}
+ '';
+
+ jupyterEnvironment = jupyter.jupyterlabWith {
+ kernels = [ pyscriptKernel ];
+ };
+
+in jupyterEnvironment.env