diff --git a/pkgs/build-support/fetch9front/default.nix b/pkgs/build-support/fetch9front/default.nix new file mode 100644 index 000000000000..677fee1decd7 --- /dev/null +++ b/pkgs/build-support/fetch9front/default.nix @@ -0,0 +1,36 @@ +{ fetchgit, fetchzip, lib }: + +lib.makeOverridable ( + { owner + , repo + , rev + , domain ? "git.9front.org" + , name ? "source" + , leaveDotGit ? false + , deepClone ? false + , ... # For hash agility + } @ args: + + let + passthruAttrs = removeAttrs args [ "domain" "owner" "repo" "rev" "leaveDotGit" "deepClone" ]; + + useFetchGit = leaveDotGit || deepClone; + fetcher = if useFetchGit then fetchgit else fetchzip; + + gitRepoUrl = "git://${domain}/${owner}/${repo}"; + + fetcherArgs = (if useFetchGit then { + # git9 does not support shallow fetches + inherit rev leaveDotGit; + url = gitRepoUrl; + } else { + url = "https://${domain}/${owner}/${repo}/${rev}/snap.tar.gz"; + + passthru = { + inherit gitRepoUrl; + }; + }) // passthruAttrs // { inherit name; }; + in + + fetcher fetcherArgs // { inherit rev; } +) diff --git a/pkgs/common-updater/unstable-updater.nix b/pkgs/common-updater/unstable-updater.nix index f8944222a8d5..29b7fcf19679 100644 --- a/pkgs/common-updater/unstable-updater.nix +++ b/pkgs/common-updater/unstable-updater.nix @@ -12,6 +12,7 @@ , branch ? null , stableVersion ? false # Use version format according to RFC 107 (i.e. LAST_TAG+date=YYYY-MM-DD) , tagPrefix ? "" # strip this prefix from a tag name when using stable version +, shallowClone ? true }: let @@ -22,6 +23,7 @@ let branch="" use_stable_version="" tag_prefix="" + shallow_clone="" while (( $# > 0 )); do flag="$1" @@ -39,6 +41,9 @@ let --tag-prefix=*) tag_prefix="''${flag#*=}" ;; + --shallow-clone) + shallow_clone=1 + ;; *) echo "$0: unknown option ‘''${flag}’" exit 1 @@ -58,9 +63,12 @@ let cloneArgs=( --bare - --depth=1 ) + if [[ "$shallow_clone" == "1" ]]; then + cloneArgs+=(--depth=1) + fi + if [[ -n "$branch" ]]; then cloneArgs+=(--branch="$branch") fi @@ -101,7 +109,8 @@ let --rev="$commit_sha" ''; -in [ +in +[ updateScript "--url=${builtins.toString url}" ] ++ lib.optionals (branch != null) [ @@ -109,4 +118,6 @@ in [ ] ++ lib.optionals stableVersion [ "--use-stable-version" "--tag-prefix=${tagPrefix}" +] ++ lib.optionals shallowClone [ + "--shallow-clone" ] diff --git a/pkgs/shells/rc-9front/default.nix b/pkgs/shells/rc-9front/default.nix index e68674dfb3d0..2c3d565db5b9 100644 --- a/pkgs/shells/rc-9front/default.nix +++ b/pkgs/shells/rc-9front/default.nix @@ -1,6 +1,7 @@ { lib , stdenv -, fetchgit +, fetchFrom9Front +, unstableGitUpdater , byacc , installShellFiles }: @@ -9,8 +10,10 @@ stdenv.mkDerivation { pname = "rc-9front"; version = "unstable-2022-11-01"; - src = fetchgit { - url = "git://shithub.us/cinap_lenrek/rc"; + src = fetchFrom9Front { + domain = "shithub.us"; + owner = "cinap_lenrek"; + repo = "rc"; rev = "69041639483e16392e3013491fcb382efd2b9374"; hash = "sha256-xc+EfC4bc9ZA97jCQ6CGCzeLGf+Hx3/syl090/x4ew4="; }; @@ -31,7 +34,10 @@ stdenv.mkDerivation { install -m644 rcmain.unix $out/lib/rcmain ''; - passthru.shellPath = "/bin/rc"; + passthru = { + shellPath = "/bin/rc"; + updateScript = unstableGitUpdater { shallowClone = false; }; + }; meta = with lib; { description = "The 9front shell"; diff --git a/pkgs/tools/admin/drawterm/default.nix b/pkgs/tools/admin/drawterm/default.nix index 8451d8b687ff..32421a62da59 100644 --- a/pkgs/tools/admin/drawterm/default.nix +++ b/pkgs/tools/admin/drawterm/default.nix @@ -1,6 +1,7 @@ { stdenv , lib -, fetchgit +, fetchFrom9Front +, unstableGitUpdater , installShellFiles , makeWrapper , xorg @@ -19,10 +20,11 @@ stdenv.mkDerivation { pname = "drawterm"; version = "unstable-2023-06-27"; - src = fetchgit { - url = "git://git.9front.org/plan9front/drawterm"; + src = fetchFrom9Front { + owner = "plan9front"; + repo = "drawterm"; rev = "36debf46ac184a22c6936345d22e4cfad995948c"; - sha256 = "ebqw1jqeRC0FWeUIO/HaEovuwzU6+B48TjZbVJXByvA="; + hash = "sha256-ebqw1jqeRC0FWeUIO/HaEovuwzU6+B48TjZbVJXByvA="; }; enableParallelBuilding = true; @@ -54,6 +56,8 @@ stdenv.mkDerivation { installManPage drawterm.1 ''; + passthru.updateScript = unstableGitUpdater { shallowClone = false; }; + meta = with lib; { description = "Connect to Plan 9 CPU servers from other operating systems."; homepage = "https://drawterm.9front.org/"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index fc92464f3cd7..053abbcadaa4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1163,6 +1163,8 @@ with pkgs; fetchFromGitiles = callPackage ../build-support/fetchgitiles { }; + fetchFrom9Front = callPackage ../build-support/fetch9front { }; + fetchFromRepoOrCz = callPackage ../build-support/fetchrepoorcz { }; fetchgx = callPackage ../build-support/fetchgx { };