6.NUR/lib/repoSource.nix
Colin 25031d3d69
fix update-nur-combined action for non-github/non-gitlab repos (#1035)
these were failing with `error: hash mismatch in fixed-output derivation`
messages, because `fetchgit` wasn't actually being passed any sha256.

see for example this run:
<https://github.com/nix-community/nur-combined/actions/runs/19902521411/job/57050064087#step:7:753>

fixes update for at least the following NUR repos:
- Pupyrinth (https://git.gliroid.com/Pupyrinth/nur-packages)
- alanpearce (https://git.alanpearce.eu/nix-packages)
- colinsane (https://git.uninsane.org/colin/nix-files)
- shelvacu (https://git.uninsane.org/shelvacu/nix-stuff)
- wolfangaukang (https://codeberg.org/wolfangaukang/nix-agordoj.git)
2025-12-03 14:20:25 -08:00

62 lines
1.4 KiB
Nix

{
name,
attr,
fetchgit,
fetchzip,
lib,
manifest,
lockedRevisions,
}:
let
parseGitlabUrl =
url:
with builtins;
let
parts = lib.splitString "/" url;
len = length parts;
in
{
domain = elemAt parts 2;
# Allow for deeper hierarchies than owner/repo (GL has groups and subgroups)
path = lib.drop 3 parts;
};
revision = lockedRevisions.${name};
submodules = attr.submodules or false;
type = attr.type or null;
localPath = ../repos + "/${name}";
in
if lib.pathExists localPath then
localPath
else if lib.hasPrefix "https://github.com" attr.url && !submodules then
fetchzip {
url = "${attr.url}/archive/${revision.rev}.zip";
inherit (revision) sha256;
}
else if (lib.hasPrefix "https://gitlab.com" attr.url || type == "gitlab") && !submodules then
let
gitlab = parseGitlabUrl attr.url;
escapedPath = builtins.concatStringsSep "%2F" gitlab.path;
in
fetchzip {
url = "https://${gitlab.domain}/api/v4/projects/${escapedPath}/repository/archive.tar.gz?sha=${revision.rev}";
inherit (revision) sha256;
}
else
fetchgit (
{
inherit (attr) url;
inherit (revision) rev;
}
// (
if fetchgit == builtins.fetchGit or null then
{ inherit submodules; }
else
{
inherit (revision) sha256;
fetchSubmodules = submodules;
}
)
)