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](https://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](https://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
24{
25 services.httpd.enable = true;
26 services.httpd.adminAddr = "...";
27 networking.firewall.allowedTCPPorts = [
28 80
29 443
30 ];
31}
32```
33
34For a simple Subversion server with basic authentication, configure the
35Subversion module for Apache as follows, setting `hostName` and
36`documentRoot` appropriately, and `SVNParentPath` to the parent
37directory of the repositories, `AuthzSVNAccessFile` to the location of
38the `.authz` file describing access permission, and `AuthUserFile` to
39the password file.
40
41```nix
42{
43 services.httpd.extraModules = [
44 # note that order is *super* important here
45 {
46 name = "dav_svn";
47 path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_dav_svn.so";
48 }
49 {
50 name = "authz_svn";
51 path = "${pkgs.apacheHttpdPackages.subversion}/modules/mod_authz_svn.so";
52 }
53 ];
54 services.httpd.virtualHosts = {
55 "svn" = {
56 hostName = HOSTNAME;
57 documentRoot = DOCUMENTROOT;
58 locations."/svn".extraConfig = ''
59 DAV svn
60 SVNParentPath REPO_PARENT
61 AuthzSVNAccessFile ACCESS_FILE
62 AuthName "SVN Repositories"
63 AuthType Basic
64 AuthUserFile PASSWORD_FILE
65 Require valid-user
66 '';
67 };
68 };
69}
70```
71
72The key `"svn"` is just a symbolic name identifying the virtual host.
73The `"/svn"` in `locations."/svn".extraConfig` is the path underneath
74which the repositories will be served.
75
76[This page](https://wiki.archlinux.org/index.php/Subversion) explains
77how to set up the Subversion configuration itself. This boils down to
78the following:
79
80Underneath `REPO_PARENT` repositories can be set up as follows:
81
82```ShellSession
83$ svn create REPO_NAME
84```
85
86Repository files need to be accessible by `wwwrun`:
87
88```ShellSession
89$ chown -R wwwrun:wwwrun REPO_PARENT
90```
91
92The password file `PASSWORD_FILE` can be created as follows:
93
94```ShellSession
95$ htpasswd -cs PASSWORD_FILE USER_NAME
96```
97
98Additional users can be set up similarly, omitting the `c` flag:
99
100```ShellSession
101$ htpasswd -s PASSWORD_FILE USER_NAME
102```
103
104The file describing access permissions `ACCESS_FILE` will look something
105like the following:
106
107```
108[/]
109* = r
110
111[REPO_NAME:/]
112USER_NAME = rw
113```
114
115The Subversion repositories will be accessible as
116`http://HOSTNAME/svn/REPO_NAME`.