From fad0a47b7547252330e4f0931c651ef63f3615dd Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 16 Mar 2024 20:23:18 +0000 Subject: [PATCH] add config.system.callService this is like pkgs.callService except that it passes config.system.service as a param so that the service being defined can invoke other services if this proves to be a good idea, all uses of pkgs.callService should be changed to use it instead --- modules/base.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/base.nix b/modules/base.nix index 8f53df2..4d3d8e4 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -29,6 +29,10 @@ in { services = mkOption { type = types.attrsOf type_service; }; + system.callService = mkOption { + type = types.functionTo (types.functionTo types.anything); + }; + filesystem = mkOption { type = types.anything; description = '' @@ -111,6 +115,31 @@ in { "fw_devlink=off" ] ++ lib.optional (config.rootOptions != null) "rootflags=${config.rootOptions}"; + system.callService = path : parameters : + let + typeChecked = caller: type: value: + let + inherit (lib) types mergeDefinitions; + defs = [{ file = caller; inherit value; }]; + type' = types.submodule { options = type; }; + in (mergeDefinitions [] type' defs).mergedValue; + cp = lib.callPackageWith(pkgs // { svc = config.system.service; }); + pkg = cp path {}; + checkTypes = t : p : typeChecked (builtins.toString path) t p; + in { + inherit parameters; + build = { dependencies ? [], ... } @ args : + let + s = pkg (checkTypes parameters + (builtins.removeAttrs args ["dependencies"])); + in s.overrideAttrs (o: { + dependencies = (builtins.map (d: d.name) dependencies) ++ o.dependencies; + buildInputs = dependencies ++ o.buildInputs; + }); + }; + + + users.root = { uid = 0; gid= 0; gecos = "Root of all evaluation"; dir = "/home/root/";