| 1 | # This is a "service unit file" for the systemd init system to launch |
| 2 | # 'guix-daemon'. Drop it in /etc/systemd/system or similar to have |
| 3 | # 'guix-daemon' automatically started. |
| 4 | |
| 5 | [Unit] |
| 6 | Description=Build daemon for GNU Guix |
| 7 | |
| 8 | # Start before 'gnu-store.mount' to get a writable view of the store. |
| 9 | Before=gnu-store.mount |
| 10 | |
| 11 | [Service] |
| 12 | ExecStart=@localstatedir@/guix/profiles/per-user/root/current-guix/bin/guix-daemon \ |
| 13 | --discover=no \ |
| 14 | --substitute-urls='@GUIX_SUBSTITUTE_URLS@' |
| 15 | Environment='GUIX_STATE_DIRECTORY=@localstatedir@/guix' 'GUIX_LOCPATH=@localstatedir@/guix/profiles/per-user/root/guix-profile/lib/locale' LC_ALL=en_US.utf8 |
| 16 | |
| 17 | # Stop the gnu-store.mount so that the daemon can capture the store as |
| 18 | # read-write in its private mount namespace. |
| 19 | # See <https://codeberg.org/guix/guix/issues/4744>. |
| 20 | ExecStartPre=-+systemctl stop gnu-store.mount |
| 21 | ExecStartPost=-+systemctl start gnu-store.mount --no-block |
| 22 | |
| 23 | # Run under a dedicated unprivileged user account. |
| 24 | User=guix-daemon |
| 25 | |
| 26 | # Bind-mount the store read-write in a private namespace, to counter the |
| 27 | # effect of 'gnu-store.mount'. |
| 28 | PrivateMounts=true |
| 29 | BindPaths=@storedir@ |
| 30 | # Disable host file system mount propagation to keep service view of the |
| 31 | # store read-write after 'gnu-store.mount' makes it read-only system-wide. |
| 32 | MountFlags=private |
| 33 | # Mitigate race condition between guix-daemon and 'gnu-store.mount'. |
| 34 | # Dependent units will only start after daemon binary is started AND THUS |
| 35 | # the mount point is acquired in a private namespace. |
| 36 | Type=exec |
| 37 | |
| 38 | # Provide the CAP_CHOWN capability so that guix-daemon can create and chown |
| 39 | # /var/guix/profiles/per-user/$USER and also chown failed build directories |
| 40 | # when using '--keep-failed'. Note that guix-daemon explicitly drops ambient |
| 41 | # capabilities before executing build processes so they don't inherit them. |
| 42 | AmbientCapabilities=CAP_CHOWN |
| 43 | |
| 44 | StandardOutput=journal |
| 45 | StandardError=journal |
| 46 | |
| 47 | # Work around a nasty systemd ‘feature’ that kills the entire process tree |
| 48 | # (including the daemon!) if any child, such as cc1plus, runs out of memory. |
| 49 | OOMPolicy=continue |
| 50 | |
| 51 | # Despite the name, this is rate-limited: a broken daemon will eventually fail. |
| 52 | Restart=always |
| 53 | |
| 54 | # See <https://lists.gnu.org/archive/html/guix-devel/2016-04/msg00608.html>. |
| 55 | # Some package builds (for example, [email protected]) may require even more than |
| 56 | # 1024 tasks. |
| 57 | TasksMax=8192 |
| 58 | |
| 59 | [Install] |
| 60 | WantedBy=multi-user.target |