nixos-configs/devices/homie/modules/home-assistant/netdaemon/default.nix
matt1432 838df34dfb
All checks were successful
Discord / discord commits (push) Has been skipped
refactor: rename legacyPackages to scopedPackages
2024-11-20 15:17:55 -05:00

103 lines
2.9 KiB
Nix

{
config,
self,
pkgs,
...
}: let
inherit (builtins) attrValues replaceStrings;
inherit (config.sops) secrets;
inherit (pkgs.callPackage ./package.nix {}) netdaemonConfig;
in {
khepri.compositions."netdaemon" = {
networks.netdaemon = {external = true;};
services."netdaemon4" = {
image = import ./images/netdaemon.nix pkgs;
restart = "always";
environmentFiles = [secrets.netdaemon.path];
environment = {
HomeAssistant__Host = "homie.nelim.org";
HomeAssistant__Port = "443";
HomeAssistant__Ssl = "true";
NetDaemon__ApplicationAssembly = "netdaemon.dll";
Logging__LogLevel__Default = "Information"; # use Information/Debug/Trace/Warning/Error
TZ = "America/New_York";
};
volumes = ["${netdaemonConfig}:/data"];
networks = ["netdaemon"];
};
};
services.home-assistant = {
customComponents = attrValues {
inherit
(self.scopedPackages.${pkgs.system}.hass-components)
netdaemon
;
};
};
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_8
];
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 .
rm -r "$FLAKE/.config"
sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix
updateImages .
'';
})
];
}