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 = "svn.active-group.de";
    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!

Regards,
Mike

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 = "admin@example.net";
  services.httpd.extraModules = [
    # note that order is *super* important here
    { name = "dav_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so"; }
    { name = "authz_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so"; }
  ];
  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
        </Location>
      '';
    }
  ];

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

[nix-projects:/]
aanderse = rw
EOT

# 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!