1# Subversion {#module-services-subversion}
2
3[Subversion](https://subversion.apache.org/) is a centralized
4version-control system. It can use a [variety of
5protocols](http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.serverconfig.choosing)
6for communication between client and server.
7
8## Subversion inside Apache HTTP {#module-services-subversion-apache-httpd}
9
10This section focuses on configuring a web-based server on top of the
11Apache HTTP server, which uses
12[WebDAV](http://www.webdav.org/)/[DeltaV](http://www.webdav.org/deltav/WWW10/deltav-intro.htm)
13for communication.
14
15For more information on the general setup, please refer to the [the
16appropriate section of the Subversion
17book](http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.serverconfig.httpd).
18
19To configure, include in `/etc/nixos/configuration.nix` code to activate
20Apache HTTP, setting [](#opt-services.httpd.adminAddr)
21appropriately:
22
23```nix
24services.httpd.enable = true;
25services.httpd.adminAddr = ...;
26networking.firewall.allowedTCPPorts = [ 80 443 ];
27```
28
29For a simple Subversion server with basic authentication, configure the
30Subversion module for Apache as follows, setting `hostName` and
31`documentRoot` appropriately, and `SVNParentPath` to the parent
32directory of the repositories, `AuthzSVNAccessFile` to the location of
33the `.authz` file describing access permission, and `AuthUserFile` to
34the password file.
35
36```nix
37services.httpd.extraModules = [
38 # note that order is *super* important here
39 { name = "dav_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so"; }
40 { name = "authz_svn"; path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so"; }
41 ];
42 services.httpd.virtualHosts = {
43 "svn" = {
44 hostName = HOSTNAME;
45 documentRoot = DOCUMENTROOT;
46 locations."/svn".extraConfig = ''
47 DAV svn
48 SVNParentPath REPO_PARENT
49 AuthzSVNAccessFile ACCESS_FILE
50 AuthName "SVN Repositories"
51 AuthType Basic
52 AuthUserFile PASSWORD_FILE
53 Require valid-user
54 '';
55 }
56```
57
58The key `"svn"` is just a symbolic name identifying the virtual host.
59The `"/svn"` in `locations."/svn".extraConfig` is the path underneath
60which the repositories will be served.
61
62[This page](https://wiki.archlinux.org/index.php/Subversion) explains
63how to set up the Subversion configuration itself. This boils down to
64the following:
65
66Underneath `REPO_PARENT` repositories can be set up as follows:
67
68```ShellSession
69$ svn create REPO_NAME
70```
71
72Repository files need to be accessible by `wwwrun`:
73
74```ShellSession
75$ chown -R wwwrun:wwwrun REPO_PARENT
76```
77
78The password file `PASSWORD_FILE` can be created as follows:
79
80```ShellSession
81$ htpasswd -cs PASSWORD_FILE USER_NAME
82```
83
84Additional users can be set up similarly, omitting the `c` flag:
85
86```ShellSession
87$ htpasswd -s PASSWORD_FILE USER_NAME
88```
89
90The file describing access permissions `ACCESS_FILE` will look something
91like the following:
92
93```nix
94[/]
95* = r
96
97[REPO_NAME:/]
98USER_NAME = rw
99```
100
101The Subversion repositories will be accessible as
102`http://HOSTNAME/svn/REPO_NAME`.