summary refs log tree commit diff
path: root/pkgs/applications/science/programming/scyther/default.nix
blob: 5cfe081072a4e1174f5da08ade8d3267e6d126ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ stdenv, lib, buildEnv, pkgsi686Linux, fetchFromGitHub, python27Packages, graphviz
, includeGUI ? true
, includeProtocols ? true
}:
let
  version = "1.1.3";

  src = fetchFromGitHub {
    rev = "v${version}";
    sha256 = "0rb4ha5bnjxnwj4f3hciq7kyj96fhw14hqbwl5kr9cdw8q62mx0h";
    owner = "cascremers";
    repo = "scyther";
  };

  meta = with lib; {
    description = "Scyther is a tool for the automatic verification of security protocols.";
    homepage = "https://www.cs.ox.ac.uk/people/cas.cremers/scyther/";
    license = licenses.gpl2;
    maintainers = with maintainers; [ infinisil ];
    platforms = platforms.linux;
  };

  cli = pkgsi686Linux.callPackage ./cli.nix {
    inherit version src meta;
  };

  gui = stdenv.mkDerivation {
    pname = "scyther-gui";
    inherit version;
    inherit src meta;
    buildInputs = [
      python27Packages.wrapPython
    ];

    patchPhase = ''
      file=gui/Scyther/Scyther.py

      # By default the scyther binary is looked for in the directory of the python script ($out/gui), but we want to have it look where our cli package is
      substituteInPlace $file --replace "return getMyDir()" "return \"${cli}/bin\""

      # Removes the Shebang from the file, as this would be wrapped wrongly
      sed -i -e "1d" $file
    '';

    dontBuild = true;

    propagatedBuildInputs = [
      python27Packages.wxPython
      graphviz
    ];

    installPhase = ''
      mkdir -p "$out"/gui "$out"/bin
      cp -r gui/* "$out"/gui
      ln -s "$out"/gui/scyther-gui.py "$out/bin/scyther-gui"
    '';

    postFixup = ''
      wrapPythonProgramsIn "$out/gui" "$out $pythonPath"
    '';

    doInstallCheck = true;
    installCheckPhase = ''
      "$out/gui/scyther.py" "$src/gui/Protocols/Demo/ns3.spdl"
    '';
  };
in
  buildEnv {
    name = "scyther-${version}";
    inherit meta;
    paths = [ cli ] ++ lib.optional includeGUI gui;
    pathsToLink = [ "/bin" ];

    postBuild = ''
      rm "$out/bin/scyther-linux"
    '' + lib.optionalString includeProtocols ''
      mkdir -p "$out/protocols"
      cp -rv ${src}/protocols/* "$out/protocols"
    '';
  }