1{
2 runCommand,
3 git,
4 coccinelle,
5 python3,
6}:
7
8/*
9 Creates a patch that replaces every instantiation of GSettings in a C project
10 with a code that loads a GSettings schema from a hardcoded path.
11
12 This is useful so that libraries can find schemas even though Nix lacks
13 a standard location like /usr/share, where GSettings system could look for schemas.
14 The derivation is is somewhat dependency-heavy so it is best used as part of an update script.
15
16 For each schema id referenced in the source code (e.g. org.gnome.evolution),
17 a variable name such as `EVOLUTION` must be provided.
18 It will end up in the generated patch as `@EVOLUTION@` placeholder, which should be replaced at build time
19 with a path to the directory containing a `gschemas.compiled` file that includes the schema.
20
21 Arguments:
22 - `src`: source to generate the patch for.
23
24 - `schemaIdToVariableMapping`: attrset assigning schema ids to variable names.
25 All used schemas must be listed.
26
27 For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }`
28 hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`.
29
30 - `patches`: A list of patches to apply before generating the patch.
31
32 Example:
33 passthru = {
34 hardcodeGsettingsPatch = makeHardcodeGsettingsPatch {
35 inherit (finalAttrs) src;
36 schemaIdToVariableMapping = {
37 ...
38 };
39 };
40
41 updateScript =
42 let
43 updateSource = ...;
44 updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch;
45 in
46 _experimental-update-script-combinators.sequence [
47 updateSource
48 updatePatch
49 ];
50 };
51 }
52*/
53{
54 src,
55 patches ? [ ],
56 schemaIdToVariableMapping,
57}:
58
59runCommand "hardcode-gsettings.patch"
60 {
61 inherit src patches;
62 nativeBuildInputs = [
63 git
64 coccinelle
65 python3 # For patch script
66 ];
67 }
68 ''
69 unpackPhase
70 cd "''${sourceRoot:-.}"
71 patchPhase
72 set -x
73 cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json
74 git init
75 git add -A
76 spatch --sp-file "${./hardcode-gsettings.cocci}" --dir . --in-place
77 git diff > "$out"
78 ''