feat: Add git submodule vendor support
enhancement
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I'm running into an issue where I'm having to override a vendored dependency that requires a submodule to be fetched, and it would be super nice if there was just a straight-forward way to tell crane that certain dependencies should have `fetchSubmodules = true`. Basically just having some way to step into the IFD generator so that it's easier for users of my library to always have the submodule fetched and they won't have to pass `--impure` to their flake or manage a FOD that will eventually break and cause odd error messages.
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
It would be cool to be able to do:
```nix
craneLib.vendorCargoDeps {
overrideVendorGitCheckout = ps: drv:
let
cond = p: p.name == "my-dep-needing-submodules";
in
if lib.any (p: cond p) ps then
drv.overrideAttrs (old: {
src = old.src.override { fetchSubmodules = true; };
})
else
drv;
};
```
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
This is what I am currently doing... I could make it a function for users and they have to provide a hash, but if there was just an option to tell crane "these deps need submodules" that would be handy.
```nix
commonTestArgs = src: {
inherit src;
strictDeps = true;
cargoVendorDir =
let
isReaperLow = p: p.name == "reaper-low";
parseCargoSource = source:
let
# Split "type+rest" e.g. "git+https://..." or "registry+https://..."
hasPlusType = builtins.match "^[a-z]+\\+.*" source != null;
type = if hasPlusType then lib.elemAt (lib.splitString "+" source) 0 else "unknown";
withoutType = if hasPlusType then lib.removePrefix "${type}+" source else source;
# Split off rev fragment "#abc123"
fragmentParts = lib.splitString "#" withoutType;
urlWithQuery = lib.elemAt fragmentParts 0;
rev = if lib.length fragmentParts > 1 then lib.last fragmentParts else null;
# Split off query string "?branch=master&foo=bar" into an attrset
queryParts = lib.splitString "?" urlWithQuery;
url = lib.elemAt queryParts 0;
queryString = if lib.length queryParts > 1 then lib.last queryParts else null;
query =
if queryString != null then
builtins.listToAttrs (map (kv:
let pair = lib.splitString "=" kv;
in { name = lib.elemAt pair 0; value = lib.elemAt pair 1; }
) (lib.splitString "&" queryString))
else
{};
in
{
inherit type url rev query;
};
in
craneLib.vendorCargoDeps {
inherit src;
overrideVendorGitCheckout = ps: drv:
if lib.any (p: isReaperLow p) ps then
let
p = lib.findFirst isReaperLow null ps;
parsed = parseCargoSource (builtins.trace "Located ${p.name} which requires a vendor override: ${builtins.toJSON p}" p.source);
src = pkgs.fetchgit {
inherit (builtins.trace "Parsed cargo source for ${p.name}: ${builtins.toJSON parsed}" parsed) url rev;
fetchSubmodules = true;
hash = "sha256-ggFAtcA0d6Gr1o8omW1vOP2V+WTpiTbaj2rRNQXbejM=";
};
in
pkgs.runCommand "cargo-git-reaper-rs-with-submodules" {} ''
echo "Patching WDL submodule for vendored dependency ${p.name}-${p.version}"
cp -r ${drv} $out
chmod -R u+w $out
mkdir -p $out/${p.name}-${p.version}/lib/WDL
cp -r ${src}/main/low/lib/WDL $out/${p.name}-${p.version}/lib
echo "Done: $out/${p.name}-${p.version}/lib/WDL"
''
else
drv;
};
};
```
**Additional context**
Add any other context or screenshots about the feature request here.
0 条评论