anchor.diff:          if ! test -e "${cfg.statePath}/db-seeded"; then
             ${pkgs.sudo}/bin/sudo -u ${cfg.user} ${gitlab-rake}/bin/gitlab-rake db:seed_fu \
               GITLAB_ROOT_PASSWORD='${cfg.initialRootPassword}' GITLAB_ROOT_EMAIL='${cfg.initialRootEmail}'
  -          touch "${cfg.statePath}/db-seeded"
  +          ${pkgs.sudo}/bin/sudo -u ${cfg.user} touch "${cfg.statePath}/db-seeded"
           fi
   
  -        # The gitlab:shell:create_hooks task seems broken for fixing links
  -        # so we instead delete all the hooks and create them anew
  +        # We remove potentially broken links to old gitlab-shell versions
           rm -f ${cfg.statePath}/repositories/**/*.git/hooks
  -        ${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${gitlab-rake}/bin/gitlab-rake gitlab:shell:create_hooks
   
           ${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${pkgs.git}/bin/git config --global core.autocrlf "input"
  -
  -        # Change permissions in the last step because some of the
  -        # intermediary scripts like to create directories as root.
  -        chmod -R u+rwX,go-rwx+X ${gitlabEnv.HOME}
  -        chmod -R ug+rwX,o-rwx ${cfg.statePath}/repositories
  -        chmod -R ug-s ${cfg.statePath}/repositories
  -        find ${cfg.statePath}/repositories -type d -print0 | xargs -0 chmod g+s
         '';
   
         serviceConfig = {
  
positive.code: 
            ${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${gitlab-rake}/bin/gitlab-rake db:schema:load
  
            touch "${cfg.statePath}/db-created"
          fi
  
          # Always do the db migrations just to be sure the database is up-to-date
  
negative.code:         gnupg
        ];
        preStart = ''
          ${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -f ${cfg.packages.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
          ${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -rf ${cfg.packages.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
          ${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -rf ${cfg.packages.gitlab}/share/gitlab/db/* ${cfg.statePath}/db
          ${pkgs.sudo}/bin/sudo -u ${cfg.user} chmod u+w ${cfg.statePath}/db/*
  
          ${pkgs.openssl}/bin/openssl rand -hex 32 > ${cfg.statePath}/config/gitlab_shell_secret
  
          ${pkgs.sudo}/bin/sudo -u ${cfg.user} ${cfg.packages.gitlab-shell}/bin/install
  
          if ! test -e "${cfg.statePath}/db-created"; then
            if [ "${cfg.databaseHost}" = "127.0.0.1" ]; then
  