Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ persys = { host }: den._.forward {
each = lib.singleton true;
fromClass = _: "persys";
intoClass = _: host.class;
intoPath = _: [ "environment" "persistance" "/nix/persist/system" ];
intoPath = _: [ "environment" "persistence" "/nix/persist/system" ];
fromAspect = _: den.aspects.${host.aspect};
guard = { options, config, ... }: options ? environment.persistance;
guard = { options, config, ... }: options ? environment.persistence;
};

# enable on all hosts
Expand Down
13 changes: 9 additions & 4 deletions modules/aspects/provides/forward.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ let
intoClass = fwd.intoClass item;
intoPath = fwd.intoPath item;

intoPathArgs = if lib.isFunction intoPath then lib.functionArgs intoPath else { };
intoPathFn = if lib.isFunction intoPath then intoPath else _: intoPath;
staticIntoPath = if lib.isFunction intoPath then [ ] else intoPath;

asp = fwd.fromAspect item;
sourceModule = den.lib.aspects.resolve fromClass asp;

Expand All @@ -76,7 +80,7 @@ let
fromClass
intoClass
]
++ intoPath
++ staticIntoPath
);

guardArgs = if guard == null then { } else lib.functionArgs guard;
Expand All @@ -99,7 +103,7 @@ let
])
];
${intoClass} = {
__functionArgs = guardArgs;
__functionArgs = guardArgs // intoPathArgs;
__functor = _: args: {
options.den.fwd.${adapterKey} = lib.mkOption {
default = { };
Expand All @@ -108,7 +112,7 @@ let
modules = adapterMods;
};
};
config = guardFn args (lib.setAttrByPath intoPath args.config.den.fwd.${adapterKey});
config = guardFn args (lib.setAttrByPath (intoPathFn args) args.config.den.fwd.${adapterKey});
};
};
};
Expand Down Expand Up @@ -161,7 +165,8 @@ let
evalImport args;
};

needsAdapter = guard != null || adaptArgs != null || adapterModule != null;
needsAdapter =
guard != null || adaptArgs != null || adapterModule != null || builtins.isFunction intoPath;
needsTopLevelAdapter = needsAdapter && intoPath == [ ];
forwarded = forward intoPath;

Expand Down
125 changes: 125 additions & 0 deletions templates/ci/modules/features/dynamic-intopath.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{ denTest, ... }:
{
flake.tests.dynamic-intopath = {

test-dynamic-intoPath-host-scope = denTest (
{
den,
lib,
igloo,
...
}:
let
slotMod =
{ lib, ... }:
{
options.my-slot = lib.mkOption {
type = lib.types.str;
default = "slot-a";
};
options.my-box = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submoduleWith {
modules = [
{
config._module.freeformType = lib.types.lazyAttrsOf lib.types.anything;
}
];
}
);
default = { };
};
};

forwarded =
{ class, aspect-chain }:
den._.forward {
each = lib.singleton class;
fromClass = _: "src";
intoClass = _: "nixos";
intoPath =
_:
{ config, ... }:
[
"my-box"
config.my-slot
];
fromAspect = _: lib.head aspect-chain;
};
in
{
den.hosts.x86_64-linux.igloo.users.tux = { };
den.aspects.igloo = {
includes = [ forwarded ];
nixos.imports = [ slotMod ];
nixos.my-slot = "slot-b";
src.my-data = "hello-from-src";
};

expr = igloo.my-box.slot-b.my-data;
expected = "hello-from-src";
}
);

test-dynamic-intoPath-user-scope = denTest (
{
den,
lib,
igloo,
...
}:
let
slotMod =
{ lib, ... }:
{
options.my-slot = lib.mkOption {
type = lib.types.str;
default = "slot-a";
};
options.my-box = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submoduleWith {
modules = [
{
config._module.freeformType = lib.types.lazyAttrsOf lib.types.anything;
}
];
}
);
default = { };
};
};

forwarded =
{ class, aspect-chain }:
den._.forward {
each = lib.singleton class;
fromClass = _: "src";
intoClass = _: "homeManager";
intoPath =
_:
{ config, ... }:
[
"my-box"
config.my-slot
];
fromAspect = _: lib.head aspect-chain;
};
in
{
den.hosts.x86_64-linux.igloo.users.tux = { };
den.aspects.igloo.homeManager.home.stateVersion = "25.11";
den.aspects.tux = {
includes = [ forwarded ];
homeManager.imports = [ slotMod ];
homeManager.my-slot = "slot-b";
src.my-data = "hello-from-src";
};

expr = igloo.home-manager.users.tux.my-box.slot-b.my-data;
expected = "hello-from-src";
}
);

};
}
Loading