From 78993a5cc800211c151db0b350afe7ced37498cb Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Thu, 3 Jun 2021 21:00:35 +0200 Subject: [PATCH] feat(build): support nix via flake make it possible to install DCE via nix build github:direct-code-execution/ns-3-dce --- default.nix | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 41 +++++++++++++++++++++ flake.nix | 19 ++++++++++ 3 files changed, 164 insertions(+) create mode 100755 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix new file mode 100755 index 00000000..ede014e8 --- /dev/null +++ b/default.nix @@ -0,0 +1,104 @@ +# some dependencies need to be patched +# http://code.nsnam.org/bake/file/c502b48053dc/bakeconf.xml +{ stdenv, fetchFromGitHub, autoreconfHook, libtool, intltool, pkgconfig +, ns-3, gcc +, castxml ? null +# hidden dependency of waf +, ncurses +, python +, lib +, fetchurl +, withManual ? false +, withQuagga ? false +, withExamples ? false, openssl ? null, ccnd ? null, iperf2 ? null +# shall we generate bindings +, pythonSupport ? false +, ... +}: + +let + dce-version = "1.10"; + modules = [ "core" "network" "internet" "point-to-point" "fd-net-device" + "point-to-point-layout" "netanim" "tap-bridge" "mobility" "flow-monitor"] + ++ lib.optionals withQuagga [ "internet-apps" ] + ; + + ns3forDce = ns-3.override( { inherit modules python; }); + pythonEnv = python.withPackages(ps: + lib.optional withManual ps.sphinx + ++ lib.optionals pythonSupport (with ps;[ pybindgen pygccxml ]) + ); + + dce = stdenv.mkDerivation rec { + pname = "direct-code-execution"; + version = dce-version; + + outputs = [ "out" ] ++ lib.optional pythonSupport "py"; + + # with other modules + srcs = [ + (fetchFromGitHub { + owner = "direct-code-execution"; + repo = "ns-3-dce"; + rev = "dce-${version}"; + sha256 = "0f2g47mql8jjzn2q6lm0cbb5fv62sdqafdvx5g8s3lqri1sca14n"; + name = "dce"; + }) + ] + ++ lib.optional withQuagga (fetchFromGitHub { + owner = "direct-code-execution"; + repo = "ns-3-dce-quagga"; + rev = "dce-${dce-version}"; + sha256 = "1bbb1v33mv1p8isiggg9qg3a8hs0yq5s1dqz22lbdx55jrdxm7rb"; + name = "dce-quagga"; + }) + ; + + postUnpack = lib.optionalString withQuagga '' + # mv won't work :'( + cp -R dce-quagga/ ${sourceRoot}/myscripts + ''; + + sourceRoot = "dce"; + + buildInputs = [ ns3forDce gcc pythonEnv ] + ++ lib.optionals pythonSupport [ castxml ncurses ] + ++ lib.optionals withExamples [ openssl ] + ; + + nativeBuildInputs = [ pkgconfig ]; + + doCheck = true; + + patchPhase = '' + patchShebangs test.py + ''; + configurePhase = '' + runHook preConfigure + + ${pythonEnv.interpreter} ./waf configure --prefix=$out \ + --with-ns3=${ns3forDce} --with-python=${pythonEnv.interpreter} \ + ${lib.optionalString (!withExamples) "--disable-examples "} ${lib.optionalString (!doCheck) " --disable-tests" }; + + runHook postConfigure + ''; + + buildPhase='' + ${pythonEnv.interpreter} ./waf build + ''; + + hardeningDisable = [ "all" ]; + + # shellHook= lib.optionalString withExamples '' + # export DCE_PATH=${iperf-dce}/bin + # ''; + + meta = { + homepage = https://www.nsnam.org/overview/projects/direct-code-execution; + license = lib.licenses.gpl3; + description = "Run real applications/network stacks in the simulator ns-3"; + platforms = with lib.platforms; unix; + }; + }; +in + dce diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..ab521365 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1622445595, + "narHash": "sha256-m+JRe6Wc5OZ/mKw2bB3+Tl0ZbtyxxxfnAWln8Q5qs+Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7d706970d94bc5559077eb1a6600afddcd25a7c8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1622744171, + "narHash": "sha256-dNPwOcVt46vonS3i53onv0MAcvkaTWCBCBOKrirTDvk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4241512688bd75a5f0755fb38d22c3003754b5f7", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a75b9142 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "Run real programs in the discrete time simulator ns3"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem ["x86_64-linux"] (system: let + pkgs = import nixpkgs { inherit system; }; + + in { + + packages.dce = pkgs.callPackage ./default.nix {}; + + defaultPackage = self.packages."${system}".dce; + + }); +}