summary refs log tree commit diff
path: root/nixos/modules/services/networking/nar-serve.nix
blob: 745138186a207839256509dbd4c3de50a5cfaec6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ config, pkgs, lib, ... }:

with lib;
let
  cfg = config.services.nar-serve;
in
{
  meta = {
    maintainers = [ maintainers.rizary ];
  };
  options = {
    services.nar-serve = {
      enable = mkEnableOption "Serve NAR file contents via HTTP";

      port = mkOption {
        type = types.port;
        default = 8383;
        description = ''
          Port number where nar-serve will listen on.
        '';
      };

      cacheURL = mkOption {
        type = types.str;
        default = "https://cache.nixos.org/";
        description = ''
          Binary cache URL to connect to.

          The URL format is compatible with the nix remote url style, such as:
          - http://, https:// for binary caches via HTTP or HTTPS
          - s3:// for binary caches stored in Amazon S3
          - gs:// for binary caches stored in Google Cloud Storage
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.nar-serve = {
      description = "NAR server";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      environment.PORT = toString cfg.port;
      environment.NAR_CACHE_URL = cfg.cacheURL;

      serviceConfig = {
        Restart = "always";
        RestartSec = "5s";
        ExecStart = "${pkgs.nar-serve}/bin/nar-serve";
        DynamicUser = true;
      };
    };
  };
}