mirror of
https://github.com/kp2pml30/git-third-party.git
synced 2026-02-16 23:54:41 +04:00
feat: add collecting nix derivation from source
This commit is contained in:
parent
49cacfdb5e
commit
9dee6d3afc
4 changed files with 161 additions and 0 deletions
62
collect-sources.nix
Normal file
62
collect-sources.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
{ rootDerivation
|
||||
, derivationName
|
||||
, stdenv
|
||||
, ... # added for future backwards compatibility
|
||||
}:
|
||||
let
|
||||
config = builtins.fromJSON (builtins.readFile "${rootDerivation}/.git-third-party/config.json");
|
||||
allRepoNames = builtins.attrNames config.repos;
|
||||
makeDependentDerivation =
|
||||
name:
|
||||
let
|
||||
cleanName = builtins.head (builtins.tail (builtins.match "^(.*/|)([^/]+)$" name));
|
||||
myConfig = config.repos."${name}";
|
||||
shouldFetchModules = !(builtins.hasAttr "submodules" myConfig) || myConfig.submodules != [];
|
||||
base-src = builtins.fetchGit {
|
||||
url = myConfig.url;
|
||||
rev = myConfig.commit;
|
||||
submodules = shouldFetchModules;
|
||||
#fetchSubmodules = shouldFetchModules;
|
||||
# fetchLFS = true;
|
||||
shallow = true;
|
||||
};
|
||||
in stdenv.mkDerivation {
|
||||
name = "git3party_${derivationName}_${cleanName}";
|
||||
src = base-src;
|
||||
patches =
|
||||
builtins.map
|
||||
(num: "${rootDerivation}/.git-third-party/patches/${name}/${toString num}")
|
||||
(builtins.genList (x: x + 1) myConfig.patches);
|
||||
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
||||
|
||||
#outputHashMode = "recursive";
|
||||
|
||||
installPhase = ''
|
||||
cp -r . "$out"
|
||||
'';
|
||||
};
|
||||
dependentDerivations = builtins.map (name: { name = name; der = makeDependentDerivation name; }) allRepoNames;
|
||||
|
||||
cpFlags = "--no-preserve=ownership,mode --preserve=xattr";
|
||||
|
||||
copyLines = builtins.concatStringsSep "\n" ([
|
||||
"cp ${cpFlags} -r '${rootDerivation}/.' ."
|
||||
] ++ builtins.map (nameDer: "mkdir -p '${nameDer.name}'\ncp ${cpFlags} -r '${nameDer.der}'/. '${nameDer.name}'") dependentDerivations);
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = derivationName;
|
||||
|
||||
srcs = [
|
||||
rootDerivation
|
||||
] ++ (builtins.map (x: x.name) dependentDerivations);
|
||||
|
||||
phases = [ "unpackPhase" "installPhase" ];
|
||||
|
||||
#outputHashMode = "recursive";
|
||||
|
||||
unpackPhase = copyLines;
|
||||
|
||||
installPhase = ''
|
||||
cp -r . "$out"
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue