From c3c5769abaa954766b6a4b8ab193d7538c02b12e Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 22 Oct 2023 22:36:24 +0100 Subject: [PATCH] multi-derivation-package: init --- lib/types/default.nix | 2 +- modules/dream2nix/groups/group.nix | 17 +++- .../multi-derivation-package/default.nix | 32 +++++++ .../multi-derivation-package/interface.nix | 19 ++++ tests/nix-unit/fixtures.nix | 7 +- .../default.nix | 87 +++++++++++++++++++ 6 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 modules/dream2nix/multi-derivation-package/default.nix create mode 100644 modules/dream2nix/multi-derivation-package/interface.nix create mode 100644 tests/nix-unit/test_groups_multi_derivation_package/default.nix diff --git a/lib/types/default.nix b/lib/types/default.nix index a5a8b178..a6ff71cf 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -8,7 +8,7 @@ in rec { derivation = t.oneOf [t.str t.path t.package]; - # A stricteer submodule type that prevents derivations from being + # A stricter submodule type that prevents derivations from being # detected as modules by accident. (derivations are attrs as well as modules) drvPart = let type = t.submoduleWith { diff --git a/modules/dream2nix/groups/group.nix b/modules/dream2nix/groups/group.nix index 20aaac13..428dfb03 100644 --- a/modules/dream2nix/groups/group.nix +++ b/modules/dream2nix/groups/group.nix @@ -9,12 +9,22 @@ packageType = t.deferredModuleWith { staticModules = [ dream2nix.modules.dream2nix.core - commonModule {_module.args = specialArgs;} + # the top-level commonModule + commonModule + # the commonModule of the current group + config.commonModule ]; }; in { options = { + commonModule = lib.mkOption { + type = t.deferredModule; + description = '' + Common configuration for all packages in all groups + ''; + default = {}; + }; overrides = lib.mkOption { type = t.attrs; description = '' @@ -28,7 +38,10 @@ in { ''; }; packagesEval = lib.mkOption { - type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith {modules = [];})); + type = t.lazyAttrsOf (t.lazyAttrsOf (t.submoduleWith { + modules = []; + inherit specialArgs; + })); description = '' The evaluated dream2nix package modules ''; diff --git a/modules/dream2nix/multi-derivation-package/default.nix b/modules/dream2nix/multi-derivation-package/default.nix new file mode 100644 index 00000000..a0ddc674 --- /dev/null +++ b/modules/dream2nix/multi-derivation-package/default.nix @@ -0,0 +1,32 @@ +{ + config, + lib, + dream2nix, + extendModules, + ... +}: { + imports = [ + ./interface.nix + dream2nix.modules.dream2nix.core + ]; + # make the core module happy + name = config.out.name; + version = config.out.version; + + # make the top-level look like a derivation under 'out' + public = { + inherit extendModules; + inherit + (config.out) + config + drvPath + name + outPath + outputName + outputs + type + version + ; + out = config.out.public; + }; +} diff --git a/modules/dream2nix/multi-derivation-package/interface.nix b/modules/dream2nix/multi-derivation-package/interface.nix new file mode 100644 index 00000000..dd116626 --- /dev/null +++ b/modules/dream2nix/multi-derivation-package/interface.nix @@ -0,0 +1,19 @@ +{ + config, + dream2nix, + lib, + specialArgs, + ... +}: let + t = lib.types; + dreamTypes = import ../../../lib/types { + inherit dream2nix lib specialArgs; + }; +in { + options = { + out = lib.mkOption { + type = dreamTypes.drvPart; + description = "default output 'out'"; + }; + }; +} diff --git a/tests/nix-unit/fixtures.nix b/tests/nix-unit/fixtures.nix index 16794f7e..88952f70 100644 --- a/tests/nix-unit/fixtures.nix +++ b/tests/nix-unit/fixtures.nix @@ -1,11 +1,12 @@ -{dream2nix}: { - basic-derivation = { +{dream2nix}: rec { + basic-derivation = named-derivation "hello"; + named-derivation = name: { # select builtins.derivation as a backend for this package imports = [ dream2nix.modules.dream2nix.builtins-derivation ]; - name = "test"; + inherit name; # set options builtins-derivation = { diff --git a/tests/nix-unit/test_groups_multi_derivation_package/default.nix b/tests/nix-unit/test_groups_multi_derivation_package/default.nix new file mode 100644 index 00000000..61a430cb --- /dev/null +++ b/tests/nix-unit/test_groups_multi_derivation_package/default.nix @@ -0,0 +1,87 @@ +{ + pkgs ? import {}, + lib ? import , + dream2nix ? (import (../../../modules + "/flake.nix")).outputs {}, +}: let + fixtures = import ../fixtures.nix {inherit dream2nix;}; + eval = module: + (lib.evalModules { + modules = [ + module + dream2nix.modules.dream2nix.multi-derivation-package + ]; + specialArgs = { + inherit dream2nix; + packageSets.nixpkgs = pkgs; + }; + }) + .config; + config = eval ( + { + config, + specialArgs, + ... + }: let + dreamTypes = import ../../../lib/types { + inherit dream2nix lib specialArgs; + }; + in { + options.dist = lib.mkOption { + type = dreamTypes.drvPart; + description = "The derivation module describing the dist output"; + }; + config = { + public.dist = config.dist.public; + out = {...}: fixtures.named-derivation "hello-out"; + dist = {...}: fixtures.named-derivation "hello-dist"; + }; + } + ); +in { + test_toplevel_drvPath_exists = { + expr = config ? drvPath; + expected = true; + }; + + test_out_drvPath_exists = { + expr = config.out ? drvPath; + expected = true; + }; + + test_dist_drvPath_exists = { + expr = config.dist ? drvPath; + expected = true; + }; + + test_toplevel_equals_out = { + expr = + config.drvPath + == config.out.drvPath; + expected = true; + }; + + test_toplevel_not_has_attr_builder = { + expr = config ? builder; + expected = false; + }; + + test_out_not_has_attr_builder = { + expr = config.out ? builder; + expected = false; + }; + + test_toplevel_name = { + expr = config.name; + expected = "hello-out"; + }; + + test_out_name = { + expr = config.out.name; + expected = "hello-out"; + }; + + test_dist_name = { + expr = config.dist.name; + expected = "hello-dist"; + }; +}