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

feat: add inputs' and self' aspects (#117)

Adds `inputs'` and `self'` aspects

authored by

Heitor Augusto and committed by
GitHub
4d439f49 3ec43279

+161
+42
modules/aspects/provides/inputs.nix
··· 1 + { den, withSystem, ... }: 2 + { 3 + den.provides.inputs' = den.lib.parametric { 4 + description = '' 5 + Provides the `flake-parts` `inputs'` (the flake's `inputs` with system pre-selected) 6 + as a top-level module argument. This allows modules to access per-system 7 + flake outputs without needing `pkgs.stdenv.hostPlatform.system`. 8 + 9 + ## Usage 10 + 11 + # makes inputs' available to modules in my-aspect 12 + den.aspects.my-aspect.includes = [ den._.inputs' ]; 13 + 14 + # module implementation 15 + { inputs', ... }: { 16 + # use inputs' as needed 17 + } 18 + ''; 19 + 20 + includes = [ 21 + ( 22 + { host, user, ... }: 23 + (withSystem host.system ( 24 + { inputs', ... }: 25 + { 26 + ${host.class}._module.args.inputs' = inputs'; 27 + ${user.class or null}._module.args.inputs' = inputs'; 28 + } 29 + )) 30 + ) 31 + ( 32 + { home, ... }: 33 + (withSystem home.system ( 34 + { inputs', ... }: 35 + { 36 + ${home.class}._module.args.inputs' = inputs'; 37 + } 38 + )) 39 + ) 40 + ]; 41 + }; 42 + }
+42
modules/aspects/provides/self.nix
··· 1 + { den, withSystem, ... }: 2 + { 3 + den.provides.self' = den.lib.parametric { 4 + description = '' 5 + Provides the `flake-parts` `self'` (the flake's `self` with system pre-selected) 6 + as a top-level module argument. This allows modules to access per-system 7 + flake outputs without needing `pkgs.stdenv.hostPlatform.system`. 8 + 9 + ## Usage 10 + 11 + # makes self' available to modules in my-aspect 12 + den.aspects.my-aspect.includes = [ den._.self' ]; 13 + 14 + # module implementation 15 + { self', ... }: { 16 + # use self' as needed 17 + } 18 + ''; 19 + 20 + includes = [ 21 + ( 22 + { host, user, ... }: 23 + (withSystem host.system ( 24 + { self', ... }: 25 + { 26 + ${host.class}._module.args.self' = self'; 27 + ${user.class or null}._module.args.self' = self'; 28 + } 29 + )) 30 + ) 31 + ( 32 + { home, ... }: 33 + (withSystem home.system ( 34 + { self', ... }: 35 + { 36 + ${home.class}._module.args.self' = self'; 37 + } 38 + )) 39 + ) 40 + ]; 41 + }; 42 + }
+7
templates/examples/flake.nix
··· 25 25 url = "github:nix-community/home-manager/release-25.05"; 26 26 }; 27 27 import-tree.url = "github:vic/import-tree"; 28 + neovim-nightly-overlay = { 29 + inputs = { 30 + flake-parts.follows = "flake-parts"; 31 + nixpkgs.follows = "nixpkgs"; 32 + }; 33 + url = "github:nix-community/neovim-nightly-overlay"; 34 + }; 28 35 nixos-wsl = { 29 36 inputs = { 30 37 flake-compat.follows = "";
+70
templates/examples/modules/_example/ci/special-args.nix
··· 1 + { den, withSystem, ... }: 2 + let 3 + testModule = 4 + { 5 + inputs', 6 + lib, 7 + self', 8 + ... 9 + }: 10 + { 11 + options.specialArgsTest = { 12 + test-package = lib.mkOption { type = lib.types.package; }; 13 + neovim-package = lib.mkOption { type = lib.types.package; }; 14 + }; 15 + 16 + config.specialArgsTest = { 17 + test-package = self'.packages.hello; 18 + neovim-package = inputs'.neovim-nightly-overlay.packages.neovim; 19 + }; 20 + }; 21 + in 22 + { 23 + flake-file.inputs.neovim-nightly-overlay = { 24 + url = "github:nix-community/neovim-nightly-overlay"; 25 + inputs.nixpkgs.follows = "nixpkgs"; 26 + inputs.flake-parts.follows = "flake-parts"; 27 + }; 28 + 29 + den.default.includes = [ 30 + den._.self' 31 + den._.inputs' 32 + ]; 33 + 34 + den.aspects.rockhopper.nixos.imports = [ testModule ]; 35 + den.aspects.cam.homeManager.imports = [ testModule ]; 36 + 37 + flake.checks.x86_64-linux = withSystem "x86_64-linux" ( 38 + { 39 + checkCond, 40 + rockhopper, 41 + cam, 42 + self', 43 + inputs', 44 + ... 45 + }: 46 + { 47 + special-args-self-nixos = checkCond "self' provides same package to nixos" ( 48 + rockhopper.config.specialArgsTest.test-package == self'.packages.hello 49 + ); 50 + 51 + special-args-inputs-nixos = checkCond "inputs' provides same package to nixos" ( 52 + rockhopper.config.specialArgsTest.neovim-package == inputs'.neovim-nightly-overlay.packages.neovim 53 + ); 54 + 55 + special-args-self-hm = checkCond "self' provides same package to home-manager" ( 56 + cam.config.specialArgsTest.test-package == self'.packages.hello 57 + ); 58 + 59 + special-args-inputs-hm = checkCond "inputs' provides same package to home-manager" ( 60 + cam.config.specialArgsTest.neovim-package == inputs'.neovim-nightly-overlay.packages.neovim 61 + ); 62 + } 63 + ); 64 + 65 + perSystem = 66 + { pkgs, ... }: 67 + { 68 + packages.hello = pkgs.hello; 69 + }; 70 + }