Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenvNoCC,
4 buildPackages,
5 cacert,
6 subversion,
7 glibcLocales,
8 sshSupport ? true,
9 openssh ? null,
10}:
11
12let
13 repoToName =
14 url: rev:
15 let
16 inherit (lib)
17 removeSuffix
18 splitString
19 reverseList
20 head
21 last
22 elemAt
23 ;
24 base = removeSuffix "/" (last (splitString ":" url));
25 path = reverseList (splitString "/" base);
26 repoName =
27 # ../repo/trunk -> repo
28 if head path == "trunk" then
29 elemAt path 1
30 # ../repo/branches/branch -> repo-branch
31 else if elemAt path 1 == "branches" then
32 "${elemAt path 2}-${head path}"
33 # ../repo/tags/tag -> repo-tag
34 else if elemAt path 1 == "tags" then
35 "${elemAt path 2}-${head path}"
36 # ../repo (no trunk) -> repo
37 else
38 head path;
39 in
40 "${repoName}-r${toString rev}";
41in
42
43{
44 url,
45 rev ? "HEAD",
46 name ? repoToName url rev,
47 sha256 ? "",
48 hash ? "",
49 ignoreExternals ? false,
50 ignoreKeywords ? false,
51 preferLocalBuild ? true,
52}:
53
54assert sshSupport -> openssh != null;
55
56if hash != "" && sha256 != "" then
57 throw "Only one of sha256 or hash can be set"
58else
59 stdenvNoCC.mkDerivation {
60 inherit name;
61 builder = ./builder.sh;
62 nativeBuildInputs = [
63 cacert
64 subversion
65 glibcLocales
66 ]
67 ++ lib.optional sshSupport openssh;
68
69 SVN_SSH = if sshSupport then "${buildPackages.openssh}/bin/ssh" else null;
70
71 outputHashAlgo = if hash != "" then null else "sha256";
72 outputHashMode = "recursive";
73 outputHash =
74 if hash != "" then
75 hash
76 else if sha256 != "" then
77 sha256
78 else
79 lib.fakeSha256;
80
81 inherit
82 url
83 rev
84 ignoreExternals
85 ignoreKeywords
86 ;
87
88 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
89 inherit preferLocalBuild;
90 }