@@ -73,4 +73,56 @@ rec {
7373 done
7474 '';
7575
76+ /* Create a channel job which success depends on the success of all of
77+ its contituents. Channel jobs are a special type of jobs that are
78+ listed in the channel tab of Hydra and that can be suscribed.
79+ A tarball of the src attribute is distributed via the channel.
80+
81+ - constituents: a list of derivations on which the channel success depends.
82+ - name: the channel name that will be used in the hydra interface.
83+ - src: should point to the root folder of the nix-expressions used by the
84+ channel, typically a folder containing a `default.nix`.
85+
86+ channel {
87+ constituents = [ foo bar baz ];
88+ name = "my-channel";
89+ src = ./.;
90+ };
91+
92+ */
93+ channel =
94+ { name, src, constituents ? [], meta ? {}, isNixOS ? true, ... }@args:
95+ stdenv.mkDerivation ({
96+ preferLocalBuild = true;
97+ _hydraAggregate = true;
98+
99+ phases = [ "unpackPhase" "patchPhase" "installPhase" ];
100+
101+ patchPhase = stdenv.lib.optionalString isNixOS ''
102+ touch .update-on-nixos-rebuild
103+ '';
104+
105+ installPhase = ''
106+ mkdir -p $out/{tarballs,nix-support}
107+
108+ tar cJf "$out/tarballs/nixexprs.tar.xz" \
109+ --owner=0 --group=0 --mtime="1970-01-01 00:00:00 UTC" \
110+ --transform='s!^\.!${name}!' .
111+
112+ echo "channel - $out/tarballs/nixexprs.tar.xz" > "$out/nix-support/hydra-build-products"
113+ echo $constituents > "$out/nix-support/hydra-aggregate-constituents"
114+
115+ # Propagate build failures.
116+ for i in $constituents; do
117+ if [ -e "$i/nix-support/failed" ]; then
118+ touch "$out/nix-support/failed"
119+ fi
120+ done
121+ '';
122+
123+ meta = meta // {
124+ isHydraChannel = true;
125+ };
126+ } // removeAttrs args [ "meta" ]);
127+
76128}