From 554e70d040d873c12309f2e7fc1375d1bfc9c09e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 27 Dec 2024 06:26:39 -0500 Subject: [PATCH] fix(hass): use js module for material you theme --- apps/update-sources/src/app.ts | 9 ++++++ .../homie/modules/home-assistant/frontend.nix | 2 ++ .../lovelace-components/default.nix | 1 + .../material-rounded-theme/default.nix | 31 +++++++++++++++++++ .../material-rounded-theme/update.sh | 13 ++++++++ 5 files changed, 56 insertions(+) create mode 100644 scopedPackages/lovelace-components/material-rounded-theme/default.nix create mode 100644 scopedPackages/lovelace-components/material-rounded-theme/update.sh diff --git a/apps/update-sources/src/app.ts b/apps/update-sources/src/app.ts index 83d99af0..1717903b 100644 --- a/apps/update-sources/src/app.ts +++ b/apps/update-sources/src/app.ts @@ -48,6 +48,12 @@ const main = async() => { )); } + if (args['m'] || args['material-rounded-theme']) { + console.log(updateCustomPackage( + 'scopedPackages.x86_64-linux.lovelace-components.material-rounded-theme', + )); + } + if (args['s'] || args['some-sass-language-server']) { console.log(updateCustomPackage('some-sass-language-server')); } @@ -91,6 +97,9 @@ const main = async() => { console.log(updateCustomPackage( 'scopedPackages.x86_64-linux.lovelace-components.custom-sidebar', )); + console.log(updateCustomPackage( + 'scopedPackages.x86_64-linux.lovelace-components.material-rounded-theme', + )); console.log(updateCustomPackage('some-sass-language-server')); // nix-update executions diff --git a/configurations/homie/modules/home-assistant/frontend.nix b/configurations/homie/modules/home-assistant/frontend.nix index 1a6b558c..9f8bc929 100644 --- a/configurations/homie/modules/home-assistant/frontend.nix +++ b/configurations/homie/modules/home-assistant/frontend.nix @@ -99,6 +99,7 @@ in { inherit (self.scopedPackages.${pkgs.system}.lovelace-components) custom-sidebar + material-rounded-theme ; }; @@ -108,6 +109,7 @@ in { "card-mod" "light-entity-card" "custom-sidebar-yaml" + "material-rounded-theme" ]; }; diff --git a/scopedPackages/lovelace-components/default.nix b/scopedPackages/lovelace-components/default.nix index ca60ed98..b9883108 100644 --- a/scopedPackages/lovelace-components/default.nix +++ b/scopedPackages/lovelace-components/default.nix @@ -7,4 +7,5 @@ lib.makeScope pkgs.newScope (lovelace: let callPackage = file: lovelace.callPackage file ({} // inputs); in { custom-sidebar = callPackage ./custom-sidebar; + material-rounded-theme = callPackage ./material-rounded-theme; }) diff --git a/scopedPackages/lovelace-components/material-rounded-theme/default.nix b/scopedPackages/lovelace-components/material-rounded-theme/default.nix new file mode 100644 index 00000000..ea3dbf1b --- /dev/null +++ b/scopedPackages/lovelace-components/material-rounded-theme/default.nix @@ -0,0 +1,31 @@ +{ + buildNpmPackage, + concatTextFile, + material-rounded-theme-src, + ... +}: let + package = builtins.fromJSON (builtins.readFile "${material-rounded-theme-src}/package.json"); +in + buildNpmPackage { + pname = package.name; + inherit (package) version; + + src = material-rounded-theme-src; + postPatch = '' + substituteInPlace ./webpack.config.js --replace-fail "git branch --show-current" "echo main" + ''; + + npmDepsHash = "sha256-INI/9N4IutwVc56w5iMzLgPtW6KQMBWwVBGN0fTxNz8="; + + installPhase = '' + mkdir $out + cp ./dist/* $out + ''; + + passthru.update = concatTextFile { + name = "update"; + files = [./update.sh]; + executable = true; + destination = "/bin/update"; + }; + } diff --git a/scopedPackages/lovelace-components/material-rounded-theme/update.sh b/scopedPackages/lovelace-components/material-rounded-theme/update.sh new file mode 100644 index 00000000..29a9b49d --- /dev/null +++ b/scopedPackages/lovelace-components/material-rounded-theme/update.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +file="$FLAKE/scopedPackages/lovelace-components/material-rounded-theme/default.nix" +old_hash="$(sed -n 's/.*hash = "\(.*\)";/\1/p' "$file")" + +sed -i "s/hash = .*/hash = \"\";/" "$file" +npm_hash="$(nix build "$FLAKE#scopedPackages.x86_64-linux.lovelace-components.material-rounded-theme" |& sed -n 's/.*got: *//p')" + +if [[ "$npm_hash" != "$old_hash" ]]; then + sed -i "s#hash = .*#hash = \"$npm_hash\";#" "$file" +else + sed -i "s#hash = .*#hash = \"$old_hash\";#" "$file" +fi