2024-10-05 12:38:13 -04:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
self,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
2024-10-20 18:49:50 -04:00
|
|
|
inherit (builtins) attrValues replaceStrings;
|
2024-10-05 12:38:13 -04:00
|
|
|
inherit (config.sops) secrets;
|
|
|
|
|
2024-10-21 02:48:43 -04:00
|
|
|
inherit (pkgs.callPackage ./package.nix {}) netdaemonConfig;
|
2024-10-05 12:38:13 -04:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2024-10-21 02:48:43 -04:00
|
|
|
volumes = ["${netdaemonConfig}:/data"];
|
2024-10-05 12:38:13 -04:00
|
|
|
networks = ["netdaemon"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.home-assistant = {
|
2024-10-20 18:49:50 -04:00
|
|
|
customComponents = attrValues {
|
2024-10-05 12:38:13 -04:00
|
|
|
inherit
|
|
|
|
(self.legacyPackages.${pkgs.system}.hass-components)
|
|
|
|
netdaemon
|
|
|
|
;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-20 18:49:50 -04:00
|
|
|
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 [
|
2024-10-05 12:38:13 -04:00
|
|
|
(pkgs.writeShellApplication {
|
2024-10-20 18:49:50 -04:00
|
|
|
name = "bumpNetdaemonDeps";
|
|
|
|
|
2024-10-05 16:17:14 -04:00
|
|
|
runtimeInputs = with pkgs; [
|
|
|
|
dos2unix
|
|
|
|
dotnet-sdk_8
|
|
|
|
];
|
2024-10-20 18:49:50 -04:00
|
|
|
|
2024-10-05 12:38:13 -04:00
|
|
|
text = ''
|
2024-10-05 16:17:14 -04:00
|
|
|
# Install codegen
|
2024-10-10 13:11:11 -04:00
|
|
|
dotnet tool install --create-manifest-if-needed NetDaemon.HassModel.CodeGen --version "$(cat ./.version)"
|
2024-10-05 16:17:14 -04:00
|
|
|
|
|
|
|
# Run it
|
|
|
|
dotnet tool run nd-codegen -token "$(sed 's/HomeAssistant__Token=//' ${secrets.netdaemon.path})"
|
|
|
|
dos2unix ./HomeAssistantGenerated.cs
|
2024-10-05 12:38:13 -04:00
|
|
|
|
2024-10-21 02:48:43 -04:00
|
|
|
# This is to not have it count towards CSharp in the repo
|
|
|
|
mv ./HomeAssistantGenerated.cs ./HomeAssistantGenerated
|
|
|
|
|
2024-10-05 12:38:13 -04:00
|
|
|
# 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
|
|
|
|
|
2024-10-20 18:49:50 -04:00
|
|
|
$(nix build --no-link --print-out-paths --impure --expr "$(cat <<EOF
|
|
|
|
${nixFetchDeps}
|
|
|
|
EOF
|
|
|
|
)") .
|
|
|
|
|
2024-10-05 14:43:43 -04:00
|
|
|
alejandra .
|
2024-10-05 16:17:14 -04:00
|
|
|
rm -r "$FLAKE/.config"
|
2024-10-10 13:11:11 -04:00
|
|
|
|
|
|
|
sed -i "s/finalImageTag = .*/finalImageTag = \"$(cat ./.version)\";/" ./images/netdaemon.nix
|
|
|
|
updateImages .
|
2024-10-05 12:38:13 -04:00
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|