From 038497d3b3fee1121c155c2787830e55c8559847 Mon Sep 17 00:00:00 2001 From: Andika Demas Riyandi Date: Sat, 7 Nov 2020 00:59:51 +0700 Subject: nar-serve: init at 0.3.0 (#95420) * nar-serve: init at 0.3.0 * nixos/nar-serve: add new module Co-authored-by: zimbatm --- nixos/modules/services/networking/nar-serve.nix | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 nixos/modules/services/networking/nar-serve.nix (limited to 'nixos/modules/services/networking/nar-serve.nix') diff --git a/nixos/modules/services/networking/nar-serve.nix b/nixos/modules/services/networking/nar-serve.nix new file mode 100644 index 00000000000..ddd42fa0107 --- /dev/null +++ b/nixos/modules/services/networking/nar-serve.nix @@ -0,0 +1,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.int; + 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; + }; + }; + }; +} -- cgit 1.4.1