From ea200d834e613571acc051cd0c9e29d8ca4006f3 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Mon, 8 Jul 2024 23:18:11 -0700 Subject: [PATCH] feat: pass through package dependencies via context --- tidepool/src/builders/basic.nix | 2 +- tidepool/src/lib/packages.nix | 81 +++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 30 deletions(-) diff --git a/tidepool/src/builders/basic.nix b/tidepool/src/builders/basic.nix index aeedd97..0f8b3c2 100644 --- a/tidepool/src/builders/basic.nix +++ b/tidepool/src/builders/basic.nix @@ -110,7 +110,7 @@ in // { inherit (package) meta; extras = { - inherit package; + inherit package context; phases = builtins.listToAttrs sorted.result; } // package.extras; }; diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index bfa4648..ccd43a0 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -89,39 +89,62 @@ in let dependencies = lib.attrs.selectOrThrow path collected; contexts = builtins.map (dependency: dependency.context or { }) dependencies; - base = ctx // { - target = builtins.concatStringsSep "." path; - }; result = lib.modules.run { - modules = builtins.map - (context: { config }: { - config = context; - }) - contexts - ++ [ - { - freeform = lib.types.any; + modules = + builtins.map + (context: { config = context; }) + contexts + ++ [ + { + freeform = lib.types.any; - options = config.packages.context.options // { - target = lib.options.create { - description = "The dependency target that is being generated."; - type = lib.types.enum [ - "build.only" - "build.build" - "build.host" - "build.target" - "host.only" - "host.host" - "host.target" - "target.only" - "target.target" - ]; + options = config.packages.context.options // { + target = lib.options.create { + description = "The dependency target that is being generated."; + type = lib.types.enum [ + "build.only" + "build.build" + "build.host" + "build.target" + "host.only" + "host.host" + "host.target" + "target.only" + "target.target" + ]; + writable = false; + default.value = builtins.concatStringsSep "." path; + }; + + deps = lib.options.create { + description = "The collected dependencies."; + writable = false; + default.value = collected; + type = lib.types.submodule { + options = { + build = { + only = lib.options.create { type = lib.types.list.of lib'.types.package; }; + build = lib.options.create { type = lib.types.list.of lib'.types.package; }; + host = lib.options.create { type = lib.types.list.of lib'.types.package; }; + target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + }; + host = { + only = lib.options.create { type = lib.types.list.of lib'.types.package; }; + host = lib.options.create { type = lib.types.list.of lib'.types.package; }; + target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + }; + target = { + only = lib.options.create { type = lib.types.list.of lib'.types.package; }; + target = lib.options.create { type = lib.types.list.of lib'.types.package; }; + }; + }; + }; + }; }; - }; - config = base; - } - ]; + config = ctx; + } + ]; }; in result.config;