diff options
author | lassulus <lassulus@lassul.us> | 2022-03-25 13:43:44 +0100 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2022-03-25 13:43:44 +0100 |
commit | b14ccba40fdb228859f93ce349aa48905ecdf835 (patch) | |
tree | 482cfe2cb5781a350baf1047f868dcb7eec69d6f /lass/2configs/hass/pyscript/shell.nix | |
parent | d2556cf5c7d6cc03c12b4ec553e1411c90b3e00e (diff) |
l hass: add pyscript dev environment
Diffstat (limited to 'lass/2configs/hass/pyscript/shell.nix')
-rw-r--r-- | lass/2configs/hass/pyscript/shell.nix | 51 |
1 files changed, 51 insertions, 0 deletions
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 |