anchor.diff:  let
     cfg = config.homebrew;
   
  -  brewfileSection = heading: type: entries: optionalString (entries != [])
  -    "# ${heading}\n" + (concatMapStrings (name: "${type} \"${name}\"\n") entries) + "\n";
  -
  -  masBrewfileSection = entries: optionalString (entries != {}) (
  +  mkBrewfileSectionString = heading: type: entries: optionalString (entries != []) ''
  +    # ${heading}
  +    ${concatMapStringsSep "\n" (v: v.brewfileLine or ''${type} "${v}"'') entries}
  +
  +  '';
  +
  +  mkMasBrewfileSectionString = entries: optionalString (entries != {}) (
       "# Mac App Store apps\n" +
       concatStringsSep "\n" (mapAttrsToList (name: id: ''mas "${name}", id: ${toString id}'') entries) +
       "\n"
     );
   
  +
     brewfile = pkgs.writeText "Brewfile" (
  -    brewfileSection "Taps" "tap" cfg.taps +
  -    (if cfg.caskArgs.brewfileLine == null then "" else "# Arguments for all casks\n${cfg.caskArgs.brewfileLine}\n\n") +
  -    brewfileSection "Brews" "brew" cfg.brews +
  -    brewfileSection "Casks" "cask" cfg.casks +
  -    masBrewfileSection cfg.masApps +
  -    brewfileSection "Docker containers" "whalebrew" cfg.whalebrews +
  +    mkBrewfileSectionString "Taps" "tap" cfg.taps +
  +    mkBrewfileSectionString "Arguments for all casks" "cask_args"
  +      (optional (cfg.caskArgs.brewfileLine != null) cfg.caskArgs) +
  +    mkBrewfileSectionString "Brews" "brew" cfg.brews +
  +    mkBrewfileSectionString "Casks" "cask" cfg.casks +
  +    mkMasBrewfileSectionString cfg.masApps +
  +    mkBrewfileSectionString "Docker containers" "whalebrew" cfg.whalebrews +
       optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig)
     );
   
  
positive.code:       type = types.lines;
        default = "";
        example = ''
          # 'brew tap' with custom Git URL
          tap "user/tap-repo", "https://user@bitbucket.org/user/homebrew-tap-repo.git"
  
          # 'brew install --with-rmtp', 'brew services restart' on version changes
          brew "denji/nginx/nginx-full", args: ["with-rmtp"], restart_service: :changed
          # 'brew install', always 'brew services restart', 'brew link', 'brew unlink mysql' (if it is installed)
  
negative.code:     };
  
      taps = mkOption {
        type = with types; listOf (coercedTo str (name: { inherit name; }) (submodule tapOptions));
        default = [];
        example = literalExpression ''
          # Adapted examples from https://github.com/Homebrew/homebrew-bundle#usage
          [
            # 'brew tap'
            "homebrew/cask"
            # 'brew tap' with custom Git URL and arguments
            {
              name = "user/tap-repo";
              clone_target = "https://user@bitbucket.org/user/homebrew-tap-repo.git";
              force_auto_update = true;
            }
          ]
        '';
        description = ''
          Homebrew formula repositories to tap.
  
          Taps defined as strings, e.g., <literal>"user/repo"</literal>, are a shorthand for:
  
          <code>{ name = "user/repo"; }</code>
        '';
      };
  
      brews = mkOption {
  