How to set up Subversion / HTTP server

I’m trying to figure out how to set up a Subversion HTTP server from inside Apache, and am failing.

Roughly, I’m trying this:

  services.httpd.extraSubservices = [ {
    siteName = "";
    urlPrefix = "/svn";
    dataDir = "/var/svn";
  } ];

Now, for the “…”, I’ve tried serviceType = "subversion" (analogously to the Wiki page on Mediawiki), and function = import <services/subversion>;, as per:

Both don’t work, the latter gives me:

error: file 'services/subversion' was not found in the Nix search path (add it using $NIX_PATH or -I), at /etc/nixos/configuration.nix:88:23
(use '--show-trace' to show detailed location information)

Help would be much appreciated!


Hi Mike,

I think the subversion sub service disappeared some time ago. I’d have to dig through git history to find out exactly when, but at whatever point it disappeared that test wasn’t cleaned up and was just removed recently.

What version of NixOS are you running? The services.httpd.extraSubservices option has been deprecated on NixOS stable and removed in unstable, so you want to avoid that.

I don’t do much in the way of subversion these days so I had to take a quick look at a guide on ArchWiki to remind myself of how to do this, but it basically boils down to this, assuming NixOS 19.09:

  services.httpd.enable = true;
  services.httpd.adminAddr = "";
  services.httpd.extraModules = [
    # note that order is *super* important here
    { name = "dav_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/"; }
    { name = "authz_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/"; }
  services.httpd.virtualHosts = [
    { hostName = "localhost";
      documentRoot = "${pkgs.apacheHttpd}/htdocs";
      extraConfig = ''
        <Location /svn>
          DAV svn
          SVNParentPath /srv/svn/repositories
          AuthzSVNAccessFile /srv/svn/.svn-policy-file
          AuthName "SVN Repositories"
          AuthType Basic
          AuthUserFile /srv/svn/.svn-auth-file
          Require valid-user

From here you’ll want to follow this guide, which in summary boils down to:

# create your state directory
mkdir -p /srv/svn/repositories

# define permissions
cat <<EOT > /srv/svn/.svn-policy-file
* = r

aanderse = rw

# create a password file with an entry for aanderse
htpasswd -cs /srv/svn/.svn-auth-file aanderse # enter password for svn when prompted

# create the actual svn repo (server side) which can then be checked out by aanderse
svnadmin create /srv/svn/repositories/nix-projects

# you could probably do a better job with file ownership/permissions here
chown -R wwwrun:wwwrun /srv/svn

Then hit http://localhost/svn/nix-projects/ in your browser to confirm everything is working as expected.

Let me know if you run into any issues.

This worked instantly - many thanks!

OK if I turn this into a piece of documentation and a pull request?

1 Like

Every time someone writes documentation for this project I’m thrilled :slight_smile: Please go ahead, and thank you!

Can you (or somebody else) approve the pull request?