at 23.05-pre 3.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.garage; 7 toml = pkgs.formats.toml {}; 8 configFile = toml.generate "garage.toml" cfg.settings; 9in 10{ 11 meta.maintainers = [ maintainers.raitobezarius ]; 12 13 options.services.garage = { 14 enable = mkEnableOption (lib.mdDoc "Garage Object Storage (S3 compatible)"); 15 16 extraEnvironment = mkOption { 17 type = types.attrsOf types.str; 18 description = lib.mdDoc "Extra environment variables to pass to the Garage server."; 19 default = {}; 20 example = { RUST_BACKTRACE="yes"; }; 21 }; 22 23 logLevel = mkOption { 24 type = types.enum (["info" "debug" "trace"]); 25 default = "info"; 26 example = "debug"; 27 description = lib.mdDoc "Garage log level, see <https://garagehq.deuxfleurs.fr/documentation/quick-start/#launching-the-garage-server> for examples."; 28 }; 29 30 settings = mkOption { 31 type = types.submodule { 32 freeformType = toml.type; 33 34 options = { 35 metadata_dir = mkOption { 36 default = "/var/lib/garage/meta"; 37 type = types.path; 38 description = lib.mdDoc "The metadata directory, put this on a fast disk (e.g. SSD) if possible."; 39 }; 40 41 data_dir = mkOption { 42 default = "/var/lib/garage/data"; 43 type = types.path; 44 description = lib.mdDoc "The main data storage, put this on your large storage (e.g. high capacity HDD)"; 45 }; 46 47 replication_mode = mkOption { 48 default = "none"; 49 type = types.enum ([ "none" "1" "2" "3" 1 2 3 ]); 50 apply = v: toString v; 51 description = lib.mdDoc "Garage replication mode, defaults to none, see: <https://garagehq.deuxfleurs.fr/reference_manual/configuration.html#replication_mode> for reference."; 52 }; 53 }; 54 }; 55 description = lib.mdDoc "Garage configuration, see <https://garagehq.deuxfleurs.fr/reference_manual/configuration.html> for reference."; 56 }; 57 58 package = mkOption { 59 default = pkgs.garage; 60 defaultText = literalExpression "pkgs.garage"; 61 type = types.package; 62 description = lib.mdDoc "Garage package to use."; 63 }; 64 }; 65 66 config = mkIf cfg.enable { 67 environment.etc."garage.toml" = { 68 source = configFile; 69 }; 70 71 environment.systemPackages = [ cfg.package ]; # For administration 72 73 systemd.services.garage = { 74 description = "Garage Object Storage (S3 compatible)"; 75 after = [ "network.target" "network-online.target" ]; 76 wants = [ "network.target" "network-online.target" ]; 77 wantedBy = [ "multi-user.target" ]; 78 serviceConfig = { 79 ExecStart = "${cfg.package}/bin/garage server"; 80 81 StateDirectory = mkIf (hasPrefix "/var/lib/garage" cfg.settings.data_dir && hasPrefix "/var/lib/garage" cfg.settings.metadata_dir) "garage"; 82 DynamicUser = lib.mkDefault true; 83 ProtectHome = true; 84 NoNewPrivileges = true; 85 }; 86 environment = { 87 RUST_LOG = lib.mkDefault "garage=${cfg.logLevel}"; 88 } // cfg.extraEnvironment; 89 }; 90 }; 91}