1{ config, pkgs, lib, ... }:
2
3with lib;
4let
5 cfg = config.services.nar-serve;
6in
7{
8 meta = {
9 maintainers = [ maintainers.rizary ];
10 };
11 options = {
12 services.nar-serve = {
13 enable = mkEnableOption (lib.mdDoc "Serve NAR file contents via HTTP");
14
15 port = mkOption {
16 type = types.port;
17 default = 8383;
18 description = lib.mdDoc ''
19 Port number where nar-serve will listen on.
20 '';
21 };
22
23 cacheURL = mkOption {
24 type = types.str;
25 default = "https://cache.nixos.org/";
26 description = lib.mdDoc ''
27 Binary cache URL to connect to.
28
29 The URL format is compatible with the nix remote url style, such as:
30 - http://, https:// for binary caches via HTTP or HTTPS
31 - s3:// for binary caches stored in Amazon S3
32 - gs:// for binary caches stored in Google Cloud Storage
33 '';
34 };
35 };
36 };
37
38 config = mkIf cfg.enable {
39 systemd.services.nar-serve = {
40 description = "NAR server";
41 after = [ "network.target" ];
42 wantedBy = [ "multi-user.target" ];
43
44 environment.PORT = toString cfg.port;
45 environment.NAR_CACHE_URL = cfg.cacheURL;
46
47 serviceConfig = {
48 Restart = "always";
49 RestartSec = "5s";
50 ExecStart = "${pkgs.nar-serve}/bin/nar-serve";
51 DynamicUser = true;
52 };
53 };
54 };
55}