summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/li/libproxy/package.nix
blob: 640beee9e97e82fd8b05b2e54638e68e87824c61 (plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
{
  lib,
  _experimental-update-script-combinators,
  curl,
  duktape,
  fetchFromGitHub,
  gi-docgen,
  gitUpdater,
  glib,
  gobject-introspection,
  gsettings-desktop-schemas,
  makeHardcodeGsettingsPatch,
  meson,
  ninja,
  pkg-config,
  stdenv,
  replaceVars,
  vala,
  buildPackages,
  withIntrospection ?
    lib.meta.availableOn stdenv.hostPlatform gobject-introspection
    && stdenv.hostPlatform.emulatorAvailable buildPackages,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "libproxy";
  version = "0.5.12";

  outputs = [
    "out"
    "dev"
  ]
  ++ lib.optionals withIntrospection [
    "devdoc"
  ];

  src = fetchFromGitHub {
    owner = "libproxy";
    repo = "libproxy";
    tag = finalAttrs.version;
    hash = "sha256-pkvmeD7O2EUDzw59/e7YcgiHDf2vvIXmd11axGSwCEs=";
  };

  patches = [
  ]
  ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
    # Disable schema presence detection, it would fail because it cannot be autopatched,
    # and it will be hardcoded by the next patch anyway.
    ./skip-gsettings-detection.patch

    # Hardcode path to Settings schemas for GNOME & related desktops.
    # Otherwise every app using libproxy would need to be wrapped individually.
    (replaceVars ./hardcode-gsettings.patch {
      gds = glib.getSchemaPath gsettings-desktop-schemas;
    })
  ];

  postPatch = ''
    # Fix running script that will try to install git hooks.
    # Though it will not do anything since we do not keep .git/ directory.
    # https://github.com/libproxy/libproxy/issues/262
    chmod +x data/install-git-hook.sh
    patchShebangs data/install-git-hook.sh

    # Fix include-path propagation in non-static builds.
    # https://github.com/libproxy/libproxy/pull/239#issuecomment-2056620246
    substituteInPlace src/libproxy/meson.build \
      --replace-fail "requires_private: 'gobject-2.0'" "requires: 'gobject-2.0'"
  '';

  nativeBuildInputs = [
    meson
    ninja
    pkg-config
  ]
  ++ lib.optionals withIntrospection [
    gi-docgen
    gobject-introspection
    vala
  ];

  buildInputs = [
    curl
    duktape
  ]
  ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
    glib
    gsettings-desktop-schemas
  ];

  mesonFlags = [
    # Prevent installing commit hook.
    "-Drelease=true"
    (lib.mesonBool "docs" withIntrospection)
    (lib.mesonBool "introspection" withIntrospection)
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    "-Dconfig-gnome=false"
  ];

  doCheck = !stdenv.hostPlatform.isDarwin;

  postFixup = ''
    # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
    moveToOutput "share/doc" "$devdoc"
  '';

  passthru = {
    hardcodeGsettingsPatch = makeHardcodeGsettingsPatch {
      schemaIdToVariableMapping = {
        "org.gnome.system.proxy" = "gds";
        "org.gnome.system.proxy.http" = "gds";
        "org.gnome.system.proxy.https" = "gds";
        "org.gnome.system.proxy.ftp" = "gds";
        "org.gnome.system.proxy.socks" = "gds";
      };
      inherit (finalAttrs) src;
    };

    updateScript =
      let
        updateSource = gitUpdater { };
        updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "libproxy.hardcodeGsettingsPatch" ./hardcode-gsettings.patch;
      in
      _experimental-update-script-combinators.sequence [
        updateSource
        updatePatch
      ];
  };

  meta = {
    description = "Library that provides automatic proxy configuration management";
    homepage = "https://libproxy.github.io/libproxy/";
    license = lib.licenses.lgpl21Plus;
    platforms = lib.platforms.linux ++ lib.platforms.darwin;
    badPlatforms = [
      # Mandatory libpxbackend-1.0 shared library.
      lib.systems.inspect.platformPatterns.isStatic
    ];
    mainProgram = "proxy";
  };
})