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
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve(core): Split outputs.nix into modules (#350)

authored by

Victor Borja and committed by
GitHub
66677bf5 d02f2d64

+135 -104
+2 -104
modules/outputs.nix
··· 1 1 { 2 - config, 3 2 lib, 4 3 den, 5 4 inputs, 6 - options, 7 5 ... 8 6 }: 9 7 let 10 - osFwd = 11 - { host }: 12 - den._.forward { 13 - each = lib.optional (host.intoAttr != [ ]) true; 14 - fromClass = _: host.class; 15 - intoClass = _: "flake"; 16 - intoPath = _: [ "flake" ]; 17 - fromAspect = _: den.ctx.host { inherit host; }; 18 - mapModule = 19 - _: module: 20 - lib.setAttrByPath host.intoAttr ( 21 - host.instantiate { 22 - modules = [ 23 - module 24 - { nixpkgs.hostPlatform = lib.mkDefault host.system; } 25 - ]; 26 - } 27 - ); 28 - }; 29 - 30 - hmFwd = 31 - { home }: 32 - den._.forward { 33 - each = lib.optional (home.intoAttr != [ ]) true; 34 - fromClass = _: home.class; 35 - intoClass = _: "flake"; 36 - intoPath = _: [ "flake" ]; 37 - fromAspect = _: den.ctx.home { inherit home; }; 38 - mapModule = 39 - _: module: 40 - lib.setAttrByPath home.intoAttr ( 41 - home.instantiate { 42 - pkgs = home.pkgs; 43 - modules = [ module ]; 44 - } 45 - ); 46 - }; 47 - 48 - systemOutputFwd = 49 - { system, output }: 50 - { class, aspect-chain }: 51 - den._.forward { 52 - each = lib.optional (class == "flake") output; 53 - fromClass = _: output; 54 - intoClass = _: "flake"; 55 - intoPath = _: [ 56 - "flake" 57 - output 58 - system 59 - ]; 60 - guard = _: has-flake-output output; 61 - adaptArgs = _: { pkgs = inputs.nixpkgs.legacyPackages.${system}; }; 62 - fromAspect = _: lib.head aspect-chain; 63 - }; 64 - 65 - ctx.flake.into.flake-system = _: map (system: { inherit system; }) den.systems; 66 - 67 - ctx.flake-system.into.flake-os = 68 - { system }: map (host: { inherit host; }) (builtins.attrValues den.hosts.${system} or { }); 69 - ctx.flake-system.provides.flake-os = osFwd; 70 - 71 - ctx.flake-system.into.flake-hm = 72 - { system }: map (home: { inherit home; }) (builtins.attrValues den.homes.${system} or { }); 73 - ctx.flake-system.provides.flake-hm = hmFwd; 74 - 75 - systemOutput = output: { system }: lib.singleton { inherit system output; }; 76 - 77 - ctxSystemOuts = 78 - let 79 - outputs = [ 80 - "packages" 81 - "apps" 82 - "checks" 83 - "devShells" 84 - "legacyPackages" 85 - ]; 86 - 87 - ctxs = map (output: { 88 - flake-system.into."flake-${output}" = systemOutput output; 89 - flake-system.provides."flake-${output}" = systemOutputFwd; 90 - }) outputs; 91 - in 92 - ctxs; 93 - 8 + no-flake-parts = !inputs ? flake-parts; 94 9 flakeModule = den.lib.aspects.resolve "flake" (den.ctx.flake { }); 95 - 96 - systemsOpt = lib.mkOption { 97 - default = 98 - let 99 - sys = config.systems or (lib.unique (lib.attrNames den.hosts) ++ (lib.attrNames den.homes)); 100 - in 101 - if sys == [ ] then lib.systems.flakeExposed else sys; 102 - type = lib.types.listOf lib.types.str; 103 - }; 104 - 105 10 flake = 106 11 (lib.evalModules { 107 12 modules = [ ··· 110 15 ]; 111 16 specialArgs.inputs = inputs; 112 17 }).config.flake; 113 - 114 - has-flake-output = 115 - output: ((options.flake.type.getSubOptions or (_: options.flake)) { }) ? ${output}; 116 - no-flake-parts = !inputs ? flake-parts; 117 - 118 18 in 119 19 { 120 20 imports = lib.optional no-flake-parts inputs.den.flakeOutputs.flake; 121 - options.den.systems = systemsOpt; 122 - config.den.ctx = lib.mkMerge (ctxSystemOuts ++ [ ctx ]); 123 - config.flake = flake; 21 + inherit flake; 124 22 }
+53
modules/outputs/flakeSystemOutputs.nix
··· 1 + { 2 + den, 3 + lib, 4 + options, 5 + inputs, 6 + ... 7 + }: 8 + let 9 + ctx.flake.into.flake-system = _: map (system: { inherit system; }) den.systems; 10 + 11 + systemOutput = output: { system }: lib.singleton { inherit system output; }; 12 + 13 + has-flake-output = 14 + output: ((options.flake.type.getSubOptions or (_: options.flake)) { }) ? ${output}; 15 + 16 + systemOutputFwd = 17 + { system, output }: 18 + { class, aspect-chain }: 19 + den._.forward { 20 + each = lib.optional (class == "flake") output; 21 + fromClass = _: output; 22 + intoClass = _: "flake"; 23 + intoPath = _: [ 24 + "flake" 25 + output 26 + system 27 + ]; 28 + guard = _: has-flake-output output; 29 + adaptArgs = _: { pkgs = inputs.nixpkgs.legacyPackages.${system}; }; 30 + fromAspect = _: lib.head aspect-chain; 31 + }; 32 + 33 + ctxSystemOuts = 34 + let 35 + outputs = [ 36 + "packages" 37 + "apps" 38 + "checks" 39 + "devShells" 40 + "legacyPackages" 41 + ]; 42 + 43 + ctxs = map (output: { 44 + flake-system.into."flake-${output}" = systemOutput output; 45 + flake-system.provides."flake-${output}" = systemOutputFwd; 46 + }) outputs; 47 + in 48 + ctxs; 49 + 50 + in 51 + { 52 + den.ctx = lib.mkMerge (ctxSystemOuts ++ [ ctx ]); 53 + }
+29
modules/outputs/hmConfigurations.nix
··· 1 + { lib, den, ... }: 2 + let 3 + 4 + ctx.flake-system.into.flake-hm = 5 + { system }: map (home: { inherit home; }) (builtins.attrValues den.homes.${system} or { }); 6 + 7 + ctx.flake-system.provides.flake-hm = hmFwd; 8 + 9 + hmFwd = 10 + { home }: 11 + den._.forward { 12 + each = lib.optional (home.intoAttr != [ ]) true; 13 + fromClass = _: home.class; 14 + intoClass = _: "flake"; 15 + intoPath = _: [ "flake" ]; 16 + fromAspect = _: den.ctx.home { inherit home; }; 17 + mapModule = 18 + _: module: 19 + lib.setAttrByPath home.intoAttr ( 20 + home.instantiate { 21 + pkgs = home.pkgs; 22 + modules = [ module ]; 23 + } 24 + ); 25 + }; 26 + in 27 + { 28 + den.ctx = ctx; 29 + }
+30
modules/outputs/osConfigurations.nix
··· 1 + { lib, den, ... }: 2 + let 3 + ctx.flake-system.into.flake-os = 4 + { system }: map (host: { inherit host; }) (builtins.attrValues den.hosts.${system} or { }); 5 + 6 + ctx.flake-system.provides.flake-os = osFwd; 7 + 8 + osFwd = 9 + { host }: 10 + den._.forward { 11 + each = lib.optional (host.intoAttr != [ ]) true; 12 + fromClass = _: host.class; 13 + intoClass = _: "flake"; 14 + intoPath = _: [ "flake" ]; 15 + fromAspect = _: den.ctx.host { inherit host; }; 16 + mapModule = 17 + _: module: 18 + lib.setAttrByPath host.intoAttr ( 19 + host.instantiate { 20 + modules = [ 21 + module 22 + { nixpkgs.hostPlatform = lib.mkDefault host.system; } 23 + ]; 24 + } 25 + ); 26 + }; 27 + in 28 + { 29 + den.ctx = ctx; 30 + }
+21
modules/outputs/systems.nix
··· 1 + { 2 + lib, 3 + config, 4 + den, 5 + ... 6 + }: 7 + let 8 + 9 + systemsOpt = lib.mkOption { 10 + default = 11 + let 12 + sys = config.systems or (lib.unique (lib.attrNames den.hosts) ++ (lib.attrNames den.homes)); 13 + in 14 + if sys == [ ] then lib.systems.flakeExposed else sys; 15 + type = lib.types.listOf lib.types.str; 16 + }; 17 + 18 + in 19 + { 20 + options.den.systems = systemsOpt; 21 + }