diff --git a/pkgs/by-name/op/openlist/frontend.nix b/pkgs/by-name/op/openlist/frontend.nix new file mode 100644 index 000000000000..2d01560617af --- /dev/null +++ b/pkgs/by-name/op/openlist/frontend.nix @@ -0,0 +1,62 @@ +{ + lib, + stdenvNoCC, + fetchFromGitHub, + fetchzip, + + nodejs, + pnpm_10, +}: + +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "openlist-frontend"; + version = "4.0.0-rc.4"; + + src = fetchFromGitHub { + owner = "OpenListTeam"; + repo = "OpenList-Frontend"; + tag = "v${finalAttrs.version}"; + hash = "sha256-ZAEaGFOWzL3apV6KXokLV8GGhmp9C38npUhBngdPbq0="; + }; + + i18n = fetchzip { + url = "https://github.com/OpenListTeam/OpenList-Frontend/releases/download/v${finalAttrs.version}/i18n.tar.gz"; + hash = "sha256-AzH1rZFqEH8sovZZfJykvsEmCedEZWigQFHWHl6/PiE="; + stripRoot = false; + }; + + nativeBuildInputs = [ + nodejs + pnpm_10.configHook + ]; + + pnpmDeps = pnpm_10.fetchDeps { + inherit (finalAttrs) pname version src; + hash = "sha256-4NKzy4q6DjWgTL63WBEeDxjAsrgcM5vfHqtmZpS5dug="; + }; + + buildPhase = '' + runHook preBuild + + cp -r ${finalAttrs.i18n}/* src/lang/ + pnpm build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + cp -r dist $out + echo -n "v${finalAttrs.version}" > $out/VERSION + + runHook postInstall + ''; + + meta = { + description = "Frontend of OpenList"; + homepage = "https://github.com/OpenListTeam/OpenList-Frontend"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ moraxyc ]; + }; +}) diff --git a/pkgs/by-name/op/openlist/package.nix b/pkgs/by-name/op/openlist/package.nix new file mode 100644 index 000000000000..d0fa4fdb52f5 --- /dev/null +++ b/pkgs/by-name/op/openlist/package.nix @@ -0,0 +1,103 @@ +{ + lib, + stdenv, + buildGoModule, + fetchFromGitHub, + callPackage, + buildPackages, + installShellFiles, + versionCheckHook, + fuse, +}: + +buildGoModule (finalAttrs: { + pname = "openlist"; + version = "4.0.0"; + + src = fetchFromGitHub { + owner = "OpenListTeam"; + repo = "OpenList"; + tag = "v${finalAttrs.version}"; + hash = "sha256-ir1yOVbf4qP0YUkE0yxOEp92PPMRyHw0VrIH5DQAvZQ="; + # populate values that require us to use git. By doing this in postFetch we + # can delete .git afterwards and maintain better reproducibility of the src. + leaveDotGit = true; + postFetch = '' + cd "$out" + git rev-parse HEAD > $out/COMMIT + # '0000-00-00T00:00:00Z' + date -u -d "@$(git log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH + find "$out" -name .git -print0 | xargs -0 rm -rf + ''; + }; + + frontend = callPackage ./frontend.nix { }; + + proxyVendor = true; + vendorHash = "sha256-e1glgNp5aYl1cEuLdMMLa8sE9lSuiLVdPCX9pek5grE="; + + buildInputs = [ fuse ]; + + tags = [ "jsoniter" ]; + + ldflags = [ + "-s" + "-X \"github.com/OpenListTeam/OpenList/internal/conf.GitAuthor=The OpenList Projects Contributors \"" + "-X github.com/OpenListTeam/OpenList/internal/conf.Version=${finalAttrs.version}" + "-X github.com/OpenListTeam/OpenList/internal/conf.WebVersion=${finalAttrs.frontend.version}" + ]; + + preConfigure = '' + rm -rf public/dist + cp -r ${finalAttrs.frontend} public/dist + ''; + + preBuild = '' + ldflags+=" -X \"github.com/OpenListTeam/OpenList/internal/conf.BuiltAt=$( $out/share/powershell/OpenList.Completion.ps1 + '' + ); + + doInstallCheck = true; + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgram = "${placeholder "out"}/bin/OpenList"; + versionCheckProgramArg = "version"; + + passthru.updateScript = lib.getExe (callPackage ./update.nix { }); + + meta = { + description = "AList Fork to Anti Trust Crisis"; + homepage = "https://github.com/OpenListTeam/OpenList"; + license = lib.licenses.agpl3Only; + maintainers = with lib.maintainers; [ moraxyc ]; + mainProgram = "OpenList"; + }; +}) diff --git a/pkgs/by-name/op/openlist/update.nix b/pkgs/by-name/op/openlist/update.nix new file mode 100644 index 000000000000..fc181992d576 --- /dev/null +++ b/pkgs/by-name/op/openlist/update.nix @@ -0,0 +1,47 @@ +{ + writeShellApplication, + nix, + nix-update, + curl, + common-updater-scripts, + jq, +}: + +writeShellApplication { + name = "update-openlist"; + runtimeInputs = [ + curl + jq + nix + common-updater-scripts + nix-update + ]; + + text = '' + # get old info + oldVersion=$(nix-instantiate --eval --strict -A "openlist.version" | jq -e -r) + + get_latest_release() { + local repo=$1 + curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \ + -s "https://api.github.com/repos/OpenListTeam/$repo/releases/latest" | jq -r ".tag_name" + } + + version=$(get_latest_release "OpenList") + version="''${version#v}" + frontendVersion=$(get_latest_release "OpenList-Frontend") + frontendVersion="''${frontendVersion#v}" + + if [[ "$oldVersion" == "$version" ]]; then + echo "Already up to date!" + exit 0 + fi + + nix-update openlist.frontend --version="$frontendVersion" + update-source-version openlist.frontend "$frontendVersion" \ + --source-key=i18n --ignore-same-version \ + --file=pkgs/by-name/op/openlist/frontend.nix + + nix-update openlist --version="$version" + ''; +}