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