anchor.diff:      EOF
     '' + lib.optionalString fileValidation ''
       echo "Running desktop-file validation"
  -    ${desktop-file-utils}/bin/desktop-file-validate "$out/share/applications/${name}.desktop"
  +    desktop-file-validate "$out/share/applications/${name}.desktop"
     '')
  
positive.code: 
    # Map all entries to a list of lines
    desktopFileStrings =
      ["[Desktop Entry]"]
      ++ builtins.filter
        (v: v != null)
        (lib.mapAttrsToList
          (name: value: if value != null then "${name}=${value}" else null)
          mainSection
        )
      ++ (if extraEntries == "" then [] else ["${extraEntries}"]);
  in
  runCommandLocal "${name}.desktop" {}
    (''
      mkdir -p "$out/share/applications"
      cat > "$out/share/applications/${name}.desktop" <<EOF
  
negative.code: , mimeType ? null
  , categories ? null
  , startupNotify ? null
  , extraDesktopEntries ? { } # Extra key-value pairs to add to the [Desktop Entry] section. This may override other values
  , extraEntries ? "" # Extra configuration. Will be appended to the end of the file and may thus contain extra sections
  , fileValidation ? true # whether to validate resulting desktop file.
  }:
  let
    # like builtins.toString, but null -> null instead of null -> ""
    nullableToString = value:
      if value == null then null
      else if builtins.isBool value then lib.boolToString value
      else builtins.toString value;
  
    # The [Desktop entry] section of the desktop file, as attribute set.
    mainSection = {
  