Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Automate creation of tarball releases with Hydra (#733)
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Run like this: | ||
# nix-build ./tarball.nix | ||
# or | ||
# nix-build --argstr hydraName snabb-lwaftr --argstr version v1.0.0 ./tarball.nix | ||
# and the release tarball will be written to ./result/ . It will contain | ||
# both the sources and the executable, patched to run on Linux LSB systems. | ||
# | ||
# NOTE: Hydra doesn't use the --tags parameter in the "git describe" command (see | ||
# https://github.com/NixOS/hydra/blob/master/src/lib/Hydra/Plugin/GitInput.pm#L148 | ||
# ), so lightweight (non-annotated) tags are not found. Always create annotated | ||
# tags with the "git tag" command by using one of the -a, -s or -u options. | ||
|
||
{ nixpkgs ? <nixpkgs> | ||
, hydraName ? "snabb" | ||
, src ? ./. | ||
, version ? "dev" | ||
}: | ||
|
||
let | ||
pkgs = import nixpkgs {}; | ||
name = (src: | ||
if builtins.isAttrs src then | ||
# Called from Hydra with "src" as "Git version", get the version from git tags. | ||
# If the last commit is the tag's one, you'll just get the tag name: "v3.1.7"; | ||
# otherwise you'll also get the number of commits since the last tag, and the | ||
# shortened commit checksum: "v3.1.7-7-g89747a1". | ||
"${hydraName}-${src.gitTag}" | ||
else | ||
# Called from the command line, the user supplies the version. | ||
"${hydraName}-${version}") src; | ||
in { | ||
tarball = pkgs.stdenv.mkDerivation rec { | ||
inherit name src; | ||
|
||
buildInputs = with pkgs; [ makeWrapper patchelf ]; | ||
|
||
postUnpack = '' | ||
mkdir -p $out/$name | ||
cp -a $sourceRoot/* $out/$name | ||
''; | ||
|
||
preBuild = '' | ||
make clean | ||
''; | ||
|
||
installPhase = '' | ||
mv src/snabb $out | ||
''; | ||
|
||
fixupPhase = '' | ||
patchelf --shrink-rpath $out/snabb | ||
patchelf --set-rpath /lib/x86_64-linux-gnu $out/snabb | ||
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $out/snabb | ||
''; | ||
|
||
doDist = true; | ||
|
||
distPhase = '' | ||
cd $out | ||
tar Jcf $name.tar.xz * | ||
# Make the tarball available for download through Hydra. | ||
mkdir -p $out/nix-support | ||
echo "file tarball $out/$name.tar.xz" >> $out/nix-support/hydra-build-products | ||
''; | ||
}; | ||
} |