Modular, context-aware and aspect-oriented dendritic Nix configurations. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ den.oeiuwq.com
configurations den dendritic nix aspect oriented

refactor(homes): Make hm,hjem,maid have the same behaviour. (#257)

authored by oeiuwq.com and committed by

GitHub 101b08a2 ae0ff608

+171 -266
+28
modules/aspects/provides/hjem.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + ... 6 + }: 7 + let 8 + inherit (den.lib.home-env) makeHomeEnv; 9 + 10 + result = makeHomeEnv { 11 + className = "hjem"; 12 + optionPath = "hjem"; 13 + inputsPath = "hjem"; 14 + getModule = { host, ... }: inputs.hjem."${host.class}Modules".default; 15 + forwardPathFn = 16 + { user, ... }: 17 + [ 18 + "hjem" 19 + "users" 20 + user.userName 21 + ]; 22 + }; 23 + 24 + in 25 + { 26 + den.ctx = result.ctx; 27 + den.schema.host.imports = [ result.hostConf ]; 28 + }
-29
modules/aspects/provides/hjem/hjem-integration.nix
··· 1 - { 2 - den, 3 - lib, 4 - inputs, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - intoClassUsers 10 - forwardToHost 11 - ; 12 - 13 - hjemClass = "hjem"; 14 - 15 - ctx.hjem-host.into.hjem-user = intoClassUsers hjemClass; 16 - ctx.hjem-user._.hjem-user = forwardToHost { 17 - className = hjemClass; 18 - forwardPathFn = 19 - { user, ... }: 20 - [ 21 - "hjem" 22 - "users" 23 - user.userName 24 - ]; 25 - }; 26 - in 27 - { 28 - den.ctx = ctx; 29 - }
-41
modules/aspects/provides/hjem/hjem-os.nix
··· 1 - { 2 - den, 3 - lib, 4 - inputs, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - detectHost 10 - hostOptions 11 - ; 12 - 13 - hjemClass = "hjem"; 14 - hjemOsClasses = [ 15 - "nixos" 16 - "darwin" 17 - ]; 18 - 19 - ctx.host.into.hjem-host = detectHost { 20 - className = hjemClass; 21 - supportedOses = hjemOsClasses; 22 - optionPath = "hjem"; 23 - }; 24 - 25 - ctx.hjem-host._.hjem-host = 26 - { host }: 27 - { 28 - ${host.class}.imports = [ host.hjem.module ]; 29 - }; 30 - 31 - hostConf = hostOptions { 32 - className = hjemClass; 33 - optionPath = "hjem"; 34 - inputsPath = "hjem"; 35 - getModule = { host, ... }: inputs.hjem."${host.class}Modules".default; 36 - }; 37 - in 38 - { 39 - den.ctx = ctx; 40 - den.schema.host.imports = [ hostConf ]; 41 - }
+54
modules/aspects/provides/home-manager.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + ... 6 + }: 7 + let 8 + inherit (den.lib.home-env) makeHomeEnv; 9 + 10 + hm-aspect-deprecated = '' 11 + NOTICE: den.provides.home-manager aspect is not used anymore. 12 + See https://den.oeiuwq.com/guides/home-manager/ 13 + 14 + Since den.ctx.hm-host requires least one user with homeManager class, 15 + Home Manager is now enabled via options. 16 + 17 + For all users unless they set a value: 18 + 19 + den.schema.user.classes = lib.mkDefault [ "homeManager" ]; 20 + 21 + On specific users: 22 + 23 + den.hosts.x86_64-linux.igloo.users.tux.classes = [ "homeManager" ]; 24 + 25 + For attaching aspects to home-manager enabled hosts. 26 + ''; 27 + 28 + result = makeHomeEnv { 29 + className = "homeManager"; 30 + ctxName = "hm"; 31 + optionPath = "home-manager"; 32 + inputsPath = "home-manager"; 33 + getModule = { host, ... }: inputs.home-manager."${host.class}Modules".home-manager; 34 + forwardPathFn = 35 + { user, ... }: 36 + [ 37 + "home-manager" 38 + "users" 39 + user.userName 40 + ]; 41 + }; 42 + 43 + homeCtx = { 44 + home.provides.home = 45 + { home }: den.lib.parametric.fixedTo { inherit home; } den.aspects.${home.aspect}; 46 + home.into.default = lib.singleton; 47 + }; 48 + 49 + in 50 + { 51 + den.provides.home-manager = _: throw hm-aspect-deprecated; 52 + den.ctx = result.ctx // homeCtx; 53 + den.schema.host.imports = [ result.hostConf ]; 54 + }
-72
modules/aspects/provides/home-manager/hm-integration.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - den, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - intoClassUsers 10 - forwardToHost 11 - ; 12 - 13 - inherit (den.lib) parametric; 14 - 15 - hmClass = "homeManager"; 16 - 17 - hm-aspect-deprecated = '' 18 - NOTICE: den.provides.home-manager aspect is not used anymore. 19 - See https://den.oeiuwq.com/guides/home-manager/ 20 - 21 - Since den.ctx.hm-host requires least one user with homeManager class, 22 - Home Manager is now enabled via options. 23 - 24 - For all users unless they set a value: 25 - 26 - den.schema.user.classes = lib.mkDefault [ "homeManager" ]; 27 - 28 - On specific users: 29 - 30 - den.hosts.x86_64-linux.igloo.users.tux.classes = [ "homeManager" ]; 31 - 32 - See <den/home-manager/hm-os.nix> 33 - 34 - If you had includes at den._.home-manager, you can use: 35 - 36 - den.ctx.hm-host.includes = [ ... ]; 37 - 38 - For attaching aspects to home-manager enabled hosts. 39 - ''; 40 - 41 - ctx.home.provides.home = { home }: parametric.fixedTo { inherit home; } den.aspects.${home.aspect}; 42 - ctx.home.into.default = lib.singleton; 43 - 44 - ctx.hm-host.into.hm-user = intoClassUsers hmClass; 45 - ctx.hm-user.provides.hm-user = forwardToHost { 46 - className = hmClass; 47 - forwardPathFn = 48 - { user, ... }: 49 - [ 50 - "home-manager" 51 - "users" 52 - user.userName 53 - ]; 54 - aspectFn = den.ctx.hm-user-internal; 55 - }; 56 - 57 - ctx.hm-user-internal.provides.hm-user-internal = 58 - { host, user }: 59 - { class, aspect-chain }: 60 - { 61 - includes = [ 62 - (den.ctx.user { inherit host user; }) 63 - (den.lib.owned den.aspects.${host.aspect}) 64 - (den.lib.statics den.aspects.${host.aspect} { inherit class aspect-chain; }) 65 - (parametric.atLeast den.aspects.${host.aspect} { inherit host user; }) 66 - ]; 67 - }; 68 - in 69 - { 70 - den.provides.home-manager = _: throw hm-aspect-deprecated; 71 - den.ctx = ctx; 72 - }
-42
modules/aspects/provides/home-manager/hm-os.nix
··· 1 - { 2 - den, 3 - lib, 4 - inputs, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - detectHost 10 - hostOptions 11 - ; 12 - 13 - hmClass = "homeManager"; 14 - hmOsClasses = [ 15 - "nixos" 16 - "darwin" 17 - ]; 18 - 19 - ctx.host.into.hm-host = detectHost { 20 - className = hmClass; 21 - supportedOses = hmOsClasses; 22 - optionPath = "home-manager"; 23 - }; 24 - 25 - ctx.hm-host.provides.hm-host = 26 - { host }: 27 - { 28 - ${host.class}.imports = [ host.home-manager.module ]; 29 - }; 30 - 31 - hostConf = hostOptions { 32 - className = hmClass; 33 - optionPath = "home-manager"; 34 - inputsPath = "home-manager"; 35 - getModule = { host, ... }: inputs.home-manager."${host.class}Modules".home-manager; 36 - }; 37 - 38 - in 39 - { 40 - den.ctx = ctx; 41 - den.schema.host.imports = [ hostConf ]; 42 - }
+30
modules/aspects/provides/maid.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + ... 6 + }: 7 + let 8 + inherit (den.lib.home-env) makeHomeEnv; 9 + 10 + result = makeHomeEnv { 11 + className = "maid"; 12 + supportedOses = [ "nixos" ]; 13 + optionPath = "nix-maid"; 14 + inputsPath = "nix-maid"; 15 + getModule = { host, ... }: inputs.nix-maid."${host.class}Modules".default; 16 + forwardPathFn = 17 + { user, ... }: 18 + [ 19 + "users" 20 + "users" 21 + user.userName 22 + "maid" 23 + ]; 24 + }; 25 + 26 + in 27 + { 28 + den.ctx = result.ctx; 29 + den.schema.host.imports = [ result.hostConf ]; 30 + }
-31
modules/aspects/provides/maid/maid-integration.nix
··· 1 - { 2 - den, 3 - lib, 4 - inputs, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - intoClassUsers 10 - forwardToHost 11 - ; 12 - 13 - maidClass = "maid"; 14 - 15 - ctx.maid-host.into.maid-user = intoClassUsers maidClass; 16 - ctx.maid-user._.maid-user = forwardToHost { 17 - className = maidClass; 18 - forwardPathFn = 19 - { user, ... }: 20 - [ 21 - "users" 22 - "users" 23 - user.userName 24 - "maid" 25 - ]; 26 - }; 27 - 28 - in 29 - { 30 - den.ctx = ctx; 31 - }
-39
modules/aspects/provides/maid/maid-os.nix
··· 1 - { 2 - den, 3 - lib, 4 - inputs, 5 - ... 6 - }: 7 - let 8 - inherit (den.lib.home-env) 9 - detectHost 10 - hostOptions 11 - ; 12 - 13 - maidClass = "maid"; 14 - maidOsClasses = [ "nixos" ]; 15 - 16 - ctx.host.into.maid-host = detectHost { 17 - className = maidClass; 18 - supportedOses = maidOsClasses; 19 - optionPath = "nix-maid"; 20 - }; 21 - 22 - ctx.maid-host._.maid-host = 23 - { host }: 24 - { 25 - ${host.class}.imports = [ host.nix-maid.module ]; 26 - }; 27 - 28 - hostConf = hostOptions { 29 - className = maidClass; 30 - optionPath = "nix-maid"; 31 - inputsPath = "nix-maid"; 32 - getModule = { host, ... }: inputs.nix-maid.nixosModules.default; 33 - }; 34 - 35 - in 36 - { 37 - den.ctx = ctx; 38 - den.schema.host.imports = [ hostConf ]; 39 - }
+59 -12
nix/home-env.nix
··· 10 10 host-has-user-with-class = 11 11 host: class: 12 12 lib.pipe host.users [ 13 - (lib.attrValues) 13 + lib.attrValues 14 14 (map (user: lib.elem class user.classes)) 15 15 (lib.filter lib.id) 16 16 (xs: lib.length xs > 0) ··· 64 64 lib.filter (u: lib.elem className u.classes) (lib.attrValues host.users) 65 65 ); 66 66 67 + userEnvAspect = 68 + ctxName: 69 + { host, user }: 70 + { class, aspect-chain }: 71 + { 72 + includes = [ 73 + (den.ctx."${ctxName}-user" { inherit host user; }) 74 + (den.ctx.user { inherit host user; }) 75 + (den.lib.owned den.aspects.${host.aspect}) 76 + (den.lib.statics den.aspects.${host.aspect} { inherit class aspect-chain; }) 77 + (den.lib.parametric.atLeast den.aspects.${host.aspect} { inherit host user; }) 78 + ]; 79 + }; 80 + 67 81 forwardToHost = 68 82 { 69 83 className, 84 + ctxName, 70 85 forwardPathFn, 71 - aspectFn ? null, 72 86 }: 73 87 { host, user }: 74 - let 75 - aspect = if aspectFn != null then aspectFn { inherit host user; } else den.aspects.${user.aspect}; 76 - in 77 88 den._.forward { 78 89 each = lib.singleton true; 79 90 fromClass = _: className; 80 91 intoClass = _: host.class; 81 92 intoPath = _: forwardPathFn { inherit host user; }; 82 - fromAspect = _: aspect; 93 + fromAspect = _: userEnvAspect ctxName { inherit host user; }; 94 + }; 95 + 96 + makeHomeEnv = 97 + { 98 + className, 99 + ctxName ? className, 100 + supportedOses ? [ 101 + "nixos" 102 + "darwin" 103 + ], 104 + optionPath, 105 + inputsPath, 106 + getModule, 107 + forwardPathFn, 108 + }: 109 + { 110 + ctx = { 111 + host.into."${ctxName}-host" = detectHost { inherit className supportedOses optionPath; }; 112 + 113 + "${ctxName}-host" = { 114 + provides."${ctxName}-host" = 115 + { host }: 116 + { 117 + ${host.class}.imports = [ host.${optionPath}.module ]; 118 + }; 119 + into."${ctxName}-user" = intoClassUsers className; 120 + }; 121 + 122 + "${ctxName}-user".provides."${ctxName}-user" = forwardToHost { 123 + inherit className ctxName forwardPathFn; 124 + }; 125 + }; 126 + 127 + hostConf = hostOptions { 128 + inherit 129 + className 130 + optionPath 131 + inputsPath 132 + getModule 133 + ; 134 + }; 83 135 }; 84 136 85 137 in 86 138 { 87 - inherit 88 - detectHost 89 - hostOptions 90 - intoClassUsers 91 - forwardToHost 92 - ; 139 + inherit makeHomeEnv; 93 140 }