at 25.11-pre 1.8 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 ... 6}: 7 8let 9 inherit (lib) mkOption types; 10 cfg = config.services.nar-serve; 11in 12{ 13 meta = { 14 maintainers = with lib.maintainers; [ 15 rizary 16 zimbatm 17 ]; 18 }; 19 options = { 20 services.nar-serve = { 21 enable = lib.mkEnableOption "serving NAR file contents via HTTP"; 22 23 package = lib.mkPackageOption pkgs "nar-serve" { }; 24 25 port = mkOption { 26 type = types.port; 27 default = 8383; 28 description = '' 29 Port number where nar-serve will listen on. 30 ''; 31 }; 32 33 cacheURL = mkOption { 34 type = types.str; 35 default = "https://cache.nixos.org/"; 36 description = '' 37 Binary cache URL to connect to. 38 39 The URL format is compatible with the nix remote url style, such as: 40 - http://, https:// for binary caches via HTTP or HTTPS 41 - s3:// for binary caches stored in Amazon S3 42 - gs:// for binary caches stored in Google Cloud Storage 43 ''; 44 }; 45 46 domain = mkOption { 47 type = types.str; 48 default = ""; 49 description = '' 50 When set, enables the feature of serving <nar-hash>.<domain> 51 on top of <domain>/nix/store/<nar-hash>-<pname>. 52 53 Useful to preview static websites where paths are absolute. 54 ''; 55 }; 56 }; 57 }; 58 59 config = lib.mkIf cfg.enable { 60 systemd.services.nar-serve = { 61 description = "NAR server"; 62 after = [ "network.target" ]; 63 wantedBy = [ "multi-user.target" ]; 64 65 environment.PORT = toString cfg.port; 66 environment.NAR_CACHE_URL = cfg.cacheURL; 67 68 serviceConfig = { 69 Restart = "always"; 70 RestartSec = "5s"; 71 ExecStart = lib.getExe cfg.package; 72 DynamicUser = true; 73 }; 74 }; 75 }; 76}