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
8 changes: 5 additions & 3 deletions modules/aspects/definition.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
...
}:
let
inherit (den.lib) parametric;

# creates den.aspects.${home.aspect}
homeAspect = home: {
${home.aspect} = {
${home.class} = { };
includes = [ den.default ];
__functor = den.lib.parametric { inherit home; };
__functor = HM: parametric { inherit HM home; } HM;
};
};

Expand All @@ -19,7 +21,7 @@ let
${host.aspect} = {
${host.class} = { };
includes = [ den.default ];
__functor = den.lib.parametric { OS = { inherit host; }; };
__functor = OS: parametric { inherit OS host; } OS;
};
};

Expand All @@ -28,7 +30,7 @@ let
${user.aspect} = {
${user.class} = { };
includes = [ den.default ];
__functor = den.lib.parametric true;
__functor = parametric.expands { inherit user; };
};
};

Expand Down
127 changes: 70 additions & 57 deletions modules/aspects/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,93 @@ let
inherit (den.lib.take) exactly;

dependencies = [
(exactly ({ home }: baseDeps home))
(exactly ({ host }: baseDeps host))
(exactly ({ user }: baseDeps user))
(exactly osDependencies)
(exactly hmDependencies)
(exactly hmUserDependencies)
(exactly hmStandaloneDependencies)
];

baseDeps =
from:
let
exists = from ? aspect && builtins.hasAttr from.aspect den.aspects;
aspect = den.aspects.${from.aspect};
in
osDependencies =
{ OS, host }:
{
includes = lib.optionals exists [
(statics den.default)
(statics aspect)
includes = [
(owned den.default)
(owned aspect)
(statics den.default)
(owned OS)
(statics OS)
{
includes =
let
users = builtins.attrValues host.users;
contrib = osUserDependencies OS host;
in
map contrib users;
}
];
};

from = o: (lib.flip parametric) den.aspects.${o.aspect};

osDependencies =
{ OS }:
osUserDependencies =
OS: host: user:
let
inherit (OS) host;
users = builtins.attrValues host.users;
hostIncludes = [
(from host { inherit host; })
(from host {
inherit OS host;
fromHost = host;
})
];
userIncludes = user: [
(from user { inherit user; })
(from user {
inherit OS user host;
fromUser = user;
})
(from host {
inherit OS user host;
fromHost = host;
})
];
USR = den.aspects.${user.aspect};
ctx = { inherit OS host user; };
in
{
includes = hostIncludes ++ (map (u: { includes = userIncludes u; }) users);
includes = [
(owned USR)
(statics USR)
(USR ctx)
];
};

hmDependencies =
{ HM }:
let
inherit (HM) user host;
hostIncludes = [
(from host { inherit host; })
(from host {
inherit HM user host;
fromHost = host;
})
];
userIncludes = [
(from user { inherit user; })
(from user {
inherit HM user host;
fromUser = user;
})
# from home-manager integration.
hmUserDependencies =
{
HM,
host,
user,
}:
{
includes = [
(owned den.default)
(statics den.default)
(owned HM)
(statics HM)
(hmOsDependencies HM host user)
];
};

hmOsDependencies =
HM: host: user:
let
OS = den.aspects.${host.aspect};
newCtx = {
inherit
HM
OS
host
user
;
};
in
{
includes = hostIncludes ++ userIncludes;
includes = [
(owned OS)
(statics OS)
(parametric newCtx OS)
];
};

hmStandaloneDependencies =
{ HM, home }:
{
includes = [
(owned den.default)
(statics den.default)
(owned HM)
(statics HM)
];
};

in
{
den.default.includes = dependencies;
Expand Down
8 changes: 4 additions & 4 deletions modules/aspects/provides/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ in
inherit aspect-chain;
class = hmClass;
};
aspect = den.aspects.${user.aspect} {
HM = { inherit host user; };
};
HM = den.aspects.${user.aspect};
aspect = HM { inherit HM host; };
module = aspect.resolve ctx;
in
aspect.resolve ctx;
module;

users = map (user: {
name = user.userName;
Expand Down
8 changes: 3 additions & 5 deletions modules/aspects/provides/user-shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ let
inherit nixos darwin homeManager;
};

inherit (den.lib.take) exactly;

in
{
den.provides.user-shell = shell: {
inherit description;
__functor = den.lib.parametric true;
__functor = den.lib.parametric.atLeast;
includes = [
(exactly ({ user }: userShell shell user))
(exactly ({ home }: userShell shell home))
({ user, ... }: userShell shell user)
({ home, ... }: userShell shell home)
];
};
}
2 changes: 1 addition & 1 deletion nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let
parametric.atLeast = funk (lib.flip take.atLeast);
parametric.exactly = funk (lib.flip take.exactly);
parametric.context = lib.flip parametric.atLeast;
parametric.expands = attrs: funk (ctx: (lib.flip take.atLeast) (attrs // ctx));
parametric.expands = attrs: funk (ctx: (lib.flip take.atLeast) (ctx // attrs));
parametric.__functor =
self: ctx:
if ctx == true then
Expand Down
45 changes: 11 additions & 34 deletions templates/default/modules/aspects/eg/routes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,18 @@
let
inherit (den.lib) parametric;

os-from-user =
{
user,
host,
# deadnix: skip
OS,
# deadnix: skip
fromUser,
}:
parametric { inherit user host; } (mutual user host);
# eg, `<user>._.<host>` and `<host>._.<user>`
mutual = from: to: den.aspects.${from.aspect}._.${to.aspect} or { };

hm-from-host =
routes =
{ host, user, ... }@ctx:
{
user,
host,
# deadnix: skip
HM,
# deadnix: skip
fromHost,
}:
parametric { inherit user host; } (mutual host user);

mutual = from: to: {
includes = [
# eg, `<user>._.<host>` and `<host>._.<user>`
(den.aspects.${from.aspect}._.${to.aspect} or { })
];
};

__functor = parametric ctx;
includes = [
(mutual user host)
(mutual host user)
];
};
in
{
__functor = parametric.exactly;
includes = [
os-from-user
hm-from-host
];
};
routes;
}
16 changes: 14 additions & 2 deletions templates/examples/modules/_example/ci/custom-nixos-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@
let
# A custom `nixos` class module that defines an option `names`.
# Used to test that we are not duplicating values from owned configs.
nixosNames.options.names = lib.mkOption { type = lib.types.listOf lib.types.str; };
nixosNames = names: { options.${names} = lib.mkOption { type = lib.types.listOf lib.types.str; }; };
in
{
den.default.nixos.imports = [ (nixosNames "people") ];
den.default.includes = [
(
{ user, ... }:
{
nixos.people = [ user.name ];
}
)
];

den.aspects.rockhopper.includes = [
# Example: importing a third-party nixos module.
{ nixos.imports = [ nixosNames ]; }
{ nixos.imports = [ (nixosNames "names") ]; }
];

den.aspects.rockhopper.nixos.names = [ "tux" ];

perSystem =
{ checkCond, rockhopper, ... }:
{
checks.rockhopper-default-people = checkCond "set from den.default for each user" (
rockhopper.config.people == [ "alice" ]
);
checks.rockhopper-names-single-entry = checkCond "custom nixos array option set once" (
rockhopper.config.names == [ "tux" ]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{ den, lib, ... }:
{ lib, ... }:
let
# Example: configuration that depends on both host and user. provides only to HM.
host-to-user-conditional =
{
HM,
user,
host,
...
}:
den.lib.take.unused [ HM ] (
if user.userName == "alice" && !lib.hasSuffix "darwin" host.system then
{
homeManager.programs.git.enable = true;
}
else
{ }
);
if user.userName == "alice" && !lib.hasSuffix "darwin" host.system then
{
homeManager.programs.git.enable = true;
}
else
{ };
in
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{ den, ... }:
let

# Example: adds hello into each user. provides only to OS.
hello-package-for-user =
{
OS,
fromUser,
user,
host,
...
}:
den.lib.take.unused [ OS fromUser ] {
{
${host.class} =
{ pkgs, ... }:
{
Expand All @@ -21,10 +18,7 @@ let
in
{

den.default.includes = [
# Example: parametric { OS, fromUser } aspect.
hello-package-for-user
];
den.default.includes = [ hello-package-for-user ];

perSystem =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let

# Example: luke standalone home-manager has access to rockhopper osConfig specialArg.
os-conditional-hm =
{ home }:
{ home, ... }:
{
# access osConfig, wired via extraSpecialArgs in homes.nix.
homeManager =
Expand Down
Loading