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
|
||||
35
package/fetchJellyfinPlugin/package.nix
Normal file
35
package/fetchJellyfinPlugin/package.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
newScope,
|
||||
}@args:
|
||||
let
|
||||
fetchJellyfinPlugin = (lib.makeScope newScope (_: args)).callPackage package;
|
||||
|
||||
package =
|
||||
{
|
||||
name,
|
||||
fetchFromGitHub,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
self = fetchJellyfinPlugin args;
|
||||
|
||||
extraArgs = lib.attrsets.removeAttrs args (builtins.attrNames (lib.functionArgs package));
|
||||
owner = args.owner or "jellyfin";
|
||||
repo = args.repo or "jellyfin-plugin-${args.name}";
|
||||
name = builtins.concatStringsSep "-" (
|
||||
[ repo ] ++ lib.optional (args ? version) args.version ++ [ "source" ]
|
||||
);
|
||||
|
||||
in
|
||||
fetchFromGitHub (
|
||||
{
|
||||
inherit owner repo name;
|
||||
passthru.override = self.override;
|
||||
}
|
||||
// extraArgs
|
||||
);
|
||||
|
||||
in
|
||||
fetchJellyfinPlugin
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
let
|
||||
capitalize =
|
||||
upper: str:
|
||||
let
|
||||
length = builtins.stringLength str;
|
||||
head = builtins.substring 0 1 str;
|
||||
tail = builtins.substring 1 length str;
|
||||
in "${upper head}${tail}";
|
||||
|
||||
buildJellyfinPlugin = {
|
||||
lib,
|
||||
name,
|
||||
version,
|
||||
|
||||
dotnetCorePackages,
|
||||
buildDotnetModule,
|
||||
fetchJellyfinPlugin,
|
||||
jellyfin,
|
||||
jprm,
|
||||
unzip,
|
||||
|
||||
...
|
||||
}@params: let
|
||||
project = params.project or "Jellyfin.Plugin.${capitalize lib.strings.toUpper name}";
|
||||
src = params.src or (fetchJellyfinPlugin { name = name; tag = "v${builtins.head (builtins.splitVersion version)}"; hash = params.hash or ""; });
|
||||
|
||||
extraArgs = lib.attrsets.removeAttrs params (builtins.attrNames (lib.functionArgs buildJellyfinPlugin));
|
||||
|
||||
pluginLibraries = extraArgs.pluginLibraries or lib.attrsets.foldlAttrs (
|
||||
acc: name: value:
|
||||
acc ++ lib.optional (value == "directory") name
|
||||
) [ ] (builtins.readDir "${src}/src");
|
||||
|
||||
args = {
|
||||
pname = "jellyfin-plugin-${name}";
|
||||
version = version;
|
||||
description = "${name} plugin for jellyfin";
|
||||
projectFile = "src/${project}/${project}.csproj";
|
||||
dotnet-sdk = dotnetCorePackages.sdk_9_0;
|
||||
dotnet-runtime = jellyfin.dotnet-runtime;
|
||||
dontDotnetBuild = true;
|
||||
dontDontnetInstall = true;
|
||||
} // extraArgs // {
|
||||
inherit src;
|
||||
meta = { inherit (jellyfin.meta) license homepage;
|
||||
maintainer = [ "nonapode@fbs42.ddnss.de" ];
|
||||
} // (extraArgs.meta or {});
|
||||
|
||||
nativeBuildInputs = (extraArgs.nativeBuildInputs or []) ++ [
|
||||
jprm
|
||||
unzip
|
||||
];
|
||||
outputs = (extraArgs.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
|
||||
'' + (extraArgs.prePatch or "");
|
||||
|
||||
postInstall =
|
||||
let
|
||||
dlls = builtins.map (name: "${name}.dll") pluginLibraries;
|
||||
in
|
||||
''
|
||||
tmp_output_dir="$(mktemp -d)"
|
||||
jprm plugin build . --output="''${tmp_output_dir}" --version="${version}" --dotnet-configuration="''${dotnetBuildType-Release}"
|
||||
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 args;
|
||||
in buildJellyfinPlugin
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
original,
|
||||
fetchFromGitHub,
|
||||
|
||||
gnused,
|
||||
jprm,
|
||||
unzip,
|
||||
dotnetCorePackages,
|
||||
buildDotnetModule,
|
||||
...
|
||||
}:
|
||||
let
|
||||
context = pkgs // {
|
||||
inherit callPackage fetchJellyfinPlugin buildJellyfinPlugin jellyfin;
|
||||
};
|
||||
callPackage = lib.callPackageWith context;
|
||||
|
||||
fetchJellyfinPlugin = callPackage ./fetch-plugin.nix;
|
||||
buildJellyfinPlugin = callPackage ./build-plugin.nix;
|
||||
|
||||
jellyfin = original.overrideAttrs (
|
||||
final: { passthru ? {}, ... }@prev:
|
||||
assert !prev ? "plugin";
|
||||
{
|
||||
passthru = passthru // {
|
||||
plugin =
|
||||
base: callPackage base;
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
jellyfin
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
let
|
||||
fetchJellyfinPlugin = {
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
runCommandLocal,
|
||||
...
|
||||
}@args: let
|
||||
owner = args.owner or "jellyfin";
|
||||
repo = args.repo or "jellyfin-plugin-${args.name}";
|
||||
|
||||
extraArgs = lib.attrsets.removeAttrs args (builtins.attrNames (lib.functionArgs fetchJellyfinPlugin));
|
||||
git = fetchFromGitHub ({
|
||||
inherit owner repo;
|
||||
} // extraArgs);
|
||||
in git;
|
||||
in fetchJellyfinPlugin
|
||||
23
package/jellyfin/package.nix
Normal file
23
package/jellyfin/package.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
jellyfin,
|
||||
fetchFromGitHub,
|
||||
|
||||
gnused,
|
||||
jprm,
|
||||
unzip,
|
||||
dotnetCorePackages,
|
||||
buildDotnetModule,
|
||||
...
|
||||
}: jellyfin.overrideAttrs (
|
||||
final: { passthru ? {}, ...}@prev: {
|
||||
passthru = passthru // {
|
||||
plugins = lib.attrsets.foldlAttrs
|
||||
(acc: name: value: assert (builtins.trace name true); if lib.strings.hasPrefix "jellyfin-plugin-" name
|
||||
then acc // {
|
||||
${lib.strings.substring (builtins.stringLength "jellyfin-plugin-") (builtins.stringLength name) name} = value;
|
||||
} else acc) {} pkgs;
|
||||
};
|
||||
}
|
||||
)
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
jellyfin,
|
||||
plugin,
|
||||
fetchFromGitHub,
|
||||
buildDotnetModule,
|
||||
gnused,
|
||||
jprm,
|
||||
unzip,
|
||||
dotnetCorePackages,
|
||||
callPackage,
|
||||
}:
|
||||
let
|
||||
drv =
|
||||
args:
|
||||
let
|
||||
meta = from: { inherit (from) license homepage description; };
|
||||
|
||||
capitalize =
|
||||
upper: str:
|
||||
let
|
||||
length = builtins.stringLength str;
|
||||
head = builtins.substring 0 1 str;
|
||||
tail = builtins.substring 1 length str;
|
||||
in
|
||||
"${upper head}${tail}";
|
||||
|
||||
helper = {
|
||||
base = plugin;
|
||||
name = builtins.baseNameOf info.base;
|
||||
self = info;
|
||||
owner = "jellyfin";
|
||||
repo = "jellyfin-plugin-${info.name}";
|
||||
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
||||
rev = "v${info.version}";
|
||||
description = "${info.name} plugin for jellyfin";
|
||||
homepage = jellyfin.meta.homepage;
|
||||
license = jellyfin.meta.license;
|
||||
mkPlugin = info: result: buildDotnetModule result;
|
||||
inherit jellyfin;
|
||||
ignore = builtins.attrNames helper ++ [
|
||||
"override"
|
||||
"overrideAttrs"
|
||||
"overrideDerivation"
|
||||
];
|
||||
};
|
||||
|
||||
defaults = {
|
||||
pname = "jellyfin-plugin-${info.name}";
|
||||
nugetDeps =
|
||||
let
|
||||
options = builtins.filter builtins.pathExists [
|
||||
"${info.base}/deps.json"
|
||||
];
|
||||
in
|
||||
assert options != [ ];
|
||||
builtins.head options;
|
||||
pluginLibraries = lib.attrsets.foldlAttrs (
|
||||
acc: name: value:
|
||||
acc ++ lib.optional (value == "directory") name
|
||||
) [ ] (builtins.readDir ("${info.src}/src"));
|
||||
dotnet-sdk = dotnetCorePackages.sdk_9_0;
|
||||
dotnet-runtime = jellyfin.dotnet-runtime;
|
||||
dontDotnetBuild = true;
|
||||
dontDotnetInstall = true;
|
||||
project = "Jellyfin.Plugin.${capitalize lib.strings.toUpper info.name}";
|
||||
prePatch = ''
|
||||
sed --sandbox --separate \
|
||||
-e 's:\(PackageReference Include="Jellyfin\..*" Version="\)[^"]\+":\1${info.jellyfin.version}":' \
|
||||
-e 's:<\(enerateDocumentationFile\|TreatWarningsAsErrors\)>true</\1>:<\1>false</\1>:' \
|
||||
-i ${
|
||||
lib.strings.escapeShellArgs (builtins.map (lib: "src/${lib}/${lib}.csproj") info.pluginLibraries)
|
||||
}
|
||||
|
||||
success=true
|
||||
for x in ${
|
||||
lib.strings.escapeShellArgs (builtins.map (lib: "src/${lib}/${lib}.csproj") info.pluginLibraries)
|
||||
}
|
||||
do
|
||||
diff -q $src/$x $x 2>/dev/null || continue
|
||||
printf >&2 'no change: %s\n' $x
|
||||
success=false
|
||||
done
|
||||
$success || exit 1
|
||||
'';
|
||||
projectFile = "src/${info.project}/${info.project}.csproj";
|
||||
src = fetchFromGitHub {
|
||||
owner = info.owner;
|
||||
repo = info.repo;
|
||||
inherit (info) rev hash;
|
||||
};
|
||||
nativeBuildInputs = [
|
||||
gnused
|
||||
jprm
|
||||
unzip
|
||||
];
|
||||
patches =
|
||||
lib.optional (builtins.pathExists "${info.base}.patch") "${info.base}.patch"
|
||||
++ lib.optionals (builtins.pathExists info.base) (
|
||||
lib.attrsets.foldlAttrs (
|
||||
acc: name: type:
|
||||
acc
|
||||
++ lib.optional (type == "regular" && lib.strings.hasSuffix ".patch" name) "${info.base}/${name}"
|
||||
) [ ] (builtins.readDir info.base)
|
||||
);
|
||||
outputs = [
|
||||
"out"
|
||||
"zip"
|
||||
];
|
||||
postInstall =
|
||||
let
|
||||
dlls = builtins.map (name: "${name}.dll") info.pluginLibraries;
|
||||
in
|
||||
''
|
||||
tmp_output_dir="$(mktemp -d)"
|
||||
jprm plugin build . --output="''${tmp_output_dir}" --version="${info.version}" --dotnet-configuration="''${dotnetBuildType-Release}"
|
||||
mv "''${tmp_output_dir}/${info.name}_${info.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
|
||||
'';
|
||||
meta = meta jellyfin.meta // meta info;
|
||||
};
|
||||
info = helper // defaults // {
|
||||
inherit (callPackage plugin ({ inherit info; } // args))
|
||||
version hash rev;
|
||||
};
|
||||
in
|
||||
info.mkPlugin info (lib.attrsets.removeAttrs info info.ignore);
|
||||
|
||||
functor =
|
||||
args:
|
||||
(drv args).overrideAttrs (
|
||||
final: { passthru ? {}, ... }@prev: {
|
||||
passthru = passthru // {
|
||||
in-version =
|
||||
{
|
||||
version,
|
||||
rev ? null,
|
||||
hash ? null,
|
||||
}@args':
|
||||
callPackage functor (
|
||||
builtins.removeAttrs args [
|
||||
"version"
|
||||
"rev"
|
||||
"hash"
|
||||
]
|
||||
// args'
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
#lib.trivial.mirrorFunctionArgs plugin functor
|
||||
drv
|
||||
|
|
@ -21,7 +21,7 @@ python3Packages.buildPythonApplication {
|
|||
src = fetchFromGitHub {
|
||||
owner = "oddstr13";
|
||||
repo = "jellyfin-plugin-repository-manager";
|
||||
tag = "v${version}";
|
||||
rev = "v${version}";
|
||||
hash = hash;
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue