Files
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

230 lines
7.2 KiB
Nix

{
_7zz,
buildDotnetModule,
callPackage,
desktop-file-utils,
dotnetCorePackages,
fetchFromGitHub,
imagemagick,
lib,
xdg-utils,
pname ? "nexusmods-app",
}:
let
# From https://nexus-mods.github.io/NexusMods.App/developers/Contributing/#for-package-maintainers
constants = [
# Tell the app it is a distro package; affects wording in update prompts
"INSTALLATION_METHOD_PACKAGE_MANAGER"
# Don't include upstream's 7zz binary; we use the nixpkgs version
"NEXUSMODS_APP_USE_SYSTEM_EXTRACTOR"
];
in
buildDotnetModule (finalAttrs: {
inherit pname;
version = "0.17.2";
src = fetchFromGitHub {
owner = "Nexus-Mods";
repo = "NexusMods.App";
tag = "v${finalAttrs.version}";
hash = "sha256-2B5n1yN42birMJ1YaUU/KjzhHIJTv8nwrupc0ULc8Hc=";
fetchSubmodules = true;
};
gameHashes = callPackage ./game-hashes { };
enableParallelBuilding = false;
# If the whole solution is published, there seems to be a race condition where
# it will sometimes publish the wrong version of a dependent assembly, for
# example: Microsoft.Extensions.Hosting.dll 6.0.0 instead of 8.0.0.
# https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/7.0/solution-level-output-no-longer-valid
# TODO: do something about this in buildDotnetModule
projectFile = "src/NexusMods.App/NexusMods.App.csproj";
testProjectFile = "NexusMods.App.sln";
nativeCheckInputs = [ _7zz ];
nativeBuildInputs = [
imagemagick # For resizing SVG icon in postInstall
];
nugetDeps = ./deps.json;
mapNuGetDependencies = true;
dotnet-sdk = dotnetCorePackages.sdk_9_0;
dotnet-runtime = dotnetCorePackages.runtime_9_0;
postPatch = ''
# for some reason these tests fail (intermittently?) with a zero timestamp
touch tests/NexusMods.UI.Tests/WorkspaceSystem/*.verified.png
# Specify a fixed date to improve build reproducibility
echo "1970-01-01T00:00:00Z" >buildDate.txt
substituteInPlace src/NexusMods.Sdk/NexusMods.Sdk.csproj \
--replace-fail '$(BaseIntermediateOutputPath)buildDate.txt' "$(realpath buildDate.txt)"
# Use a pinned version of the game hashes db
substituteInPlace src/NexusMods.Games.FileHashes/NexusMods.Games.FileHashes.csproj \
--replace-fail '$(BaseIntermediateOutputPath)games_hashes_db.zip' "$gameHashes"
# Use a vendored version of the nexus API's games.json data
substituteInPlace src/NexusMods.Networking.NexusWebApi/NexusMods.Networking.NexusWebApi.csproj \
--replace-fail '$(BaseIntermediateOutputPath)games.json' ${./vendored/games.json}
'';
makeWrapperArgs = [
"--prefix PATH : ${lib.makeBinPath finalAttrs.runtimeInputs}"
];
postInstall = ''
${lib.strings.toShellVars {
inherit (finalAttrs.meta) mainProgram;
INSTALL_EXEC = "\${INSTALL_EXEC}";
INSTALL_TRYEXEC = "\${INSTALL_TRYEXEC}";
}}
# Desktop entry
# As per #308324, use mainProgram from PATH, instead of $out/bin/NexusMods.App
install -D -m 444 -t $out/share/applications src/NexusMods.App/com.nexusmods.app.desktop
substituteInPlace $out/share/applications/com.nexusmods.app.desktop \
--replace-fail "$INSTALL_EXEC" "$mainProgram" \
--replace-fail "$INSTALL_TRYEXEC" "$mainProgram"
# AppStream metadata
install -D -m 444 -t $out/share/metainfo src/NexusMods.App/com.nexusmods.app.metainfo.xml
# Icon
icon=src/NexusMods.App/icon.svg
install -D -m 444 -T $icon $out/share/icons/hicolor/scalable/apps/com.nexusmods.app.svg
# Bitmap icons
for i in 16 24 48 64 96 128 256 512; do
size="$i"x"$i"
dir="$out/share/icons/hicolor/$size/apps"
mkdir -p $dir
magick -background none $icon -resize $size $dir/com.nexusmods.app.png
done
'';
runtimeInputs = [
_7zz
desktop-file-utils
xdg-utils
];
executables = [ "NexusMods.App" ];
dotnetBuildFlags = [
# From https://github.com/Nexus-Mods/NexusMods.App/blob/v0.7.0/src/NexusMods.App/app.pupnet.conf#L38
"--property:Version=${finalAttrs.version}"
"--property:TieredCompilation=true"
"--property:PublishReadyToRun=true"
"--property:DefineConstants=${lib.strings.concatStringsSep "%3B" constants}"
];
# Avoid running `dotnet test` in the main package:
# - The test-suite is slow
# - Some tests fail intermittently
# - The package is often uncached; especially the unfree variant
# - We can enable tests in a `passthru.tests` override
doCheck = false;
dotnetTestFlags = [
"--environment=USER=nobody"
"--property:Version=${finalAttrs.version}"
"--property:DefineConstants=${lib.strings.concatStringsSep "%3B" constants}"
];
testFilters = [
"Category!=Disabled"
"FlakeyTest!=True"
"RequiresNetworking!=True"
];
disabledTests = [
# Fails attempting to fetch SMAPI version data from github:
# https://github.com/erri120/smapi-versions/raw/main/data/game-smapi-versions.json
"NexusMods.Games.StardewValley.Tests.SMAPIGameVersionDiagnosticEmitterTests.Test_TryGetLastSupportedSMAPIVersion"
]
++ lib.optionals (!_7zz.meta.unfree) [
"NexusMods.Games.FOMOD.Tests.FomodXmlInstallerTests.InstallsFilesSimple_UsingRar"
];
doInstallCheck = true;
nativeInstallCheckInputs = [
desktop-file-utils
];
# Upstream use ${...} templates in the desktop entry, so assert that we haven't missed any
# See https://github.com/NixOS/nixpkgs/issues/421241
installCheckPhase = ''
runHook preInstallCheck
echo 'Checking for issues in $out/share/applications/com.nexusmods.app.desktop'
(
cd $out/share/applications
desktop-file-validate com.nexusmods.app.desktop
if grep '\$' com.nexusmods.app.desktop \
--with-filename --line-number
then
echo 'error: unexpected "$"'
exit 1
fi
) &>/dev/stderr
runHook postInstallCheck
'';
passthru.tests = {
# Build the package and run `dotnet test`
app = finalAttrs.finalPackage.overrideAttrs {
pname = "${finalAttrs.pname}-tested";
doCheck = true;
};
};
passthru.updateScript = ./update.sh;
meta = {
mainProgram = "NexusMods.App";
homepage = "https://github.com/Nexus-Mods/NexusMods.App";
changelog = "https://github.com/Nexus-Mods/NexusMods.App/releases/tag/${finalAttrs.src.tag}";
license = [ lib.licenses.gpl3Plus ];
maintainers = with lib.maintainers; [
l0b0
MattSturgeon
];
platforms = lib.platforms.linux;
description = "Game mod installer, creator and manager";
longDescription = ''
A mod installer, creator and manager for all your popular games.
Currently experimental and undergoing active development,
new releases may include breaking changes!
${
if _7zz.meta.unfree then
''
This "unfree" variant includes support for mods packaged as RAR archives.
''
else
''
It is strongly recommended that you use the "unfree" variant of this package,
which provides support for mods packaged as RAR archives.
You can also enable unrar support manually, by overriding the `_7zz` used:
```nix
pkgs.nexusmods-app.override {
_7zz = pkgs._7zz-rar;
}
```
''
}
'';
};
})