1{ 2 runCommand, 3 gitMinimal, 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 - `schemaExistsFunction`: name of the function that is used for checking 31 if optional schema exists. Its invocation will be replaced with TRUE 32 for known schemas. 33 34 - `patches`: A list of patches to apply before generating the patch. 35 36 Example: 37 passthru = { 38 hardcodeGsettingsPatch = makeHardcodeGsettingsPatch { 39 inherit (finalAttrs) src; 40 schemaIdToVariableMapping = { 41 ... 42 }; 43 }; 44 45 updateScript = 46 let 47 updateSource = ...; 48 updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; 49 in 50 _experimental-update-script-combinators.sequence [ 51 updateSource 52 updatePatch 53 ]; 54 }; 55 } 56*/ 57{ 58 src, 59 patches ? [ ], 60 schemaIdToVariableMapping, 61 schemaExistsFunction ? null, 62}: 63 64runCommand "hardcode-gsettings.patch" 65 { 66 inherit src patches; 67 nativeBuildInputs = [ 68 gitMinimal 69 coccinelle 70 python3 # For patch script 71 ]; 72 } 73 '' 74 unpackPhase 75 cd "''${sourceRoot:-.}" 76 patchPhase 77 set -x 78 cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json 79 cp ${builtins.toFile "glib-schema-exists-function.json" (builtins.toJSON schemaExistsFunction)} ./glib-schema-exists-function.json 80 git init 81 git add -A 82 spatch --sp-file "${./hardcode-gsettings.cocci}" --dir . --in-place 83 git diff > "$out" 84 ''