Producer quirks taking pkgs argument
#552
|
Heya. Finally checking out the new architecture of Den and quirks got me curious. Reading about Let us say I want to define shell command abbreviations across multiple aspects (aspect nix: den.quirks.abbreviations = {
description = "Abbreviations";
};
# These are the problematic arguments.
den.aspects.git.abbreviations = { lib, pkgs, ...}: {
abbreviations = {
g = "${lib.getExe pkgs.git}";
};
};
den.aspects.just.abbreviations = { lib, pkgs, ...}: {
abbreviations = {
j = "${lib.getExe pkgs.just}";
};
};
den.aspects.fish.homeManager = { lib, abbreviations, ... }: {
programs.fish.shellAbbrs = lib.mergeAttrsList abbreviations;
};The issue is that the quirks need both |
Replies: 4 comments 8 replies
|
I think this is an example of what you're trying to do: https://den.denful.dev/explanation/fleet/#config-dependent-cross-host-data |
|
I'm not familiar with quirks, but your case can be resolved using custom class (+ forwarder) Here an example: { den, lib, ... }: let
abbrFwd =
{ class, aspect-chain }:
den.batteries.forward {
each = [ "nixos" "homeManager" ]; # remove nixos if you only want to forward to homeManager
fromClass = _: "abbreviations";
intoClass = lib.id;
intoPath = _: [ "programs" "fish" "shellAbbrs" ];
fromAspect = _: lib.head aspect-chain;
guard = { config, ... }: _: lib.mkIf config.programs.fish.enable;
};
in {
# Register `abbreviations` class into global classes
den.classes.abbreviations = {};
# Import the forwarder to all entities
den.default.includes = [ abbrFwd ];
}Then, you can use it like your previous config (without duplicating den.aspects.git.abbreviations = { lib, pkgs, ...}: {
ls = "${lib.getExe pkgs.git}";
};
den.aspects.just.abbreviations = { lib, pkgs, ...}: {
j = "${lib.getExe pkgs.just}";
};You don't need to manually collect them in the fish aspect. The forwarder will collect them for you, and you just need to enable fish so that the abbrs are available and usable (look at the guard, remove it if you want to expose abbrs even when fish is disabled) |
|
Sorry, it's a long time, you may have already found a solution. We can pass the args in the collector aspect. e.g: den.quirks.abbreviations = {
description = "Abbreviations";
};
# These are the problematic arguments.
den.aspects.git.abbreviations = { lib, pkgs, ...}: {
g = "${lib.getExe pkgs.git}";
};
den.aspects.just.abbreviations = { lib, pkgs, ...}: {
j = "${lib.getExe pkgs.just}";
};
den.aspects.fish.homeManager = { lib, config, pkgs, abbreviations, ... }: let
args = config._module.args // config._module.specialArgs // { inherit lib config pkgs; };
fix = item:
if item ? __fn && builtins.isFunction item.__fn then
item.__fn (builtins.intersectAttrs (builtins.functionArgs item.__fn) args)
else item;
in {
programs.fish.shellAbbrs = lib.mergeAttrsList (map fix abbreviations);
}; |
Good news @Adda0! #625 allow quirks/pipe to pass module args. Will be merged soon.