fake.modules transposition for aspect-oriented Dendritic Nix. with cross-aspect dependencies. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic nix aspect oriented
at main 71 lines 1.9 kB view raw
1lib: 2# An utility for creating new aspect configuration classes that 3# help with separation of concerns. 4# 5# `forward` is a function that generates an aspect 6# that imports configurations from an originClass into 7# an scoped submodule of another targetClass. 8# 9# It takes te following arguments: 10# 11# - each: listOf items. 12# - fromClass: item -> originClassName. 13# - intoClass: item -> targetClassName. 14# - intoPath: item -> [ submoduleAttrPath ]. 15# - fromAspect: item -> aspect. An aspect to resolve origin class modules from. 16# 17# This is particularly useful for per-user homeManager like 18# configurations. 19# 20# The following pseudo-code snippet is used by [den](https://github.com/vic/den) 21# to support homeManager classes on NixOS. 22# 23# hmSupport = { host }: forward { 24# each = host.users; 25# fromClass = _user: "homeManager"; # originClass could have depended on user. 26# intoClass = _user: "nixos" 27# intoPath = user: [ "home-manager" "users" user.userName ] # HM users submodule. 28# fromAspect = user: den.aspects.${user.userName}; # resolve originClass from user aspect. 29# } 30# 31# 32# den.aspects.my-host.includes = [ hmSupport ]; 33# den.aspects.my-user = { 34# homeManager = { }; # settings for nixos.home-manager.users.my-user submodule. 35# } 36# 37# However usage is not limited to HM, and this settings forwarding ability 38# can be used for other use cases. 39# 40# See checkmate/modules/tests/forward.nix for working example. 41# 42{ 43 each, 44 fromClass, 45 intoClass, 46 intoPath, 47 fromAspect, 48}: 49let 50 include = 51 item: 52 let 53 from = fromClass item; 54 into = intoClass item; 55 path = intoPath item; 56 aspect = fromAspect item; 57 module = aspect.resolve { class = from; }; 58 config = lib.setAttrByPath path ( 59 { ... }: 60 { 61 imports = [ module ]; 62 } 63 ); 64 in 65 { 66 ${into} = config; 67 }; 68in 69{ 70 includes = map include each; 71}