This repository has no description
1.3 kB
51 lines
1{ pkgs ? import <nixpkgs> {} }: let
2
3 hass_host = "styx.r";
4 hass_token = builtins.readFile ./hass_token;
5
6 mach-nix = import (builtins.fetchGit {
7 url = "https://github.com/DavHau/mach-nix/";
8 ref = "refs/tags/3.4.0";
9 }) {
10 pkgs = pkgs;
11 };
12 pyenv = mach-nix.mkPython {
13 requirements = ''
14 hass_pyscript_kernel
15 '';
16 };
17 jupyter = import (builtins.fetchGit {
18 url = https://github.com/tweag/jupyterWith;
19 ref = "master";
20 }) {};
21
22 pyscriptKernel = {
23 spec = pkgs.runCommand "pyscript" {} ''
24 mkdir -p $out/kernels/pyscript
25 cp ${kernel_json} $out/kernels/pyscript/kernel.json
26 cp ${pyscript_conf} $out/kernels/pyscript/pyscript.conf
27 '';
28 runtimePackages = [ pyenv ];
29 };
30
31 kernel_json = pkgs.writeText "kernel.json" (builtins.toJSON {
32 argv = [
33 "${pyenv}/bin/python3" "-m" "hass_pyscript_kernel"
34 "-f" "{connection_file}"
35 ];
36 display_name = "hass_pyscript";
37 language = "python";
38 });
39
40 pyscript_conf = pkgs.writeText "pyscript.conf" ''
41 [homeassistant]
42 hass_host = ${hass_host}
43 hass_url = http://''${hass_host}:8123
44 hass_token = ${hass_token}
45 '';
46
47 jupyterEnvironment = jupyter.jupyterlabWith {
48 kernels = [ pyscriptKernel ];
49 };
50
51in jupyterEnvironment.env