at 24.11-pre 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 inherit (lib) escapeShellArgs mkEnableOption mkPackageOption mkIf mkOption types; 5 6 cfg = config.services.mimir; 7 8 settingsFormat = pkgs.formats.yaml {}; 9in { 10 options.services.mimir = { 11 enable = mkEnableOption "mimir"; 12 13 configuration = mkOption { 14 type = (pkgs.formats.json {}).type; 15 default = {}; 16 description = '' 17 Specify the configuration for Mimir in Nix. 18 ''; 19 }; 20 21 configFile = mkOption { 22 type = types.nullOr types.path; 23 default = null; 24 description = '' 25 Specify a configuration file that Mimir should use. 26 ''; 27 }; 28 29 package = mkPackageOption pkgs "mimir" { }; 30 31 extraFlags = mkOption { 32 type = types.listOf types.str; 33 default = []; 34 example = [ "--config.expand-env=true" ]; 35 description = '' 36 Specify a list of additional command line flags, 37 which get escaped and are then passed to Mimir. 38 ''; 39 }; 40 }; 41 42 config = mkIf cfg.enable { 43 # for mimirtool 44 environment.systemPackages = [ cfg.package ]; 45 46 assertions = [{ 47 assertion = ( 48 (cfg.configuration == {} -> cfg.configFile != null) && 49 (cfg.configFile != null -> cfg.configuration == {}) 50 ); 51 message = '' 52 Please specify either 53 'services.mimir.configuration' or 54 'services.mimir.configFile'. 55 ''; 56 }]; 57 58 systemd.services.mimir = { 59 description = "mimir Service Daemon"; 60 wantedBy = [ "multi-user.target" ]; 61 62 serviceConfig = let 63 conf = if cfg.configFile == null 64 then settingsFormat.generate "config.yaml" cfg.configuration 65 else cfg.configFile; 66 in 67 { 68 ExecStart = "${cfg.package}/bin/mimir --config.file=${conf} ${escapeShellArgs cfg.extraFlags}"; 69 DynamicUser = true; 70 Restart = "always"; 71 ProtectSystem = "full"; 72 DevicePolicy = "closed"; 73 NoNewPrivileges = true; 74 WorkingDirectory = "/var/lib/mimir"; 75 StateDirectory = "mimir"; 76 }; 77 }; 78 }; 79}