wip
This commit is contained in:
parent
4c2f85ad62
commit
794925acb2
15 changed files with 516 additions and 529 deletions
146
package/buildJellyfinPlugin/package.nix
Normal file
146
package/buildJellyfinPlugin/package.nix
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
{
|
||||
lib,
|
||||
newScope,
|
||||
|
||||
dotnetCorePackages,
|
||||
buildDotnetModule,
|
||||
fetchJellyfinPlugin,
|
||||
jellyfin,
|
||||
jprm,
|
||||
unzip,
|
||||
}@args:
|
||||
let
|
||||
buildJellyfinPlugin = (lib.makeScope newScope (_: args)).callPackage package;
|
||||
|
||||
capitalize =
|
||||
str:
|
||||
let
|
||||
length = builtins.stringLength str;
|
||||
head = builtins.substring 0 1 str;
|
||||
tail = builtins.substring 1 length str;
|
||||
in
|
||||
"${lib.strings.toUpper head}${tail}";
|
||||
|
||||
package =
|
||||
{
|
||||
lib,
|
||||
name,
|
||||
version,
|
||||
|
||||
dotnetCorePackages,
|
||||
buildDotnetModule,
|
||||
fetchJellyfinPlugin,
|
||||
jellyfin,
|
||||
jprm,
|
||||
unzip,
|
||||
|
||||
...
|
||||
}@params:
|
||||
let
|
||||
self = buildJellyfinPlugin params;
|
||||
|
||||
project = params.project or "Jellyfin.Plugin.${capitalize name}";
|
||||
|
||||
pluginLibraries = params.pluginLibraries or lib.attrsets.foldlAttrs (
|
||||
acc: name: value:
|
||||
acc ++ lib.optional (value == "directory") name
|
||||
) [ ] (builtins.readDir "${self.src}/src");
|
||||
dlls = builtins.map (name: "${name}.dll") pluginLibraries;
|
||||
|
||||
defaults = {
|
||||
pname = "jellyfin-plugin-${name}";
|
||||
version = version;
|
||||
description = "${name} plugin for ${jellyfin.name}";
|
||||
projectFile = "src/${project}/${project}.csproj";
|
||||
dotnet-sdk = dotnetCorePackages.sdk_9_0;
|
||||
dotnet-runtime = jellyfin.dotnet-runtime;
|
||||
dontDotnetBuild = true;
|
||||
dontDotnetInstall = true;
|
||||
src = fetchJellyfinPlugin {
|
||||
inherit name version;
|
||||
tag = "v${builtins.head (builtins.splitVersion version)}";
|
||||
hash = params.hash or "";
|
||||
};
|
||||
};
|
||||
|
||||
override =
|
||||
(lib.attrsets.removeAttrs params (
|
||||
builtins.attrNames (lib.functionArgs package)
|
||||
++ [
|
||||
"project"
|
||||
"pluginLibraries"
|
||||
]
|
||||
))
|
||||
// {
|
||||
inherit jellyfin;
|
||||
jellyfinPluginFiles = (params.jellyfinPluginFiles or []) ++ dlls;
|
||||
meta = {
|
||||
inherit (jellyfin.meta) license homepage;
|
||||
maintaner = [ "nonapode@fbs42.ddnss.de" ];
|
||||
}
|
||||
// (params.meta or { });
|
||||
|
||||
nativeBuildInputs = (params.nativeBuildInputs or [ ]) ++ [
|
||||
jprm
|
||||
unzip
|
||||
];
|
||||
outputs = (params.outputs or [ ]) ++ [
|
||||
"out"
|
||||
"zip"
|
||||
];
|
||||
prePatch = ''
|
||||
sed --sandbox --separate \
|
||||
-e 's:\(PackageReference Include="Jellyfin\..*" Version="\)[^"]\+":\1${jellyfin.version}":' \
|
||||
-e 's:<\(enerateDocumentationFile\|TreatWarningsAsErrors\)>true</\1>:<\1>false</\1>:' \
|
||||
-i ${lib.strings.escapeShellArgs (builtins.map (lib: "src/${lib}/${lib}.csproj") pluginLibraries)}
|
||||
|
||||
success=true
|
||||
for x in ${
|
||||
lib.strings.escapeShellArgs (builtins.map (lib: "src/${lib}/${lib}.csproj") pluginLibraries)
|
||||
}
|
||||
do
|
||||
diff -q $src/$x $x 2>/dev/null || continue
|
||||
printf >&2 'no change: %s\n' $x
|
||||
success=false
|
||||
done
|
||||
$success || exit 1
|
||||
''
|
||||
+ (params.prePatch or "");
|
||||
|
||||
postInstall = (params.postInstall or "") + ''
|
||||
tmp_output_dir="$(mktemp -d)"
|
||||
jprm plugin build . --output="''${tmp_output_dir}" --version="${version}" --dotnet-configuration="''${dotnetBuildType-Release}"
|
||||
env
|
||||
mv "''${tmp_output_dir}/${name}_${version}.zip" $zip
|
||||
mkdir -p $out
|
||||
unzip $zip -d $out
|
||||
|
||||
success=true
|
||||
for file in $out/*;
|
||||
do
|
||||
case "''${file##*/}" in
|
||||
meta.json)
|
||||
;;
|
||||
${builtins.concatStringsSep "|" (builtins.map lib.strings.escapeShellArg dlls)}) ;;
|
||||
*)
|
||||
printf 'unknown file: %s\n' ''${file@Q}
|
||||
success=false
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for file in meta.json ${lib.strings.escapeShellArgs dlls}
|
||||
do
|
||||
[[ -f "$out/$file" ]] && continue
|
||||
printf 'missing file: %s\n' ''${file@Q}
|
||||
success=false
|
||||
done
|
||||
|
||||
$success || exit 42
|
||||
'';
|
||||
};
|
||||
|
||||
in
|
||||
buildDotnetModule (defaults // override);
|
||||
in
|
||||
buildJellyfinPlugin
|
||||
Loading…
Add table
Add a link
Reference in a new issue