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

host/home apps at flakes/noflake for building with nh (#233)

authored by oeiuwq.com and committed by

GitHub 0a84eba5 2a654815

+127 -18
+47 -17
nix/nh.nix
··· 5 5 defaultAction = "build"; 6 6 7 7 denShell = 8 - pkgs: 8 + args: pkgs: 9 9 pkgs.mkShell { 10 - buildInputs = [ pkgs.nh ] ++ (denApps pkgs); 10 + buildInputs = [ pkgs.nh ] ++ (denApps args pkgs); 11 11 }; 12 12 13 + denPackages = 14 + args: pkgs: 15 + lib.listToAttrs ( 16 + map (a: { 17 + name = a.name; 18 + value = a; 19 + }) (denApps args pkgs) 20 + ); 21 + 13 22 hosts = lib.concatMap lib.attrValues (lib.attrValues den.hosts); 14 23 homes = lib.concatMap lib.attrValues (lib.attrValues den.homes); 15 24 16 - hostApps = pkgs: map (os pkgs) hosts; 17 - homeApps = pkgs: map (hm pkgs) homes; 18 - denApps = pkgs: (hostApps pkgs) ++ (homeApps pkgs); 25 + hostApps = args: pkgs: map (os args pkgs) hosts; 26 + homeApps = args: pkgs: map (hm args pkgs) homes; 27 + denApps = args: pkgs: (hostApps args pkgs) ++ (homeApps args pkgs); 19 28 20 29 os = 30 + { 31 + outPrefix ? [ ], 32 + fromFlake ? true, 33 + fromPath ? ".", 34 + }: 21 35 pkgs: host: 22 36 pkgs.writeShellApplication { 23 37 name = host.name; ··· 30 44 nixos = "os"; 31 45 } 32 46 .${host.class}; 33 - attr = lib.concatStringsSep "." ([ "flake" ] ++ host.intoAttr); 34 - args = lib.concatStringsSep " " [ 35 - "--file" 36 - "." 37 - attr 38 - ]; 47 + attr = lib.concatStringsSep "." (outPrefix ++ host.intoAttr); 48 + from = 49 + if fromFlake then 50 + [ "${fromPath}#.${attr}" ] 51 + else 52 + [ 53 + "--file" 54 + fromPath 55 + attr 56 + ]; 57 + args = lib.concatStringsSep " " from; 39 58 in 40 59 '' 41 60 action="''${1:-${defaultAction}}" ··· 45 64 }; 46 65 47 66 hm = 67 + { 68 + outPrefix ? [ ], 69 + fromFlake ? true, 70 + fromPath ? ".", 71 + }: 48 72 pkgs: home: 49 73 pkgs.writeShellApplication { 50 74 name = home.name; 51 75 runtimeInputs = [ pkgs.nh ]; 52 76 text = 53 77 let 54 - attr = lib.concatStringsSep "." ([ "flake" ] ++ home.intoAttr); 55 - args = lib.concatStringsSep " " [ 56 - "--file" 57 - "." 58 - attr 59 - ]; 78 + attr = lib.concatStringsSep "." (outPrefix ++ home.intoAttr); 79 + from = 80 + if fromFlake then 81 + [ "${fromPath}#.${attr}" ] 82 + else 83 + [ 84 + "--file" 85 + fromPath 86 + attr 87 + ]; 88 + args = lib.concatStringsSep " " from; 60 89 in 61 90 '' 62 91 action="''${1:-${defaultAction}}" ··· 67 96 in 68 97 { 69 98 inherit 99 + denPackages 70 100 denShell 71 101 homeApps 72 102 hostApps
+10
templates/default/README.md
··· 12 12 13 13 - Edit [modules/hosts.nix](modules/hosts.nix) 14 14 15 + - Build 16 + 17 + ```console 18 + # default action is build 19 + nix run .#igloo 20 + 21 + # pass any other nh action 22 + nix run .#igloo -- switch 23 + ``` 24 + 15 25 - Run the VM 16 26 17 27 We recommend to use a VM develop cycle so you can play with the system before applying to your hardware.
+9
templates/default/modules/nh.nix
··· 1 + # Exposes flake apps under the name of each host / home for building with nh. 2 + { den, lib, ... }: 3 + { 4 + perSystem = 5 + { pkgs, ... }: 6 + { 7 + packages = den.lib.nh.denPackages { fromFlake = true; } pkgs; 8 + }; 9 + }
+10
templates/example/README.md
··· 27 27 28 28 - Read [modules/aspects/alice.nix](modules/aspects/alice.nix) where the `alice` user is configured. 29 29 30 + - Build 31 + 32 + ```console 33 + # default action is build 34 + nix run .#igloo 35 + 36 + # pass any other nh action 37 + nix run .#igloo -- switch 38 + ``` 39 + 30 40 - Run the VM. 31 41 32 42 ```console
+9
templates/example/modules/nh.nix
··· 1 + # Exposes flake apps under the name of each host / home for building with nh. 2 + { den, lib, ... }: 3 + { 4 + perSystem = 5 + { pkgs, ... }: 6 + { 7 + packages = den.lib.nh.denPackages { fromFlake = true; } pkgs; 8 + }; 9 + }
+23
templates/minimal/README.md
··· 1 + # Getting Started Guide 2 + 3 + Steps you can follow after cloning this template: 4 + 5 + - Be sure to read the [den documentation](https://vic.github.io/den) 6 + 7 + - Update den input. 8 + 9 + ```console 10 + nix flake update den 11 + ``` 12 + 13 + - Edit [modules/den.nix](modules/den.nix) 14 + 15 + - Build 16 + 17 + ```console 18 + # default action is build 19 + nix run .#igloo 20 + 21 + # pass any other nh action 22 + nix run .#igloo -- switch 23 + ```
+15
templates/minimal/modules/nh.nix
··· 1 + # Exposes flake apps under the name of each host / home for building with nh. 2 + { 3 + den, 4 + lib, 5 + inputs, 6 + ... 7 + }: 8 + { 9 + 10 + flake.packages = lib.genAttrs lib.systems.flakeExposed ( 11 + system: 12 + 13 + den.lib.nh.denPackages { fromFlake = true; } inputs.nixpkgs.legacyPackages.${system} 14 + ); 15 + }
+4 -1
templates/noflake/modules/nh.nix
··· 9 9 { 10 10 options.den.sh = lib.mkOption { 11 11 description = "Non-flake Den shell environment"; 12 - default = den.lib.nh.denShell (import inputs.nixpkgs { }); 12 + default = den.lib.nh.denShell { 13 + fromFlake = false; 14 + outPrefix = [ "flake" ]; 15 + } (import inputs.nixpkgs { }); 13 16 }; 14 17 }