summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/fetchsvn/default.nix
blob: 64d1514c3c974cab4146641511eb813157613800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  lib,
  stdenvNoCC,
  buildPackages,
  cacert,
  subversion,
  glibcLocales,
  sshSupport ? true,
  openssh ? null,
}:

let
  repoToName =
    url: rev:
    let
      inherit (lib)
        removeSuffix
        splitString
        reverseList
        head
        last
        elemAt
        ;
      base = removeSuffix "/" (last (splitString ":" url));
      path = reverseList (splitString "/" base);
      repoName =
        # ../repo/trunk -> repo
        if head path == "trunk" then
          elemAt path 1
        # ../repo/branches/branch -> repo-branch
        else if elemAt path 1 == "branches" then
          "${elemAt path 2}-${head path}"
        # ../repo/tags/tag -> repo-tag
        else if elemAt path 1 == "tags" then
          "${elemAt path 2}-${head path}"
        # ../repo (no trunk) -> repo
        else
          head path;
    in
    "${repoName}-r${toString rev}";
in

{
  url,
  rev ? "HEAD",
  name ? repoToName url rev,
  sha256 ? "",
  hash ? "",
  ignoreExternals ? false,
  ignoreKeywords ? false,
  preferLocalBuild ? true,
}:

assert sshSupport -> openssh != null;

if hash != "" && sha256 != "" then
  throw "Only one of sha256 or hash can be set"
else
  stdenvNoCC.mkDerivation {
    inherit name;
    builder = ./builder.sh;
    nativeBuildInputs = [
      cacert
      subversion
      glibcLocales
    ]
    ++ lib.optional sshSupport openssh;

    strictDeps = true;
    __structuredAttrs = true;

    env = lib.optionalAttrs sshSupport {
      SVN_SSH = lib.getExe buildPackages.openssh;
    };

    outputHashAlgo = if hash != "" then null else "sha256";
    outputHashMode = "recursive";
    outputHash =
      if hash != "" then
        hash
      else if sha256 != "" then
        sha256
      else
        lib.fakeSha256;

    inherit
      url
      rev
      ignoreExternals
      ignoreKeywords
      ;

    impureEnvVars = lib.fetchers.proxyImpureEnvVars;
    inherit preferLocalBuild;
  }