about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/electronics/fritzing/default.nix
blob: 955edb9b59ae27efabbbcbd6e351b475a7eb609d (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{ stdenv
, lib
, fetchFromGitHub
, wrapQtAppsHook
, qmake
, pkg-config
, qtbase
, qtsvg
, qttools
, qtserialport
, qtwayland
, qt5compat
, boost
, libngspice
, libgit2
, quazip
, clipper
}:

let
  # SHA256 of the fritzing-parts HEAD on the master branch,
  # which contains the latest stable parts definitions
  partsSha = "015626e6cafb1fc7831c2e536d97ca2275a83d32";

  parts = fetchFromGitHub {
    owner = "fritzing";
    repo = "fritzing-parts";
    rev = partsSha;
    hash = "sha256-5jw56cqxpT/8bf1q551WG53J6Lw5pH0HEtRUoNNMc+A=";
  };

  # Header-only library
  svgpp = fetchFromGitHub {
    owner = "svgpp";
    repo = "svgpp";
    rev = "v1.3.0";
    hash = "sha256-kJEVnMYnDF7bThDB60bGXalYgpn9c5/JCZkRSK5GoE4=";
  };
in

stdenv.mkDerivation {
  pname = "fritzing";
  version = "1.0.2";

  src = fetchFromGitHub {
    owner = "fritzing";
    repo = "fritzing-app";
    rev = "dbdbe34c843677df721c7b3fc3e32c0f737e7e95";
    hash = "sha256-Xi5sPU2RGkqh7T+EOvwxJJKKYDhJfccyEZ8LBBTb2s4=";
  };

  nativeBuildInputs = [ qmake pkg-config qttools wrapQtAppsHook ];
  buildInputs = [
    qtbase
    qtsvg
    qtserialport
    qt5compat
    boost
    libgit2
    quazip
    libngspice
    clipper
  ] ++ lib.optionals stdenv.isLinux [
    qtwayland
  ];

  postPatch = ''
    # Use packaged quazip, libgit and ngspice
    sed -i "/pri\/quazipdetect.pri/d" phoenix.pro
    sed -i "/pri\/spicedetect.pri/d" phoenix.pro
    substituteInPlace pri/libgit2detect.pri \
      --replace-fail 'LIBGIT_STATIC = true' 'LIBGIT_STATIC = false'

    #TODO: Do not hardcode SHA.
    substituteInPlace src/fapplication.cpp \
      --replace-fail 'PartsChecker::getSha(dir.absolutePath());' '"${partsSha}";'

    substituteInPlace phoenix.pro \
      --replace-fail "6.5.10" "${qtbase.version}"

    mkdir parts
    cp -a ${parts}/* parts/
  '';

  env.NIX_CFLAGS_COMPILE = lib.concatStringsSep " " [
    "-I${lib.getDev quazip}/include/QuaZip-Qt${lib.versions.major qtbase.version}-${quazip.version}"
    "-I${svgpp}/include"
    "-I${clipper}/include/polyclipping"
  ];
  env.NIX_LDFLAGS = "-lquazip1-qt${lib.versions.major qtbase.version}";

  qmakeFlags = [
    "phoenix.pro"
  ];

  postInstall = lib.optionalString stdenv.isDarwin ''
    mkdir $out/Applications
    mv $out/bin/Fritzing.app $out/Applications/Fritzing.app
    cp FritzingInfo.plist $out/Applications/Fritzing.app/Contents/Info.plist
    makeWrapper $out/Applications/Fritzing.app/Contents/MacOS/Fritzing $out/bin/Fritzing
  '';

  postFixup = ''
    # generate the parts.db file
    QT_QPA_PLATFORM=offscreen "$out/bin/Fritzing" \
      -db "$out/share/fritzing/parts/parts.db" \
      -pp "$out/share/fritzing/parts" \
      -folder "$out/share/fritzing"
  '';

  meta = with lib; {
    description = "An open source prototyping tool for Arduino-based projects";
    homepage = "https://fritzing.org/";
    license = with licenses; [ gpl3 cc-by-sa-30 ];
    maintainers = with maintainers; [ robberer muscaln ];
    platforms = platforms.unix;
    mainProgram = "Fritzing";
  };
}