diff --git a/apps/update-sources/default.nix b/apps/update-sources/default.nix index 7aaecfcd..b390a147 100644 --- a/apps/update-sources/default.nix +++ b/apps/update-sources/default.nix @@ -23,6 +23,7 @@ buildApp { nodejs_latest prefetch-npm-deps (callPackage ../../modules/docker/updateImage.nix {}) + (callPackage ../../configurations/homie/modules/home-assistant/netdaemon/update.nix {}) ]; meta.description = '' diff --git a/apps/update-sources/src/app.ts b/apps/update-sources/src/app.ts index dadeb6d7..af0a2dee 100644 --- a/apps/update-sources/src/app.ts +++ b/apps/update-sources/src/app.ts @@ -8,6 +8,7 @@ import updateCaddyPlugins from './caddy'; import updateDocker from './docker'; import updateFirefoxAddons from '././firefox'; import updateFlakeInputs from './flake'; +import updateNetDaemon from './netdaemon'; import runNixUpdate from './nix-update'; import updateNodeModules from './node-modules'; import updateVuetorrent from './vuetorrent'; @@ -56,6 +57,10 @@ const main = async() => { console.log(runNixUpdate('scopedPackages', 'lovelace-components', 'material-rounded-theme')); } + if (args['netdaemon']) { + console.log(updateNetDaemon()); + } + if (args['node'] || args['node_modules']) { console.log((await updateNodeModules()) ?? 'No updates'); } @@ -97,6 +102,11 @@ const main = async() => { console.log(dockerOutput ?? 'No updates'); + const netdaemonOutput = updateNetDaemon(); + + console.log(netdaemonOutput ?? 'No updates'); + + const nodeModulesOutput = await updateNodeModules(); console.log(nodeModulesOutput ?? 'No updates'); @@ -171,6 +181,9 @@ const main = async() => { if (caddyPluginsOutput) { output.push(`Caddy Plugins:\n${indentOutput(caddyPluginsOutput)}\n`); } + if (netdaemonOutput) { + output.push(`NetDaemon:\n${indentOutput(netdaemonOutput)}\n`); + } if (nixUpdateOutputs.length > 0) { output.push(`nix-update executions:\n${indentOutput(nixUpdateOutputs.join('\n'))}\n`); } diff --git a/apps/update-sources/src/netdaemon.ts b/apps/update-sources/src/netdaemon.ts new file mode 100644 index 00000000..0067c750 --- /dev/null +++ b/apps/update-sources/src/netdaemon.ts @@ -0,0 +1,32 @@ +import { readFileSync, writeFileSync } from 'node:fs'; +import { spawnSync } from 'node:child_process'; +import { styleText } from 'node:util'; + + +/* Constants */ +const FLAKE = process.env.FLAKE; + +export default (): string | null => { + console.log(styleText(['magenta'], '\nUpdating NetDaemon:\n')); + + const FOLDER = `${FLAKE}/configurations/homie/modules/home-assistant/netdaemon`; + + const OLD_VERSION = readFileSync(`${FOLDER}/.version`).toString().replace('\n', ''); + + const VERSION = JSON.parse(spawnSync('curl', + ['-s', 'https://api.github.com/repos/net-daemon/netdaemon/releases/latest'], + { shell: true }).stdout.toString()).tag_name.replace('v', ''); + + if (OLD_VERSION !== VERSION) { + writeFileSync(`${FOLDER}/.version`, `${VERSION}\n`); + + spawnSync('bumpNetdaemonDeps', [], { + cwd: FOLDER, + stdio: 'inherit', + }); + + return `NetDaemon: ${OLD_VERSION} -> ${VERSION}\n`; + } + + return null; +}; diff --git a/configurations/homie/modules/home-assistant/netdaemon/default.nix b/configurations/homie/modules/home-assistant/netdaemon/default.nix index 9570798a..6ef4703e 100644 --- a/configurations/homie/modules/home-assistant/netdaemon/default.nix +++ b/configurations/homie/modules/home-assistant/netdaemon/default.nix @@ -1,10 +1,9 @@ { config, - self, pkgs, ... }: let - inherit (builtins) attrValues replaceStrings; + inherit (builtins) attrValues; inherit (config.sops) secrets; inherit (pkgs.callPackage ./package.nix {}) netdaemonConfig; @@ -40,64 +39,7 @@ in { }; }; - environment.systemPackages = let - nixFetchDeps = - replaceStrings [(toString self)] ["$FLAKE"] - #nix - '' - let - config = (builtins.getFlake ("$FLAKE")).nixosConfigurations.homie; - inherit (config) pkgs; - - netdaemonConfig = pkgs.callPackage ${toString ./package.nix} {}; - in - netdaemonConfig.fetch-deps - ''; - in [ - (pkgs.writeShellApplication { - name = "bumpNetdaemonDeps"; - - runtimeInputs = with pkgs; [ - dos2unix - dotnet-sdk_9 - ]; - - text = '' - # Install codegen - dotnet tool install --create-manifest-if-needed NetDaemon.HassModel.CodeGen --version "$(cat ./.version)" - - # Run it - dotnet tool run nd-codegen -token "$(sed 's/HomeAssistant__Token=//' ${secrets.netdaemon.path})" - dos2unix ./HomeAssistantGenerated.cs - - # This is to not have it count towards CSharp in the repo - mv ./HomeAssistantGenerated.cs ./HomeAssistantGenerated - - # Update all nugets to latest versions - regex='PackageReference Include="([^"]*)" Version="([^"]*)"' - - find . -type f -name '*.csproj' | while read -r file; do - # Extract unique package names from the .csproj file - packages=$(grep -oP "$regex" "$file" | sed -E 's/.*Include="([^"]*)".*/\1/' | sort -u) - - # Loop through each package and update - for package in $packages; do - echo -e "\033[35mUpdate $file package: $package\033[0m" - dotnet add "$file" package "$package" - done - done - - $(nix build --no-link --print-out-paths --impure --expr "$(cat <<EOF - ${nixFetchDeps} - EOF - )") . - - alejandra -q . - rm -r "$FLAKE/.config" - - sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix - updateImages . - ''; - }) + environment.systemPackages = [ + (pkgs.callPackage ./update.nix {}) ]; } diff --git a/configurations/homie/modules/home-assistant/netdaemon/update.nix b/configurations/homie/modules/home-assistant/netdaemon/update.nix new file mode 100644 index 00000000..0941d59a --- /dev/null +++ b/configurations/homie/modules/home-assistant/netdaemon/update.nix @@ -0,0 +1,73 @@ +{ + # nix build inputs + writeShellApplication, + # deps + alejandra, + dos2unix, + dotnet-sdk_9, + findutils, + gnused, + nix, + ... +}: let + nixFetchDeps = + #nix + '' + let + config = (builtins.getFlake ("$FLAKE")).nixosConfigurations.homie; + inherit (config) pkgs; + + netdaemonConfig = pkgs.callPackage ${toString ./package.nix} {}; + in + netdaemonConfig.fetch-deps + ''; +in + writeShellApplication { + name = "bumpNetdaemonDeps"; + + runtimeInputs = [ + alejandra + dos2unix + dotnet-sdk_9 + findutils + gnused + nix + ]; + + text = '' + # Install codegen + dotnet tool install --create-manifest-if-needed NetDaemon.HassModel.CodeGen --version "$(cat ./.version)" + + # Run it + dotnet tool run nd-codegen -token "$(sed 's/HomeAssistant__Token=//' /run/secrets/netdaemon)" + dos2unix ./HomeAssistantGenerated.cs + + # This is to not have it count towards CSharp in the repo + mv ./HomeAssistantGenerated.cs ./HomeAssistantGenerated + + # Update all nugets to latest versions + regex='PackageReference Include="([^"]*)" Version="([^"]*)"' + + find . -type f -name '*.csproj' | while read -r file; do + # Extract unique package names from the .csproj file + packages=$(grep -oP "$regex" "$file" | sed -E 's/.*Include="([^"]*)".*/\1/' | sort -u) + + # Loop through each package and update + for package in $packages; do + echo -e "\033[35mUpdate $file package: $package\033[0m" + dotnet add "$file" package "$package" + done + done + + $(nix build --no-link --print-out-paths --impure --expr "$(cat <<EOF + ${nixFetchDeps} + EOF + )") . + + alejandra -q . + rm -r "$FLAKE/.config" + + sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix + updateImages . + ''; + }