anchor.diff:      };
     };
   
  -  config = mkIf cfg.enable {
  +  config = mkIf cfg.enable (
  +  let
  +    manageGitoliteRc = cfg.extraGitoliteRc != "";
  +    rcDir = pkgs.runCommand "gitolite-rc" { } rcDirScript;
  +    rcDirScript =
  +      ''
  +        mkdir "$out"
  +        export HOME=temp-home
  +        mkdir -p "$HOME/.gitolite/logs" # gitolite can't run without it
  +        '${pkgs.gitolite}'/bin/gitolite print-default-rc >>"$out/gitolite.rc.default"
  +        cat <<END >>"$out/gitolite.rc"
  +        # This file is managed by NixOS.
  +        # Use services.gitolite options to control it.
  +
  +        END
  +        cat "$out/gitolite.rc.default" >>"$out/gitolite.rc"
  +      '' +
  +      optionalString (cfg.extraGitoliteRc != "") ''
  +        echo -n ${escapeShellArg ''
  +
  +          # Added by NixOS:
  +          ${removeSuffix "\n" cfg.extraGitoliteRc}
  +
  +          # per perl rules, this should be the last line in such a file:
  +          1;
  +        ''} >>"$out/gitolite.rc"
  +      '';
  +  in {
       users.extraUsers.${cfg.user} = {
         description     = "Gitolite user";
         home            = cfg.dataDir;
  
positive.code:       serviceConfig.Type = "oneshot";
        serviceConfig.RemainAfterExit = true;
  
        path = [ pkgs.gitolite pkgs.git pkgs.perl pkgs.bash config.programs.ssh.package ];
        script = ''
          cd ${cfg.dataDir}
          mkdir -p .gitolite/logs
          if [ ! -d repositories ]; then
            gitolite setup -pk ${pubkeyFile}
          fi
          if [ -n "${hooks}" ]; then
            cp ${hooks} .gitolite/hooks/common/
            chmod +x .gitolite/hooks/common/*
          fi
          gitolite setup # Upgrade if needed
        '';
      };
  
      environment.systemPackages = [ pkgs.gitolite pkgs.git ];
    };
  }
  
negative.code:         '';
        };
  
        extraGitoliteRc = mkOption {
          type = types.lines;
          default = "";
          example = literalExample ''
            $RC{UMASK} = 0027;
            $RC{SITE_INFO} = 'This is our private repository host';
            push( @{$RC{ENABLE}}, 'Kindergarten' ); # enable the command/feature
            @{$RC{ENABLE}} = grep { $_ ne 'desc' } @{$RC{ENABLE}}; # disable the command/feature
          '';
          description = ''
            Extra configuration to append to the default <literal>~/.gitolite.rc</literal>.
  
            This should be Perl code that modifies the <literal>%RC</literal>
            configuration variable. The default <literal>~/.gitolite.rc</literal>
            content is generated by invoking <literal>gitolite print-default-rc</literal>,
            and extra configuration from this option is appended to it. The result
            is placed to Nix store, and the <literal>~/.gitolite.rc</literal> file
            becomes a symlink to it.
  
            If you already have a customized (or otherwise changed)
            <literal>~/.gitolite.rc</literal> file, NixOS will refuse to replace
            it with a symlink, and the `gitolite-init` initialization service
            will fail. In this situation, in order to use this option, you
            will need to take any customizations you may have in
            <literal>~/.gitolite.rc</literal>, convert them to appropriate Perl
            statements, add them to this option, and remove the file.
          '';
        };
  
        user = mkOption {
          type = types.str;
          default = "gitolite";
  