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
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
||||||
/.ruff_cache
|
/.ruff_cache
|
||||||
__pycache__
|
__pycache__
|
||||||
/third-party
|
/third-party
|
||||||
|
/.direnv
|
||||||
|
/.envrc
|
||||||
|
|
|
||||||
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"
|
||||||
|
'';
|
||||||
|
}
|
||||||
64
flake.lock
generated
Normal file
64
flake.lock
generated
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": [
|
||||||
|
"systems"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1744440957,
|
||||||
|
"narHash": "sha256-FHlSkNqFmPxPJvy+6fNLaNeWnF1lZSgqVCl/eWaJRc4=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "26d499fc9f1d567283d5d56fcf367edd815dba1d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-24.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"systems": "systems"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
33
flake.nix
Normal file
33
flake.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
||||||
|
systems = {
|
||||||
|
url = "github:nix-systems/default";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
flake-utils = {
|
||||||
|
url = "github:numtide/flake-utils";
|
||||||
|
inputs.systems.follows = "systems";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem
|
||||||
|
(system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
python312
|
||||||
|
pre-commit
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue