milahu / nixpkgs

Nix Packages collection
MIT License
1 stars 0 forks source link

fetchgit should deduplicate gitmodules in the nix store #38

Open milahu opened 7 months ago

milahu commented 7 months ago

currently, when a git repo has git modules (git submodules) (.gitmodules file) then fetchgit with { fetchSubmodules = true; } will fetch the git modules with git submodule update

the result is a directory with copies of all git modules

expected: fetchgit should store the git modules in separate derivations and symlink git modules to the parent repo this adds more complexity because we need a lockfile with all rev and hash values for all git modules

nixpkgs/pkgs/build-support/fetchgit/nix-prefetch-git

# Update submodules
init_submodules(){
    # shallow with leaveDotGit will change hashes
    [[ -z "$deepClone" ]] && [[ -z "$leaveDotGit" ]] && \
    clean_git submodule update --init --recursive -j ${NIX_BUILD_CORES:-1} --progress --depth 1 || \
    clean_git submodule update --init --recursive -j ${NIX_BUILD_CORES:-1} --progress
}

clone(){
    local top=$PWD
    local dir="$1"
    local url="$2"
    local hash="$3"
    local ref="$4"

    cd "$dir"

    # Initialize the repository.
    init_remote "$url"

    # Download data from the repository.
    checkout_ref "$hash" "$ref" ||
    checkout_hash "$hash" "$ref" || (
        echo 1>&2 "Unable to checkout $hash$ref from $url."
        exit 1
    )

    # Checkout linked sources.
    if test -n "$fetchSubmodules"; then
        init_submodules
    fi