about summary refs log tree commit diff
path: root/pkgs/sternenseemann/bundle-signed-release/default.nix
blob: 5db979b0c5377f9a8fd13bae57da276ed2a3d1fb (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
# Build a directory containing release tarballs and
# their signatures. Fail if a signature is invalid.
{ lib
, getBins
, signify
, buildGitTarball
, runCommandNoCC
}:

{ # public key to verify against
  publicKey
  # directory signature files are located in
, sigs
}:

{ # project name:
  # * tarballs are name ${pname}-${tag}.tar.gz
  # * signatures are name ${pname}-${tag}.tar.gz.sig
  pname
  # information about the git remote to fetch from
  # must contain an url attribute and may contain
  # a subDir attribute.
, git
  # List of releases which are represented as an
  # attribute set which contains a sha256 and
  # either a tag or rev attribute.
, releases
}:

let
  bins = getBins signify [ "signify" ];

  tarballs = builtins.map
    (args: buildGitTarball (git // args // {
      inherit pname;
    })) releases;

  sigFor = tarball: "${sigs}/${tarball.name}.sig";
in

runCommandNoCC "${pname}-releases" {} (''
  mkdir -p "$out"
'' + lib.concatMapStrings (tarball: ''
  # verify tarball and inform user about what's happening
  echo -n "${tarball.name}: "
  ${bins.signify} -V \
    -p "${publicKey}" \
    -m "${tarball}" \
    -x "${sigFor tarball}"

  # succeeded, so copy tarball and signature
  ln -s "${tarball}" "$out/${tarball.name}"
  ln -s "${sigFor tarball}" "$out/${baseNameOf (sigFor tarball)}"
'') tarballs)