Skip to content

Commit

Permalink
Add Nix expressions to build Snabb project
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Apr 18, 2016
1 parent 03f5958 commit a357165
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
39 changes: 39 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Run like this:
# nix-build /path/to/this/directory
# ... and the files are produced in ./result/

{ pkgs ? (import <nixpkgs> {})
}:

with pkgs;

stdenv.mkDerivation rec {
# TODO: get the version from somewhere?
name = "snabb";

src = ./.;

buildInputs = [ makeWrapper ];

patchPhase = ''
patchShebangs .
# some hardcodeism
for f in $(find src/program/snabbnfv/ -type f); do
substituteInPlace $f --replace "/bin/bash" "${bash}/bin/bash"
done
# We need a way to pass $PATH to the scripts
sed -i '2iexport PATH=${git}/bin:${mariadb}/bin:${which}/bin:${procps}/bin:${coreutils}/bin' src/program/snabbnfv/neutron_sync_master/neutron_sync_master.sh.inc
sed -i '2iexport PATH=${git}/bin:${coreutils}/bin:${diffutils}/bin:${nettools}/bin' src/program/snabbnfv/neutron_sync_agent/neutron_sync_agent.sh.inc
'';

preBuild = ''
make clean
'';

installPhase = ''
mkdir -p $out/bin
cp src/snabb $out/bin
'';
}
64 changes: 64 additions & 0 deletions release.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Run like this:
# nix-build /path/to/this/directory/release.nix -A manual
# ... and the files are produced in ./result/

{ pkgs ? (import <nixpkgs> {})
}:

with pkgs;

let
# see https://github.com/snabbco/snabb/blob/master/src/doc/testing.md
test_env = fetchurl {
url = "http://lab1.snabb.co:2008/~max/assets/vm-ubuntu-trusty-14.04-dpdk-snabb.tar.gz";
sha256 = "0323591i925jhd6wv8h268wc3ildjpa6j57n4p9yg9d6ikwkw06j";
};
in rec {
manual = import ./src/doc {};
snabb = import ./default.nix {};
tests = stdenv.mkDerivation rec {
name = "snabb-tests";

src = snabb.src;

# allow sudo
__noChroot = true;
requiredSystemFeatures = [ "performance" ];

buildInputs = [ git telnet tmux numactl bc iproute which qemu ];

buildPhase = ''
export PATH=$PATH:/var/setuid-wrappers/
export HOME=$TMPDIR
# make sure we reuse the snabb built in another derivation
ln -s ${snabb}/bin/snabb src/snabb
sed -i 's/testlog snabb/testlog/' src/Makefile
# setup the environment
mkdir ~/.test_env
tar xvzf ${test_env} -C ~/.test_env/
'';

doCheck = true;
checkPhase = ''
export SNABB_PCI0="0000:01:00.0"
export SNABB_PCI_INTEL1="0000:01:00.1"
export SNABB_PCI_INTEL0="0000:01:00.0"
export FAIL_ON_FIRST=true
# run tests
sudo -E make test -C src/
'';

installPhase = ''
mkdir -p $out/nix-support
# keep the logs
cp src/testlog/* $out/
for f in $(ls $out/* | sort); do
echo "file log $f" >> $out/nix-support/hydra-build-products
done
'';
};
}
43 changes: 43 additions & 0 deletions src/doc/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Run like this:
# nix-build /path/to/this/directory
# ... and the files are produced in ./result/

{ pkgs ? (import <nixpkgs> {})
}:

with pkgs;

stdenv.mkDerivation rec {
name = "snabb-manual";
src = ../../.;

buildInputs = [ ditaa pandoc git
(texlive.combine {
inherit (texlive) scheme-small luatex luatexbase sectsty titlesec cprotect bigfoot titling droid;
})
];

patchPhase = ''
patchShebangs src/doc
patchShebangs src/scripts
'';

buildPhase = ''
# needed for font cache
export TEXMFCACHE=`pwd`
make book -C src
'';

installPhase = ''
mkdir -p $out/share/doc
cp src/obj/doc/snabb.* $out/share/doc
# Give manual to Hydra
mkdir -p $out/nix-support
echo "doc-pdf manual $out/share/doc/snabb.pdf" >> $out/nix-support/hydra-build-products;
echo "doc HTML $out/share/doc/snabb.html" >> $out/nix-support/hydra-build-products;
echo "doc epub $out/share/doc/snabb.epub" >> $out/nix-support/hydra-build-products;
echo "doc markdown $out/share/doc/snabb.markdown" >> $out/nix-support/hydra-build-products;
'';
}

0 comments on commit a357165

Please sign in to comment.