at master 2.0 kB view raw
1{ lib, ... }: 2let 3 inherit (lib) 4 concatLists 5 mapAttrsToList 6 showOption 7 types 8 ; 9in 10rec { 11 flattenMapServicesConfigToList = 12 f: loc: config: 13 f loc config 14 ++ concatLists ( 15 mapAttrsToList ( 16 k: v: 17 flattenMapServicesConfigToList f ( 18 loc 19 ++ [ 20 "services" 21 k 22 ] 23 ) v 24 ) config.services 25 ); 26 27 getWarnings = flattenMapServicesConfigToList ( 28 loc: config: map (msg: "in ${showOption loc}: ${msg}") config.warnings 29 ); 30 31 getAssertions = flattenMapServicesConfigToList ( 32 loc: config: 33 map (ass: { 34 message = "in ${showOption loc}: ${ass.message}"; 35 assertion = ass.assertion; 36 }) config.assertions 37 ); 38 39 /** 40 This is the entrypoint for the portable part of modular services. 41 42 It provides the various options that are consumed by service manager implementations. 43 44 # Inputs 45 46 `serviceManagerPkgs`: A Nixpkgs instance which will be used for built-in logic such as converting `configData.<path>.text` to a store path. 47 48 `extraRootModules`: Modules to be loaded into the "root" service submodule, but not into its sub-`services`. That's the modules' own responsibility. 49 50 `extraRootSpecialArgs`: Fixed module arguments that are provided in a similar manner to `extraRootModules`. 51 52 # Output 53 54 An attribute set. 55 56 `serviceSubmodule`: a Module System option type which is a `submodule` with the portable modules and this function's inputs loaded into it. 57 */ 58 configure = 59 { 60 serviceManagerPkgs, 61 extraRootModules ? [ ], 62 extraRootSpecialArgs ? { }, 63 }: 64 let 65 modules = [ 66 (lib.modules.importApply ./service.nix { pkgs = serviceManagerPkgs; }) 67 ]; 68 serviceSubmodule = types.submoduleWith { 69 class = "service"; 70 modules = modules ++ extraRootModules; 71 specialArgs = extraRootSpecialArgs; 72 }; 73 in 74 { 75 inherit serviceSubmodule; 76 }; 77}