multi-derivation-package: init

This commit is contained in:
DavHau 2023-10-22 22:36:24 +01:00 committed by mergify[bot]
parent 8b5ddd6fe9
commit c3c5769aba
6 changed files with 158 additions and 6 deletions

View File

@ -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 {

View File

@ -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
'';

View File

@ -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;
};
}

View File

@ -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'";
};
};
}

View File

@ -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 = {

View File

@ -0,0 +1,87 @@
{
pkgs ? import <nixpkgs> {},
lib ? import <nixpkgs/lib>,
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";
};
}