summaryrefslogtreecommitdiffstats
path: root/nixos/lib/make-channel.nix
blob: 098be3237dae35412c18b558e0000ef43037eb1a (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
/*
  Build a channel tarball. These contain, in addition to the nixpkgs
  expressions themselves, files that indicate the version of nixpkgs
  that they represent.
*/
{
  pkgs,
  nixpkgs,
  version,
  versionSuffix,
}:

pkgs.releaseTools.makeSourceTarball {
  name = "nixos-channel";

  src = nixpkgs;

  officialRelease = false; # FIXME: fix this in makeSourceTarball
  inherit version versionSuffix;

  buildInputs = with pkgs; [
    nix
    zstd
  ];

  distPhase = ''
    rm -rf .git
    echo -n $VERSION_SUFFIX > .version-suffix
    echo -n ${nixpkgs.rev or nixpkgs.shortRev} > .git-revision
    releaseName=nixos-$VERSION$VERSION_SUFFIX
    mkdir -p $out/tarballs
    cp -prd . ../$releaseName
    chmod -R u+w ../$releaseName
    ln -s . ../$releaseName/nixpkgs # hack to make ‘<nixpkgs>’ work
    NIX_STATE_DIR=$TMPDIR nix-env -f ../$releaseName/default.nix -qaP --meta --show-trace --xml \* > /dev/null
    cd ..
    chmod -R u+w $releaseName

    # The compression tasks are shortlived; use all available CPUs (-T0) to
    # prioritize fast channel advancement.
    XZ_OPT="-T0" tar \
      --create \
      --file=$out/tarballs/$releaseName.tar.xz \
      --xz \
      --absolute-names \
      --owner=0 \
      --group=0 \
      --numeric-owner \
      --format=gnu \
      --sort=name \
      --mtime="@$SOURCE_DATE_EPOCH" \
      --hard-dereference \
      $releaseName

    tar \
      --create \
      --file="$out/tarballs/$releaseName.tar.zst" \
      --use-compress-program="zstd -19 -T0" \
      --absolute-names \
      --owner=0 \
      --group=0 \
      --numeric-owner \
      --format=gnu \
      --sort=name \
      --mtime="@$SOURCE_DATE_EPOCH" \
      --hard-dereference \
      $releaseName
  '';
}