Hi all, I’m looking for advice on how to handle making a derivation.
This also happens to be the first derivation I’m making myself, so any other feedback to the structure is welcome! It’s a bit cobbled together from what I could find in the documentation and on Github
The application I’m trying to build is the Artemis. Compiling this app comes in two steps, the main repo (linked above) and the plugins repo.
I have a working derivation for just the program (no plugins). Which looks like this:
{ lib
, buildDotnetModule
, fetchFromGitHub
, dotnetCorePackages
, copyDesktopItems
, libX11
, libICE
, libSM
, fontconfig
, makeDesktopItem
}:
buildDotnetModule rec {
pname = "artemis";
version = "1.2024.0518.1"; # Latest versions here https://artemis-rgb.com/releases/linux
src = fetchFromGitHub {
owner = "Artemis-RGB";
repo = "Artemis";
rev = "7052ee38b6023a56dc385f277a52c65c6252afa2";
sha256 = "sha256-ShgIAi0vp5q+5TPcLlJfEzfb3afo6atM45ZUFFgFeKU=";
};
projectFile = "src/Artemis.UI.Linux/Artemis.UI.Linux.csproj";
nugetDeps = ./deps.nix;
dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.runtime_8_0;
nativeBuildInputs = [ copyDesktopItems ];
runtimeDeps = [
libX11
libICE
libSM
fontconfig # https://discourse.nixos.org/t/builddotnetmodule-runtimedeps-from-nugetdeps/23565
];
postFixup = ''
mv $out/bin/Artemis.UI.Linux $out/bin/artemis-rgb
export ICON_DIR=$out/share/icons/hicolor/256x256/apps
mkdir -p $ICON_DIR
cp $out/lib/artemis/Icons/256x256/apps/artemis.png $ICON_DIR/Artemis.png
'';
desktopItems = [
(makeDesktopItem {
desktopName = "Artemis";
name = "Artemis";
exec = "artemis-rgb";
icon = "Artemis";
categories = [ "Utility" ];
comment = meta.description;
})
];
meta = with lib; {
homepage = "https://artemis-rgb.com/";
description = "The unified RGB platform";
license = licenses.free; # license is a PolyForm Noncommercial License 1.0.0
mainProgram = "Artemis";
};
}
From the logs I know where the built plugins should go:
[WRN] No built-in plugins found at /nix/store/f0j3igywpzxp5hck4bw7qpppq2yy6m1n-artemis-1.2024.0518.1/lib/artemis/Plugins, skipping CopyBuiltInPlugins
I’ve seen you can use multiple sources by using srcs = [...];
Currently the derivation looks like this. It does not link the plugins to the right directory yet, as I’m trying to figure out what the output is of the build of the plugins:
{ lib
, buildDotnetModule
, fetchFromGitHub
, dotnetCorePackages
, copyDesktopItems
, libX11
, libICE
, libSM
, fontconfig
, makeDesktopItem
}:
buildDotnetModule rec {
pname = "artemis";
version = "1.2024.0518.1"; # Latest versions here https://artemis-rgb.com/releases/linux
sourceRoot = pname;
srcs = [
(fetchFromGitHub {
owner = "Artemis-RGB";
repo = "Artemis";
name = pname;
rev = "7052ee38b6023a56dc385f277a52c65c6252afa2";
sha256 = "sha256-ShgIAi0vp5q+5TPcLlJfEzfb3afo6atM45ZUFFgFeKU=";
})
(fetchFromGitHub {
owner = "Artemis-RGB";
repo = "Artemis.Plugins";
name = "artemis-plugins";
rev = "d80cf160149fff7c9df9564fd06b8c87ecbfdfad";
sha256 = "sha256-S5drT1W/7JNBKQd4Kh3onngAS/+a4sU88rtNJHND88k=";
})
];
projectFile = [
"artemis/src/Artemis.UI.Linux/Artemis.UI.Linux.csproj"
"artemis-plugins/src/Artemis.Plugins.sln"
];
# https://github.com/NixOS/nixpkgs/blob/2e1ed6a2305c3c092265c758c1964ad0cc526ad8/doc/languages-frameworks/dotnet.section.md#generating-and-updating-nuget-dependencies-generating-and-updating-nuget-dependencies
nugetDeps = ./deps.nix;
dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.runtime_8_0;
nativeBuildInputs = [ copyDesktopItems ];
runtimeDeps = [
libX11
libICE
libSM
fontconfig # https://discourse.nixos.org/t/builddotnetmodule-runtimedeps-from-nugetdeps/23565
];
# https://discourse.nixos.org/t/how-to-create-package-with-multiple-sources/9308
preConfigure = ''
mkdir artemis
mv !(artemis) artemis
chmod -R u+w ../artemis-plugins
ln -s ../artemis-plugins .
'';
postFixup = ''
mv $out/bin/Artemis.UI.Linux $out/bin/artemis-rgb
export ICON_DIR=$out/share/icons/hicolor/256x256/apps
mkdir -p $ICON_DIR
cp $out/lib/artemis/Icons/256x256/apps/artemis.png $ICON_DIR/Artemis.png
'';
desktopItems = [
(makeDesktopItem rec {
desktopName = name;
name = "Artemis";
exec = "artemis-rgb";
icon = "Artemis";
type = "Application";
})
];
meta = with lib; {
homepage = "https://artemis-rgb.com/";
description = "The unified RGB platform";
license = licenses.free; # license is a PolyForm Noncommercial License 1.0.0
mainProgram = "artemis";
};
}
The problem I’m running into is the deps.nix. I generated it by running the following in the Artemis.UI.Linux directory.
dotnet restore --packages out
nuget-to-nix out > deps.nix
But this tackles only one of the two projects that I want to compile
Long story short… I’ve tried manually combining the deps.nix of the two projects in projectFile attribute, but I’m still left with build errors. Now I’m considering splitting the two into separate derivations, and linking the plugins project with the projectReferences attribute somehow. But I’m not sure what the correct approach would be here.
Should I split the project into two, or keep them together?
And if I keep them together, how do I keep the deps.nix updateable and working?