at 18.03-beta 1.7 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.dockerRegistry; 7 8in { 9 options.services.dockerRegistry = { 10 enable = mkEnableOption "Docker Registry"; 11 12 listenAddress = mkOption { 13 description = "Docker registry host or ip to bind to."; 14 default = "127.0.0.1"; 15 type = types.str; 16 }; 17 18 port = mkOption { 19 description = "Docker registry port to bind to."; 20 default = 5000; 21 type = types.int; 22 }; 23 24 storagePath = mkOption { 25 type = types.path; 26 default = "/var/lib/docker-registry"; 27 description = "Docker registry storage path."; 28 }; 29 30 extraConfig = mkOption { 31 description = '' 32 Docker extra registry configuration via environment variables. 33 ''; 34 default = {}; 35 type = types.attrsOf types.str; 36 }; 37 }; 38 39 config = mkIf cfg.enable { 40 systemd.services.docker-registry = { 41 description = "Docker Container Registry"; 42 wantedBy = [ "multi-user.target" ]; 43 after = [ "network.target" ]; 44 45 environment = { 46 REGISTRY_HTTP_ADDR = "${cfg.listenAddress}:${toString cfg.port}"; 47 REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY = cfg.storagePath; 48 } // cfg.extraConfig; 49 50 script = '' 51 ${pkgs.docker-distribution}/bin/registry serve \ 52 ${pkgs.docker-distribution.out}/share/go/src/github.com/docker/distribution/cmd/registry/config-example.yml 53 ''; 54 55 serviceConfig = { 56 User = "docker-registry"; 57 WorkingDirectory = cfg.storagePath; 58 }; 59 }; 60 61 users.extraUsers.docker-registry = { 62 createHome = true; 63 home = cfg.storagePath; 64 }; 65 }; 66}