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

move denShell apps to den.lib

+98 -67
+1 -2
modules/context/types.nix
··· 1 1 { den, lib, ... }: 2 2 let 3 3 inherit (den.lib.aspects.types) aspectSubmodule; 4 - 5 - ctxApply = import ./../../nix/ctx-apply.nix { inherit lib den; }; 4 + inherit (den.lib) ctxApply; 6 5 7 6 # a context-definiton is an aspect extended with into.* transformations 8 7 # and a fixed functor to apply them.
+14
nix/lib.nix
··· 5 5 ... 6 6 }: 7 7 let 8 + inherit (config) den; 8 9 9 10 # "Just Give 'Em One of These" - Moe Szyslak 10 11 # A __functor that applies context to parametric includes (functions) ··· 103 104 104 105 __findFile = import ./den-brackets.nix { inherit lib config; }; 105 106 107 + nh = import ./nh.nix { 108 + inherit 109 + lib 110 + config 111 + den 112 + inputs 113 + ; 114 + }; 115 + 116 + ctxApply = import ./ctx-apply.nix { inherit lib den; }; 117 + 106 118 den-lib = { 107 119 inherit 108 120 parametric ··· 114 126 canTake 115 127 take 116 128 isStatic 129 + ctxApply 130 + nh 117 131 ; 118 132 }; 119 133 in
+75
nix/nh.nix
··· 1 + # Provides shell utilities under `den.sh` for building OS configurations using 2 + # github:nix-community/nh instead of nixos-rebuild, etc 3 + { lib, den, ... }: 4 + let 5 + defaultAction = "build"; 6 + 7 + denShell = 8 + pkgs: 9 + pkgs.mkShell { 10 + buildInputs = [ pkgs.nh ] ++ (denApps pkgs); 11 + }; 12 + 13 + hosts = lib.concatMap lib.attrValues (lib.attrValues den.hosts); 14 + homes = lib.concatMap lib.attrValues (lib.attrValues den.homes); 15 + 16 + hostApps = pkgs: map (os pkgs) hosts; 17 + homeApps = pkgs: map (hm pkgs) homes; 18 + denApps = pkgs: (hostApps pkgs) ++ (homeApps pkgs); 19 + 20 + os = 21 + pkgs: host: 22 + pkgs.writeShellApplication { 23 + name = host.name; 24 + runtimeInputs = [ pkgs.nh ]; 25 + text = 26 + let 27 + command = 28 + { 29 + darwin = "darwin"; 30 + nixos = "os"; 31 + } 32 + .${host.class}; 33 + attr = lib.concatStringsSep "." ([ "flake" ] ++ host.intoAttr); 34 + args = lib.concatStringsSep " " [ 35 + "--file" 36 + "." 37 + attr 38 + ]; 39 + in 40 + '' 41 + action="''${1:-${defaultAction}}" 42 + shift || true 43 + exec nh ${command} "$action" ${args} "$@" 44 + ''; 45 + }; 46 + 47 + hm = 48 + pkgs: home: 49 + pkgs.writeShellApplication { 50 + name = home.name; 51 + runtimeInputs = [ pkgs.nh ]; 52 + text = 53 + let 54 + attr = lib.concatStringsSep "." ([ "flake" ] ++ home.intoAttr); 55 + args = lib.concatStringsSep " " [ 56 + "--file" 57 + "." 58 + attr 59 + ]; 60 + in 61 + '' 62 + action="''${1:-${defaultAction}}" 63 + shift || true 64 + exec nh home "$action" ${args} "$@" 65 + ''; 66 + }; 67 + in 68 + { 69 + inherit 70 + denShell 71 + homeApps 72 + hostApps 73 + denApps 74 + ; 75 + }
+1 -1
templates/noflake/default.nix
··· 2 2 sources = import ./npins; 3 3 with-inputs = import sources.with-inputs sources { 4 4 # uncomment for local checkout on CI 5 - # den.outPath = ./../..; 5 + den.outPath = ./../..; 6 6 }; 7 7 8 8 outputs =
+7 -64
templates/noflake/modules/nh.nix
··· 1 1 # Provides shell utilities under `den.sh` for building OS configurations using 2 2 # github:nix-community/nh instead of nixos-rebuild, etc 3 - { lib, den, inputs, ... }: 4 - let 5 - defaultAction = "build"; 6 - 7 - denShell = 8 - pkgs: 9 - pkgs.mkShell { 10 - buildInputs = [ pkgs.nh ] ++ (denApps pkgs); 11 - }; 12 - 13 - hosts = lib.concatMap lib.attrValues (lib.attrValues den.hosts); 14 - homes = lib.concatMap lib.attrValues (lib.attrValues den.homes); 15 - 16 - denApps = pkgs: (map (os pkgs) hosts) ++ (map (hm pkgs) homes); 17 - 18 - os = 19 - pkgs: host: 20 - pkgs.writeShellApplication { 21 - name = host.name; 22 - runtimeInputs = [ pkgs.nh ]; 23 - text = 24 - let 25 - command = 26 - { 27 - darwin = "darwin"; 28 - nixos = "os"; 29 - } 30 - .${host.class}; 31 - attr = lib.concatStringsSep "." ([ "flake" ] ++ host.intoAttr); 32 - args = lib.concatStringsSep " " [ 33 - "--file" 34 - "." 35 - attr 36 - ]; 37 - in 38 - '' 39 - action="''${1:-${defaultAction}}" 40 - shift || true 41 - exec nh ${command} "$action" ${args} "$@" 42 - ''; 43 - }; 44 - 45 - hm = 46 - pkgs: home: 47 - pkgs.writeShellApplication { 48 - name = home.name; 49 - runtimeInputs = [ pkgs.nh ]; 50 - text = 51 - let 52 - attr = lib.concatStringsSep "." ([ "flake" ] ++ home.intoAttr); 53 - args = lib.concatStringsSep " " [ 54 - "--file" 55 - "." 56 - attr 57 - ]; 58 - in 59 - '' 60 - action="''${1:-${defaultAction}}" 61 - shift || true 62 - exec nh home "$action" ${args} "$@" 63 - ''; 64 - }; 65 - in 3 + { 4 + lib, 5 + den, 6 + inputs, 7 + ... 8 + }: 66 9 { 67 10 options.den.sh = lib.mkOption { 68 11 description = "Non-flake Den shell environment"; 69 - default = denShell (import inputs.nixpkgs { }); 12 + default = den.lib.nh.denShell (import inputs.nixpkgs { }); 70 13 }; 71 14 }