From 1f7ab7d09c2bf92ba588cc72c92fe71be4ac0c9e Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Wed, 3 Jul 2024 00:42:34 -0700 Subject: [PATCH] refactor: make dependencies dynamically built per-package --- tidepool/src/lib/packages.nix | 51 +++++------------------------------ tidepool/src/lib/types.nix | 41 +++++++++++++++------------- 2 files changed, 28 insertions(+), 64 deletions(-) diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index 786e65c..591e966 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -43,58 +43,19 @@ in { {config}: { config = { __modules__ = package.__modules__; - platform = { - build = lib.modules.overrides.force (lib'.systems.withBuildInfo build); - host = lib.modules.overrides.force (lib'.systems.withBuildInfo host); - target = lib.modules.overrides.force (lib'.systems.withBuildInfo target); - }; - # NOTE: This does not seem to work and instead the pre-existing deps are used. - # This causes an issue because the platforms will be wrong. - # deps = { - # build = { - # only = buildDependencies build build build package.deps.build.only; - # build = buildDependencies build build target package.deps.build.build; - # host = buildDependencies build host target package.deps.build.host; - # target = buildDependencies build target target package.deps.build.target; - # }; - # host = { - # only = buildDependencies host host host package.deps.host.only; - # host = buildDependencies host host target package.deps.host.host; - # target = buildDependencies host target target package.deps.host.target; - # }; - # target = { - # only = buildDependencies target target target package.deps.target.only; - # target = buildDependencies target target target package.deps.target.target; - # }; - # }; + platform = { + build = lib.modules.overrides.force build; + host = lib.modules.overrides.force host; + target = lib.modules.overrides.force target; + }; }; } ) ]; }; - resolved = - result.config - // { - deps = { - build = { - only = buildDependencies build build build package.deps.build.only; - build = buildDependencies build build target package.deps.build.build; - host = buildDependencies build host target package.deps.build.host; - target = buildDependencies build target target package.deps.build.target; - }; - host = { - only = buildDependencies host host host package.deps.host.only; - host = buildDependencies host host target package.deps.host.host; - target = buildDependencies host target target package.deps.host.target; - }; - target = { - only = buildDependencies target target target package.deps.target.only; - target = buildDependencies target target target package.deps.target.target; - }; - }; - }; + resolved = result.config; in resolved // { diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index c0068ef..bd16c8b 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -74,16 +74,15 @@ in { packages = lib.types.attrs.of (lib.types.attrs.of lib'.types.alias); - dependencies = let - initial = - (lib.types.attrs.lazy lib.types.any) - // { - check = value: - lib.types.attrs.any.check value - && value ? versions; - }; + dependencies = build: host: target: let + initial = lib.types.attrs.any; + + transform = value: let + package = lib'.packages.resolve value; + in + lib'.packages.build package build host target; in - lib.types.attrs.of (lib.types.coerce initial lib'.packages.resolve lib'.types.package); + lib.types.attrs.of (lib.types.coerce initial transform lib'.types.package); alias = lib.types.submodule { options = { @@ -144,7 +143,11 @@ in { final = lib.types.attrs.any; - submodule = {config}: { + submodule = {config}: let + build = config.platform.build; + host = config.platform.host; + target = config.platform.target; + in { options = { __modules__ = lib.options.create { description = "User specified modules for the package definition."; @@ -278,25 +281,25 @@ in { build = { only = lib.options.create { description = "Dependencies which are only used in the build environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies build build build; default.value = {}; }; build = lib.options.create { description = "Dependencies which are created in the build environment and are executed in the build environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies build build target; default.value = {}; }; host = lib.options.create { description = "Dependencies which are created in the build environment and are executed in the host environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies build host target; default.value = {}; }; target = lib.options.create { description = "Dependencies which are created in the build environment and are executed in the target environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies build target target; default.value = {}; }; }; @@ -304,19 +307,19 @@ in { host = { only = lib.options.create { description = "Dependencies which are only used in the host environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies host host host; default.value = {}; }; host = lib.options.create { description = "Dependencies which are executed in the host environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies host host target; default.value = {}; }; target = lib.options.create { description = "Dependencies which are executed in the host environment which produces code for the target environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies host target target; default.value = {}; }; }; @@ -324,13 +327,13 @@ in { target = { only = lib.options.create { description = "Dependencies which are only used in the target environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies target target target; default.value = {}; }; target = lib.options.create { description = "Dependencies which are executed in the target environment."; - type = lib'.types.dependencies; + type = lib'.types.dependencies target target target; default.value = {}; }; };