Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Run like this:
- # nix-build /path/to/this/directory
- # ... and the files are produced in ./result/bin/snabb
- { pkgs ? (import <nixpkgs> {})
- # FIXME: make it work with either nix-build ("source") or Hydra ("src") or both
- , source ? ./.
- , src ? null
- # Overrides the version in src.gitTag
- , version ? null
- # Optional subname like "lwaftr"
- , subname ? null
- , supportOpenstack ? true
- }:
- with pkgs;
- let
- tag_version = (src:
- if builtins.isAttrs src && builtins.isString src.gitTag then
- # FIXME: run the system command, or split the string natively
- # "git describe --tags" returns the former when not run in a tag checkout:
- # "v3.1.5-14-54a7b34f" -> "v3.1.5"
- "cut -d '-' -f 1 ${src.gitTag}"
- else "") src;
- tmp_name = (subname:
- if builtins.isString subname then "snabb-${subname}" else "snabb") subname;
- name = (version: tag_version:
- if builtins.isString version then
- "${tmp_name}-${version}"
- else if builtins.isString tag_version then
- "${tmp_name}-${tag_version}"
- else
- "${tmp_name}-dev") version tag_version;
- in stdenv.mkDerivation rec {
- inherit name;
- # cleanSource removes the .git directory, needed by distPhase
- # src = lib.cleanSource source;
- buildInputs = [ git makeWrapper ];
- patchPhase = ''
- patchShebangs .
- # some hardcodeism
- for f in $(find src/program/snabbnfv/ -type f); do
- substituteInPlace $f --replace "/bin/bash" "${bash}/bin/bash"
- done
- '' + lib.optionalString supportOpenstack ''
- # 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
- '';
- enableParallelBuilding = true;
- # Enable distPhase and xz-compressed tarballs.
- doDist = true;
- # Enable handling of xz-compressed tarballs.
- tarballs = "*.tar.xz";
- # Pass Makefile parameters that massage the generated tarball.
- distFlags = "PACKAGE=${name} DIST_BINARY=${name}";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement