about summary refs log tree commit diff
path: root/pkgs/build-support/fetchpijul/default.nix
blob: ca7e1a7926e804659a805794eab439c6145e6e09 (plain) (blame)
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
{ lib, stdenvNoCC, pijul }:

lib.makeOverridable (
{ url
, hash ? ""
, change ? null
, state ? null
, channel ? "main"
, name ? "fetchpijul"
, # TODO: Changes in pijul are unordered so there's many ways to end up with the same repository state.
  # This makes leaveDotPijul unfeasible to implement until pijul CLI implements
  # a way of reordering changes to sort them in a consistent and deterministic manner.
  # leaveDotPijul ? false
}:
if change != null && state != null then
  throw "Only one of 'change' or 'state' can be set"
else
  stdenvNoCC.mkDerivation {
    inherit name;
    nativeBuildInputs = [ pijul ];

    dontUnpack = true;
    dontConfigure = true;
    dontBuild = true;

    installPhase = ''
      runHook preInstall

      pijul clone \
        ''${change:+--change "$change"} \
        ''${state:+--state "$state"} \
        --channel "$channel" \
        "$url" \
        "$out"

      runHook postInstall
    '';

    fixupPhase = ''
      runHook preFixup

      rm -rf "$out/.pijul"

      runHook postFixup
    '';

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

    inherit url change state channel;
  }
)