Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. # Run like this:
  2. # nix-build /path/to/this/directory
  3. # ... and the files are produced in ./result/bin/snabb
  4.  
  5. { pkgs ? (import <nixpkgs> {})
  6. # FIXME: make it work with either nix-build ("source") or Hydra ("src") or both
  7. , source ? ./.
  8. , src ? null
  9. # Overrides the version in src.gitTag
  10. , version ? null
  11. # Optional subname like "lwaftr"
  12. , subname ? null
  13. , supportOpenstack ? true
  14. }:
  15.  
  16. with pkgs;
  17.  
  18. let
  19. tag_version = (src:
  20. if builtins.isAttrs src && builtins.isString src.gitTag then
  21. # FIXME: run the system command, or split the string natively
  22. # "git describe --tags" returns the former when not run in a tag checkout:
  23. # "v3.1.5-14-54a7b34f" -> "v3.1.5"
  24. "cut -d '-' -f 1 ${src.gitTag}"
  25. else "") src;
  26. tmp_name = (subname:
  27. if builtins.isString subname then "snabb-${subname}" else "snabb") subname;
  28. name = (version: tag_version:
  29. if builtins.isString version then
  30. "${tmp_name}-${version}"
  31. else if builtins.isString tag_version then
  32. "${tmp_name}-${tag_version}"
  33. else
  34. "${tmp_name}-dev") version tag_version;
  35. in stdenv.mkDerivation rec {
  36. inherit name;
  37.  
  38. # cleanSource removes the .git directory, needed by distPhase
  39. # src = lib.cleanSource source;
  40.  
  41. buildInputs = [ git makeWrapper ];
  42.  
  43. patchPhase = ''
  44. patchShebangs .
  45.  
  46. # some hardcodeism
  47. for f in $(find src/program/snabbnfv/ -type f); do
  48. substituteInPlace $f --replace "/bin/bash" "${bash}/bin/bash"
  49. done
  50. '' + lib.optionalString supportOpenstack ''
  51. # We need a way to pass $PATH to the scripts
  52. 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
  53. sed -i '2iexport PATH=${git}/bin:${coreutils}/bin:${diffutils}/bin:${nettools}/bin' src/program/snabbnfv/neutron_sync_agent/neutron_sync_agent.sh.inc
  54. '';
  55.  
  56. preBuild = ''
  57. make clean
  58. '';
  59.  
  60. installPhase = ''
  61. mkdir -p $out/bin
  62. cp src/snabb $out/bin
  63. '';
  64.  
  65. enableParallelBuilding = true;
  66.  
  67. # Enable distPhase and xz-compressed tarballs.
  68. doDist = true;
  69. # Enable handling of xz-compressed tarballs.
  70. tarballs = "*.tar.xz";
  71. # Pass Makefile parameters that massage the generated tarball.
  72. distFlags = "PACKAGE=${name} DIST_BINARY=${name}";
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement