From e47f6ea0d728b7ab8d2d5203994bb0e905dd73b1 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 16 Oct 2024 20:12:23 -0400 Subject: [PATCH] feat(hass): setup custom-sidebar --- .../homie/modules/home-assistant/frontend.nix | 86 +++++++++++++++--- flake.lock | Bin 56618 -> 57131 bytes flake.nix | Bin 10977 -> 11114 bytes inputs.nix | 13 ++- legacyPackages/default.nix | 3 +- legacyPackages/dracula/default.nix | 8 +- legacyPackages/hass-components/default.nix | 8 +- .../custom-sidebar/default.nix | 34 +++++++ .../lovelace-components/default.nix | 11 +++ .../material-symbols/default.nix | 15 +++ 10 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 legacyPackages/lovelace-components/custom-sidebar/default.nix create mode 100644 legacyPackages/lovelace-components/default.nix create mode 100644 legacyPackages/lovelace-components/material-symbols/default.nix diff --git a/devices/homie/modules/home-assistant/frontend.nix b/devices/homie/modules/home-assistant/frontend.nix index 523628d9..0b428802 100644 --- a/devices/homie/modules/home-assistant/frontend.nix +++ b/devices/homie/modules/home-assistant/frontend.nix @@ -2,8 +2,8 @@ caule-themes-src, dracul-ha-src, material-rounded-theme-src, - material-symbols-src, pkgs, + self, ... }: let inherit (pkgs.writers) writeYAML; @@ -13,6 +13,70 @@ in { "themes/caule.yaml".source = "${caule-themes-src}/themes/caule-themes-pack-1.yaml"; "themes/dracul-ha.yaml".source = "${dracul-ha-src}/themes/dracul-ha.yaml"; "themes/material_rounded.yaml".source = "${material-rounded-theme-src}/themes/material_rounded.yaml"; + + "www/sidebar-config.yaml".source = writeYAML "sidebar" { + id = "my-sidebar"; + + order = [ + # Top + { + item = "overview"; + order = 1; + } + { + match = "href"; + item = "calendar"; + order = 2; + } + { + match = "href"; + item = "todo"; + order = 3; + } + + # Bottom + { + bottom = true; + item = "esphome"; + order = 5; + } + { + bottom = true; + item = "logbook"; + order = 7; + } + { + bottom = true; + icon = "mdi:tools"; + item = "developer tools"; + name = "Developer tools"; + order = 9; + } + { + bottom = true; + item = "settings"; + order = 11; + } + + # Hidden + { + hide = true; + item = "map"; + } + { + hide = true; + item = "energy"; + } + { + hide = true; + item = "history"; + } + { + hide = true; + item = "media"; + } + ]; + }; }; customLovelaceModules = builtins.attrValues { @@ -21,21 +85,19 @@ in { card-mod ; - material-symbols = pkgs.stdenv.mkDerivation { - pname = "material-symbols"; - version = "0.0.0+${material-symbols-src.shortRev}"; - src = material-symbols-src; - phases = ["installPhase"]; - installPhase = '' - mkdir $out - cp $src/dist/material-symbols.js $out - ''; - }; + inherit + (self.legacyPackages.${pkgs.system}.lovelace-components) + material-symbols + custom-sidebar + ; }; config.frontend = { themes = "!include_dir_merge_named themes"; - extra_module_url = ["/local/nixos-lovelace-modules/card-mod.js"]; + extra_module_url = map (p: "/local/nixos-lovelace-modules/${p}.js") [ + "card-mod" + "custom-sidebar-yaml" + ]; }; config.template = [ diff --git a/flake.lock b/flake.lock index 5f7a8c9c26d4b90d8172de750522f4b7909623ea..c8273ae89bf153ca6d63baff620e2b4e921013f1 100644 GIT binary patch delta 245 zcmZ3ri+S}v<_%FIe95K7CHc9!#hEFoNr^?1FUtC`SsEA{7@AC;$Rekm66}}m>YJVx zk!w_C8txXEnjcl1m~9#1>}e3`S{|C~8{lYZmf>aLZZb}PE1L(G&D^zO-f2lPBl%lOfomMG%`uFFfdC?Ge|W~Gd49bNuB&q n)CbKlbeAsFGT0m?(lSK_#gZc3;-X|FD+MJ~(aq;p#Fzj8`5ac) delta 19 bcmZ3zk9pND<_%FIo7Kfyrfj~y%Etr%SM3P4 diff --git a/flake.nix b/flake.nix index d056936a34b97a5974332425d72bfa16c5cd6788..7cf04b91cc8bf569b50a9805b69069133470e85a 100644 GIT binary patch delta 77 zcmaDD`YLQg4GUj#X>mz@u5NK=N@`MK(PTq5UCq>-JhBC<_Gd diff --git a/inputs.nix b/inputs.nix index c3650208..52892bed 100644 --- a/inputs.nix +++ b/inputs.nix @@ -180,12 +180,12 @@ let srcs = [ # Home-assistant + ## Components { name = "extended-ollama-conversation-src"; owner = "TheNimaj"; repo = "extended_ollama_conversation"; } - { owner = "m50"; repo = "ha-fallback-conversation"; @@ -199,6 +199,7 @@ let owner = "net-daemon"; repo = "integration"; } + ### SpotifyPlus { name = "spotifyplus-src"; owner = "thlucas1"; @@ -214,12 +215,16 @@ let owner = "thlucas1"; repo = "SpotifyWebApiPython"; } + ### + ## Voice { name = "wakewords-src"; owner = "fwartner"; repo = "home-assistant-wakewords-collection"; } + + ## Themes { owner = "berti24"; repo = "dracul-ha"; @@ -233,10 +238,16 @@ let owner = "Nerwyn"; repo = "material-rounded-theme"; } + + ## Lovelace Components { owner = "beecho01"; repo = "material-symbols"; } + { + owner = "elchininet"; + repo = "custom-sidebar"; + } # Nvim plugins { diff --git a/legacyPackages/default.nix b/legacyPackages/default.nix index f4099ea3..4c16de72 100644 --- a/legacyPackages/default.nix +++ b/legacyPackages/default.nix @@ -11,7 +11,8 @@ (pkgs.callPackage file ({inherit mkVersion;} // inputs)); in { dracula = mkScope ./dracula; - hass-components = mkScope ./hass-components; firefoxAddons = mkScope ./firefox-addons; + hass-components = mkScope ./hass-components; + lovelace-components = mkScope ./lovelace-components; mpvScripts = mkScope ./mpv-scripts; } diff --git a/legacyPackages/dracula/default.nix b/legacyPackages/dracula/default.nix index a6a2c0c9..9f7d4c3a 100644 --- a/legacyPackages/dracula/default.nix +++ b/legacyPackages/dracula/default.nix @@ -1,5 +1,9 @@ -{pkgs, ...} @ inputs: -pkgs.lib.makeScope pkgs.newScope (drac: { +{ + lib, + pkgs, + ... +} @ inputs: +lib.makeScope pkgs.newScope (drac: { bat = drac.callPackage ./bat.nix { inherit (inputs) bat-theme-src mkVersion; }; diff --git a/legacyPackages/hass-components/default.nix b/legacyPackages/hass-components/default.nix index 4c88eefb..a00307ca 100644 --- a/legacyPackages/hass-components/default.nix +++ b/legacyPackages/hass-components/default.nix @@ -1,5 +1,9 @@ -{pkgs, ...} @ inputs: -pkgs.lib.makeScope pkgs.newScope (hass: let +{ + lib, + pkgs, + ... +} @ inputs: +lib.makeScope pkgs.newScope (hass: let buildHassComponent = file: extraArgs: hass.callPackage file (inputs // extraArgs // {}); in { diff --git a/legacyPackages/lovelace-components/custom-sidebar/default.nix b/legacyPackages/lovelace-components/custom-sidebar/default.nix new file mode 100644 index 00000000..9aa1d631 --- /dev/null +++ b/legacyPackages/lovelace-components/custom-sidebar/default.nix @@ -0,0 +1,34 @@ +{ + custom-sidebar-src, + nodejs, + pnpm, + stdenv, + ... +}: let + package = builtins.fromJSON (builtins.readFile "${custom-sidebar-src}/package.json"); +in + stdenv.mkDerivation (finalAttrs: { + pname = "custom-sidebar"; + inherit (package) version; + + src = custom-sidebar-src; + + nativeBuildInputs = [ + nodejs + pnpm.configHook + ]; + + buildPhase = '' + npm run build + ''; + + installPhase = '' + mkdir $out + cp ./dist/* $out + ''; + + pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) pname version src; + hash = "sha256-oERAaN/0uyImDRlxJIdKutFh3jYFJQh2KAeM1LXBpjU="; + }; + }) diff --git a/legacyPackages/lovelace-components/default.nix b/legacyPackages/lovelace-components/default.nix new file mode 100644 index 00000000..a99e2541 --- /dev/null +++ b/legacyPackages/lovelace-components/default.nix @@ -0,0 +1,11 @@ +{ + lib, + pkgs, + ... +} @ inputs: +lib.makeScope pkgs.newScope (lovelace: let + callPackage = file: lovelace.callPackage file ({} // inputs); +in { + custom-sidebar = callPackage ./custom-sidebar; + material-symbols = callPackage ./material-symbols; +}) diff --git a/legacyPackages/lovelace-components/material-symbols/default.nix b/legacyPackages/lovelace-components/material-symbols/default.nix new file mode 100644 index 00000000..0f769c2a --- /dev/null +++ b/legacyPackages/lovelace-components/material-symbols/default.nix @@ -0,0 +1,15 @@ +{ + material-symbols-src, + stdenv, + ... +}: +stdenv.mkDerivation { + pname = "material-symbols"; + version = "0.0.0+${material-symbols-src.shortRev}"; + src = material-symbols-src; + phases = ["installPhase"]; + installPhase = '' + mkdir $out + cp $src/dist/material-symbols.js $out + ''; +}