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 22 Arguments: 23 - `src`: source to generate the patch for. 24 25 - `schemaIdToVariableMapping`: attrset assigning schema ids to variable names. 26 All used schemas must be listed. 27 28 For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }` 29 hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`. 30 31 - `patches`: A list of patches to apply before generating the patch. 32 33 Example: 34 passthru = { 35 hardcodeGsettingsPatch = makeHardcodeGsettingsPatch { 36 inherit (finalAttrs) src; 37 schemaIdToVariableMapping = { 38 ... 39 }; 40 }; 41 42 updateScript = 43 let 44 updateSource = ...; 45 updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; 46 in 47 _experimental-update-script-combinators.sequence [ 48 updateSource 49 updatePatch 50 ]; 51 }; 52 } 53*/ 54{ 55 src, 56 patches ? [ ], 57 schemaIdToVariableMapping, 58}: 59 60runCommand 61 "hardcode-gsettings.patch" 62 { 63 inherit src patches; 64 nativeBuildInputs = [ 65 git 66 coccinelle 67 python3 # For patch script 68 ]; 69 } 70 '' 71 unpackPhase 72 cd "''${sourceRoot:-.}" 73 patchPhase 74 set -x 75 cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json 76 git init 77 git add -A 78 spatch --sp-file "${./hardcode-gsettings.cocci}" --dir . --in-place 79 git diff > "$out" 80 ''