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

Compare changes

Choose any two refs to compare.

+283 -983
+1 -12
.github/workflows/test.yml
··· 18 steps: 19 - uses: cachix/install-nix-action@v31 20 - run: nix flake check -L github:vic/checkmate --override-input target github:$GITHUB_REPOSITORY/$GITHUB_SHA 21 - noflake: 22 - needs: [non-draft] 23 - name: noflake 24 - runs-on: ubuntu-latest 25 - steps: 26 - - uses: wimpysworld/nothing-but-nix@main 27 - - uses: cachix/install-nix-action@v31 28 - - uses: DeterminateSystems/magic-nix-cache-action@v13 29 - - uses: actions/checkout@v4 30 - - run: sed -i 's@# den.outPath@den.outPath@' templates/noflake/with-inputs.nix 31 - - run: cd templates/noflake && nix-build -A nixosConfigurations.igloo.config.system.build.toplevel 32 template: 33 needs: [non-draft] 34 strategy: ··· 55 - run: nix flake update den 56 - run: nix run .#write-flake 57 - run: nix flake metadata 58 - - run: nix flake check
··· 18 steps: 19 - uses: cachix/install-nix-action@v31 20 - run: nix flake check -L github:vic/checkmate --override-input target github:$GITHUB_REPOSITORY/$GITHUB_SHA 21 template: 22 needs: [non-draft] 23 strategy: ··· 44 - run: nix flake update den 45 - run: nix run .#write-flake 46 - run: nix flake metadata 47 + - run: nix flake check -L
+5 -9
README.md
··· 1 <p align="right"> 2 <a href="https://github.com/sponsors/vic"><img src="https://img.shields.io/badge/sponsor-vic-white?logo=githubsponsors&logoColor=white&labelColor=%23FF0000" alt="Sponsor Vic"/> 3 </a> 4 - <a href="https://deepwiki.com/vic/den"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a> 5 <a href="https://github.com/vic/den/releases"><img src="https://img.shields.io/github/v/release/vic/den?style=plastic&logo=github&color=purple"/></a> 6 <a href="https://vic.github.io/dendrix/Dendritic-Ecosystem.html#vics-dendritic-libraries"> <img src="https://img.shields.io/badge/Dendritic-Nix-informational?logo=nixos&logoColor=white" alt="Dendritic Nix"/> </a> 7 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/den" alt="License"/> </a> ··· 20 21 <img width="300" height="300" alt="den" src="https://github.com/user-attachments/assets/af9c9bca-ab8b-4682-8678-31a70d510bbb" /> 22 23 - - [Dendritic](https://github.com/mightyiam/dendritic): **same** concern across **different** Nix classes. 24 - 25 - - [Flake optional](templates/noflake). Works with _stable_/_unstable_ Nix and with/without flake-parts. 26 27 - Create [DRY](modules/aspects/provides/unfree.nix) & [`class`-generic](modules/aspects/provides/primary-user.nix) modules. 28 29 - [Parametric](modules/aspects/provides/define-user.nix) over `host`/`home`/`user`. 30 - 31 - - Context-aware [dependencies](modules/aspects/dependencies.nix): user/host contributions. 32 33 - [Share](templates/default/modules/namespace.nix) aspects across systems & repos. 34 35 - [Routable](templates/default/modules/aspects/eg/routes.nix) configurations. 36 37 - Custom factories for any Nix `class`. 38 39 - Use `stable`/`unstable` channels per config. 40 41 - - Freeform `host`/`user`/`home` [schemas](modules/_types.nix) (no `specialArgs`) with base modules. 42 43 - Multi-platform, multi-tenant hosts. 44 ··· 71 **Real-world examples for inspiration** 72 73 - [`vic/vix`](https://github.com/vic/vix/tree/den) 74 - - [`quasigod.xyz/nixconfig`](https://tangled.org/quasigod.xyz/nixconfig) 75 - [GitHub Search](https://github.com/search?q=vic%2Fden+language%3ANix&type=code). 76 77 **Available templates** 78 79 - [`default`](templates/default) batteries-included layout. 80 - [`minimal`](templates/minimal) truly minimalistic start. 81 - - [`noflake`](templates/noflake) no flakes, no flake-parts, user nix-maid. 82 - [`examples`](templates/examples) tests for all features. 83 - [`bogus`](templates/bogus) reproduce and report bugs. 84
··· 1 <p align="right"> 2 <a href="https://github.com/sponsors/vic"><img src="https://img.shields.io/badge/sponsor-vic-white?logo=githubsponsors&logoColor=white&labelColor=%23FF0000" alt="Sponsor Vic"/> 3 </a> 4 <a href="https://github.com/vic/den/releases"><img src="https://img.shields.io/github/v/release/vic/den?style=plastic&logo=github&color=purple"/></a> 5 <a href="https://vic.github.io/dendrix/Dendritic-Ecosystem.html#vics-dendritic-libraries"> <img src="https://img.shields.io/badge/Dendritic-Nix-informational?logo=nixos&logoColor=white" alt="Dendritic Nix"/> </a> 6 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/den" alt="License"/> </a> ··· 19 20 <img width="300" height="300" alt="den" src="https://github.com/user-attachments/assets/af9c9bca-ab8b-4682-8678-31a70d510bbb" /> 21 22 + - Dendritic: each module configures **same** concern over **different** Nix classes. 23 24 - Create [DRY](modules/aspects/provides/unfree.nix) & [`class`-generic](modules/aspects/provides/primary-user.nix) modules. 25 26 - [Parametric](modules/aspects/provides/define-user.nix) over `host`/`home`/`user`. 27 28 - [Share](templates/default/modules/namespace.nix) aspects across systems & repos. 29 30 + - Context-aware [dependencies](modules/aspects/dependencies.nix): user/host contributions. 31 + 32 - [Routable](templates/default/modules/aspects/eg/routes.nix) configurations. 33 34 - Custom factories for any Nix `class`. 35 36 - Use `stable`/`unstable` channels per config. 37 38 + - Freeform `host`/`user`/`home` [schemas](modules/_types.nix) (no `specialArgs`). 39 40 - Multi-platform, multi-tenant hosts. 41 ··· 68 **Real-world examples for inspiration** 69 70 - [`vic/vix`](https://github.com/vic/vix/tree/den) 71 + - [`belsanti.xyz/nixconfig`](https://tangled.org/belsanti.xyz/nixconfig/tree/den) 72 - [GitHub Search](https://github.com/search?q=vic%2Fden+language%3ANix&type=code). 73 74 **Available templates** 75 76 - [`default`](templates/default) batteries-included layout. 77 - [`minimal`](templates/minimal) truly minimalistic start. 78 - [`examples`](templates/examples) tests for all features. 79 - [`bogus`](templates/bogus) reproduce and report bugs. 80
+10 -16
modules/aspects/provides/inputs.nix
··· 1 { den, withSystem, ... }: 2 - let 3 - inherit (den.lib) 4 - parametric 5 - take 6 - ; 7 - in 8 { 9 - den.provides.inputs' = parametric.exactly { 10 description = '' 11 Provides the `flake-parts` `inputs'` (the flake's `inputs` with system pre-selected) 12 as a top-level module argument. ··· 36 ( 37 { OS, host }: 38 let 39 - unused = take.unused OS; 40 in 41 withSystem host.system ( 42 { inputs', ... }: 43 - unused { 44 - ${host.class}._module.args.inputs' = inputs'; 45 } 46 ) 47 ) ··· 53 host, 54 }: 55 let 56 - unused = take.unused [ 57 OS 58 HM 59 ]; 60 in 61 withSystem host.system ( 62 { inputs', ... }: 63 - unused { 64 - ${user.class}._module.args.inputs' = inputs'; 65 } 66 ) 67 ) 68 ( 69 { HM, home }: 70 let 71 - unused = take.unused HM; 72 in 73 withSystem home.system ( 74 { inputs', ... }: 75 - unused { 76 - ${home.class}._module.args.inputs' = inputs'; 77 } 78 ) 79 )
··· 1 { den, withSystem, ... }: 2 { 3 + den.provides.inputs' = den.lib.parametric.exactly { 4 description = '' 5 Provides the `flake-parts` `inputs'` (the flake's `inputs` with system pre-selected) 6 as a top-level module argument. ··· 30 ( 31 { OS, host }: 32 let 33 + unused = den.lib.take.unused OS; 34 in 35 withSystem host.system ( 36 { inputs', ... }: 37 + { 38 + ${host.class}._module.args.inputs' = unused inputs'; 39 } 40 ) 41 ) ··· 47 host, 48 }: 49 let 50 + unused = den.lib.take.unused [ 51 OS 52 HM 53 ]; 54 in 55 withSystem host.system ( 56 { inputs', ... }: 57 + { 58 + ${user.class}._module.args.inputs' = unused inputs'; 59 } 60 ) 61 ) 62 ( 63 { HM, home }: 64 let 65 + unused = den.lib.take.unused HM; 66 in 67 withSystem home.system ( 68 { inputs', ... }: 69 + { 70 + ${home.class}._module.args.inputs' = unused inputs'; 71 } 72 ) 73 )
-91
modules/aspects/provides/unfree/unfree-predicate-builder.nix
··· 1 - { den, lib, ... }: 2 - let 3 - inherit (den.lib) 4 - parametric 5 - take 6 - ; 7 - 8 - description = '' 9 - This is a private aspect always included in den.default. 10 - 11 - It adds a module option that gathers all packages defined 12 - in den._.unfree usages and declares a 13 - nixpkgs.config.allowUnfreePredicate for each class. 14 - 15 - ''; 16 - 17 - unfreeComposableModule.options.unfree = { 18 - packages = lib.mkOption { 19 - type = lib.types.listOf lib.types.str; 20 - default = [ ]; 21 - }; 22 - }; 23 - 24 - nixosAspect = 25 - { config, ... }: 26 - { 27 - nixpkgs.config.allowUnfreePredicate = (pkg: builtins.elem (lib.getName pkg) config.unfree.packages); 28 - }; 29 - 30 - homeManagerAspect = 31 - { config, osConfig, ... }: 32 - { 33 - nixpkgs = lib.mkIf (!osConfig.home-manager.useGlobalPkgs) { 34 - config.allowUnfreePredicate = (pkg: builtins.elem (lib.getName pkg) config.unfree.packages); 35 - }; 36 - }; 37 - 38 - aspect = parametric.exactly { 39 - inherit description; 40 - includes = [ 41 - ( 42 - { OS, host }: 43 - let 44 - unused = take.unused OS; 45 - in 46 - { 47 - ${host.class}.imports = unused [ 48 - unfreeComposableModule 49 - nixosAspect 50 - ]; 51 - } 52 - ) 53 - ( 54 - { 55 - OS, 56 - HM, 57 - user, 58 - host, 59 - }: 60 - let 61 - unused = take.unused [ 62 - OS 63 - HM 64 - host 65 - ]; 66 - in 67 - { 68 - ${user.class}.imports = unused [ 69 - unfreeComposableModule 70 - homeManagerAspect 71 - ]; 72 - } 73 - ) 74 - ( 75 - { HM, home }: 76 - let 77 - unused = take.unused HM; 78 - in 79 - { 80 - ${home.class}.imports = unused [ 81 - unfreeComposableModule 82 - nixosAspect 83 - ]; 84 - } 85 - ) 86 - ]; 87 - }; 88 - in 89 - { 90 - den.default.includes = [ aspect ]; 91 - }
···
-21
modules/aspects/provides/unfree/unfree.nix
··· 1 - { den, ... }: 2 - { 3 - den.provides.unfree.description = '' 4 - A class generic aspect that enables unfree packages by name. 5 - 6 - Works for any class (nixos/darwin/homeManager,etc) on any host/user/home context. 7 - 8 - ## Usage 9 - 10 - den.aspects.my-laptop.includes = [ (den._.unfree [ "code" ]) ]; 11 - 12 - It will dynamically provide a module for each class when accessed. 13 - ''; 14 - 15 - den.provides.unfree.__functor = 16 - _self: allowed-names: 17 - { class, aspect-chain }: 18 - den.lib.take.unused aspect-chain { 19 - ${class}.unfree.packages = allowed-names; 20 - }; 21 - }
···
+21
modules/aspects/provides/unfree.nix
···
··· 1 + { lib, den, ... }: 2 + { 3 + den.provides.unfree.description = '' 4 + A class generic aspect that enables unfree packages by name. 5 + 6 + Works for any class (nixos/darwin/homeManager,etc) on any host/user/home context. 7 + 8 + ## Usage 9 + 10 + den.aspects.my-laptop.includes = [ (den._.unfree [ "code" ]) ]; 11 + 12 + It will dynamically provide a module for each class when accessed. 13 + ''; 14 + 15 + den.provides.unfree.__functor = 16 + _self: allowed-names: 17 + { class, aspect-chain }: 18 + den.lib.take.unused aspect-chain { 19 + ${class}.nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) allowed-names; 20 + }; 21 + }
+50 -6
nix/namespace.nix
··· 3 let 4 from = lib.flatten [ sources ]; 5 isOutput = builtins.any (x: x == true) from; 6 - denfuls = map (lib.getAttrFromPath [ 7 - "denful" 8 - name 9 - ]) (builtins.filter builtins.isAttrs from); 10 11 sourceModule = { 12 - config.den.ful.${name} = lib.mkMerge denfuls; 13 }; 14 15 aliasModule = lib.mkAliasOptionModule [ name ] [ "den" "ful" name ]; ··· 17 outputModule = 18 if isOutput then 19 { 20 - config.flake.denful.${name} = config.den.ful.${name}; 21 } 22 else 23 { };
··· 3 let 4 from = lib.flatten [ sources ]; 5 isOutput = builtins.any (x: x == true) from; 6 + attrs = builtins.filter builtins.isAttrs from; 7 + 8 + # Strip module system metadata to get clean raw values 9 + stripMeta = value: 10 + if builtins.isList value then 11 + map stripMeta value 12 + else if builtins.isAttrs value then 13 + let 14 + # Remove module system special attributes 15 + cleaned = builtins.removeAttrs value [ 16 + "__functor" 17 + "__functionArgs" 18 + "_module" 19 + "config" 20 + ]; 21 + in 22 + lib.mapAttrs (_: stripMeta) cleaned 23 + else 24 + value; 25 + 26 + # Deep merge that concatenates lists instead of overwriting them 27 + deepMergeWith = lhs: rhs: 28 + if builtins.isList lhs && builtins.isList rhs then 29 + lhs ++ rhs 30 + else if builtins.isAttrs lhs && builtins.isAttrs rhs then 31 + let 32 + allKeys = lib.unique (builtins.attrNames lhs ++ builtins.attrNames rhs); 33 + mergedAttrs = builtins.listToAttrs (map (name: { 34 + inherit name; 35 + value = 36 + if lhs ? ${name} && rhs ? ${name} then 37 + deepMergeWith lhs.${name} rhs.${name} 38 + else if lhs ? ${name} then 39 + lhs.${name} 40 + else 41 + rhs.${name}; 42 + }) allKeys); 43 + in 44 + mergedAttrs 45 + else 46 + rhs; 47 + 48 + # Extract denful values, strip metadata, and merge them deeply before passing to module system 49 + deepMerge = builtins.foldl' (acc: x: 50 + deepMergeWith acc (stripMeta (lib.getAttrFromPath [ "denful" name ] x)) 51 + ) { } attrs; 52 53 sourceModule = { 54 + config.den.ful.${name} = deepMerge; 55 }; 56 57 aliasModule = lib.mkAliasOptionModule [ name ] [ "den" "ful" name ]; ··· 59 outputModule = 60 if isOutput then 61 { 62 + # Use mkOptionDefault to ensure this assignment has lower priority 63 + # This prevents re-evaluation and duplication issues 64 + config.flake.denful.${name} = lib.mkOptionDefault config.den.ful.${name}; 65 } 66 else 67 { };
+3 -3
templates/bogus/flake.lock
··· 38 }, 39 "flake-aspects": { 40 "locked": { 41 - "lastModified": 1769717274, 42 - "narHash": "sha256-U15OaMr9AcJiB1wW2uCFzFO+DnQ3jJSvln+ZR/+Q0vE=", 43 "owner": "vic", 44 "repo": "flake-aspects", 45 - "rev": "a35ed5efc9a629694d659d606230ba18a76cefaa", 46 "type": "github" 47 }, 48 "original": {
··· 38 }, 39 "flake-aspects": { 40 "locked": { 41 + "lastModified": 1766081176, 42 + "narHash": "sha256-JrsuNSIEXPS3AiIxuWZw+sJ2Td6ni1OkqbW6mO/F4Rs=", 43 "owner": "vic", 44 "repo": "flake-aspects", 45 + "rev": "d0a226c84be2900d307aa1896e4e2c6e451844b2", 46 "type": "github" 47 }, 48 "original": {
+3 -3
templates/default/flake.lock
··· 37 }, 38 "flake-aspects": { 39 "locked": { 40 - "lastModified": 1769717274, 41 - "narHash": "sha256-U15OaMr9AcJiB1wW2uCFzFO+DnQ3jJSvln+ZR/+Q0vE=", 42 "owner": "vic", 43 "repo": "flake-aspects", 44 - "rev": "a35ed5efc9a629694d659d606230ba18a76cefaa", 45 "type": "github" 46 }, 47 "original": {
··· 37 }, 38 "flake-aspects": { 39 "locked": { 40 + "lastModified": 1766081176, 41 + "narHash": "sha256-JrsuNSIEXPS3AiIxuWZw+sJ2Td6ni1OkqbW6mO/F4Rs=", 42 "owner": "vic", 43 "repo": "flake-aspects", 44 + "rev": "d0a226c84be2900d307aa1896e4e2c6e451844b2", 45 "type": "github" 46 }, 47 "original": {
+1 -1
templates/default/modules/vm.nix
··· 1 # enables `nix run .#vm`. it is very useful to have a VM 2 - # you can edit your config and launch the VM to test stuff 3 # instead of having to reboot each time. 4 { inputs, eg, ... }: 5 {
··· 1 # enables `nix run .#vm`. it is very useful to have a VM 2 + # you can edit your config an launch the VM to test stuff 3 # instead of having to reboot each time. 4 { inputs, eg, ... }: 5 {
+36 -36
templates/examples/flake.lock
··· 22 }, 23 "den": { 24 "locked": { 25 - "lastModified": 1767645236, 26 - "narHash": "sha256-VMrWett3fWRb0hQh9K1JUC3zV2OlV4zOajFZHGr1GPw=", 27 "owner": "vic", 28 "repo": "den", 29 - "rev": "e7837daa0ea0f03fba62a2653ce16314a7d9d1c8", 30 "type": "github" 31 }, 32 "original": { ··· 37 }, 38 "flake-aspects": { 39 "locked": { 40 - "lastModified": 1769717274, 41 - "narHash": "sha256-U15OaMr9AcJiB1wW2uCFzFO+DnQ3jJSvln+ZR/+Q0vE=", 42 "owner": "vic", 43 "repo": "flake-aspects", 44 - "rev": "a35ed5efc9a629694d659d606230ba18a76cefaa", 45 "type": "github" 46 }, 47 "original": { ··· 234 "type": "github" 235 } 236 }, 237 - "provider": { 238 - "inputs": { 239 - "den": [ 240 - "den" 241 - ], 242 - "flake-aspects": [ 243 - "flake-aspects" 244 - ], 245 - "flake-parts": [ 246 - "flake-parts" 247 - ], 248 - "import-tree": [ 249 - "import-tree" 250 - ], 251 - "nixpkgs": [ 252 - "nixpkgs" 253 - ] 254 - }, 255 - "locked": { 256 - "path": "./provider", 257 - "type": "path" 258 - }, 259 - "original": { 260 - "path": "./provider", 261 - "type": "path" 262 - }, 263 - "parent": [] 264 - }, 265 "root": { 266 "inputs": { 267 "darwin": "darwin", ··· 279 "nixpkgs" 280 ], 281 "nixpkgs-stable": "nixpkgs-stable", 282 - "provider": "provider", 283 - "systems": "systems" 284 } 285 }, 286 "systems": { ··· 297 "repo": "default", 298 "type": "github" 299 } 300 } 301 }, 302 "root": "root",
··· 22 }, 23 "den": { 24 "locked": { 25 + "lastModified": 1766081768, 26 + "narHash": "sha256-8Ea1DW3YZHifezfdEFHWEIpZBNKvEL+3iFOEcl3eFBU=", 27 "owner": "vic", 28 "repo": "den", 29 + "rev": "7271da18c60ab4d7c275ecaab480d29729f05d17", 30 "type": "github" 31 }, 32 "original": { ··· 37 }, 38 "flake-aspects": { 39 "locked": { 40 + "lastModified": 1766081176, 41 + "narHash": "sha256-JrsuNSIEXPS3AiIxuWZw+sJ2Td6ni1OkqbW6mO/F4Rs=", 42 "owner": "vic", 43 "repo": "flake-aspects", 44 + "rev": "d0a226c84be2900d307aa1896e4e2c6e451844b2", 45 "type": "github" 46 }, 47 "original": { ··· 234 "type": "github" 235 } 236 }, 237 "root": { 238 "inputs": { 239 "darwin": "darwin", ··· 251 "nixpkgs" 252 ], 253 "nixpkgs-stable": "nixpkgs-stable", 254 + "systems": "systems", 255 + "theirs": "theirs" 256 } 257 }, 258 "systems": { ··· 269 "repo": "default", 270 "type": "github" 271 } 272 + }, 273 + "theirs": { 274 + "inputs": { 275 + "den": [ 276 + "den" 277 + ], 278 + "flake-aspects": [ 279 + "flake-aspects" 280 + ], 281 + "flake-parts": [ 282 + "flake-parts" 283 + ], 284 + "import-tree": [ 285 + "import-tree" 286 + ], 287 + "nixpkgs": [ 288 + "nixpkgs" 289 + ] 290 + }, 291 + "locked": { 292 + "path": "./modules/_example/ci/_theirs", 293 + "type": "path" 294 + }, 295 + "original": { 296 + "path": "./modules/_example/ci/_theirs", 297 + "type": "path" 298 + }, 299 + "parent": [] 300 } 301 }, 302 "root": "root",
+3 -3
templates/examples/flake.nix
··· 42 nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 43 nixpkgs-lib.follows = "nixpkgs"; 44 nixpkgs-stable.url = "github:nixos/nixpkgs/release-25.05"; 45 - provider = { 46 inputs = { 47 den.follows = "den"; 48 flake-aspects.follows = "flake-aspects"; ··· 50 import-tree.follows = "import-tree"; 51 nixpkgs.follows = "nixpkgs"; 52 }; 53 - url = "path:./provider"; 54 }; 55 - systems.url = "github:nix-systems/default"; 56 }; 57 58 }
··· 42 nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 43 nixpkgs-lib.follows = "nixpkgs"; 44 nixpkgs-stable.url = "github:nixos/nixpkgs/release-25.05"; 45 + systems.url = "github:nix-systems/default"; 46 + theirs = { 47 inputs = { 48 den.follows = "den"; 49 flake-aspects.follows = "flake-aspects"; ··· 51 import-tree.follows = "import-tree"; 52 nixpkgs.follows = "nixpkgs"; 53 }; 54 + url = "path:./modules/_example/ci/_theirs"; 55 }; 56 }; 57 58 }
+96
templates/examples/modules/_example/ci/_theirs/flake.lock
···
··· 1 + { 2 + "nodes": { 3 + "den": { 4 + "locked": { 5 + "lastModified": 1766081768, 6 + "narHash": "sha256-8Ea1DW3YZHifezfdEFHWEIpZBNKvEL+3iFOEcl3eFBU=", 7 + "owner": "vic", 8 + "repo": "den", 9 + "rev": "7271da18c60ab4d7c275ecaab480d29729f05d17", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "vic", 14 + "repo": "den", 15 + "type": "github" 16 + } 17 + }, 18 + "flake-aspects": { 19 + "locked": { 20 + "lastModified": 1766081176, 21 + "narHash": "sha256-JrsuNSIEXPS3AiIxuWZw+sJ2Td6ni1OkqbW6mO/F4Rs=", 22 + "owner": "vic", 23 + "repo": "flake-aspects", 24 + "rev": "d0a226c84be2900d307aa1896e4e2c6e451844b2", 25 + "type": "github" 26 + }, 27 + "original": { 28 + "owner": "vic", 29 + "repo": "flake-aspects", 30 + "type": "github" 31 + } 32 + }, 33 + "flake-parts": { 34 + "inputs": { 35 + "nixpkgs-lib": [ 36 + "nixpkgs" 37 + ] 38 + }, 39 + "locked": { 40 + "lastModified": 1762980239, 41 + "narHash": "sha256-8oNVE8TrD19ulHinjaqONf9QWCKK+w4url56cdStMpM=", 42 + "owner": "hercules-ci", 43 + "repo": "flake-parts", 44 + "rev": "52a2caecc898d0b46b2b905f058ccc5081f842da", 45 + "type": "github" 46 + }, 47 + "original": { 48 + "owner": "hercules-ci", 49 + "repo": "flake-parts", 50 + "type": "github" 51 + } 52 + }, 53 + "import-tree": { 54 + "locked": { 55 + "lastModified": 1763263999, 56 + "narHash": "sha256-AZ4UkBJQKfaL9sX+/mzc1xBtcJk8hDQGkhjWX0Py5hU=", 57 + "owner": "vic", 58 + "repo": "import-tree", 59 + "rev": "058bd03ac818ea349946323ae3c2837b4cab7f22", 60 + "type": "github" 61 + }, 62 + "original": { 63 + "owner": "vic", 64 + "repo": "import-tree", 65 + "type": "github" 66 + } 67 + }, 68 + "nixpkgs": { 69 + "locked": { 70 + "lastModified": 1763464769, 71 + "narHash": "sha256-AJHrsT7VoeQzErpBRlLJM1SODcaayp0joAoEA35yiwM=", 72 + "owner": "nixos", 73 + "repo": "nixpkgs", 74 + "rev": "6f374686605df381de8541c072038472a5ea2e2d", 75 + "type": "github" 76 + }, 77 + "original": { 78 + "owner": "nixos", 79 + "ref": "nixpkgs-unstable", 80 + "repo": "nixpkgs", 81 + "type": "github" 82 + } 83 + }, 84 + "root": { 85 + "inputs": { 86 + "den": "den", 87 + "flake-aspects": "flake-aspects", 88 + "flake-parts": "flake-parts", 89 + "import-tree": "import-tree", 90 + "nixpkgs": "nixpkgs" 91 + } 92 + } 93 + }, 94 + "root": "root", 95 + "version": 7 96 + }
+13
templates/examples/modules/_example/ci/_theirs/flake.nix
···
··· 1 + { 2 + outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 3 + 4 + inputs = { 5 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 6 + flake-parts.url = "github:hercules-ci/flake-parts"; 7 + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 8 + 9 + import-tree.url = "github:vic/import-tree"; 10 + flake-aspects.url = "github:vic/flake-aspects"; 11 + den.url = "github:vic/den"; 12 + }; 13 + }
+21
templates/examples/modules/_example/ci/_theirs/modules/theirs.nix
···
··· 1 + # This flake is for testing by ci/namespace.nix 2 + { inputs, ... }: 3 + { 4 + systems = [ 5 + "x86_64-linux" 6 + "aarch64-darwin" 7 + ]; 8 + imports = [ 9 + inputs.den.flakeModule 10 + (inputs.den.namespace "sim" true) 11 + ]; 12 + 13 + sim.a._.b._.c._.d = { 14 + nixos.sims = [ "theirs abcd" ]; 15 + }; 16 + 17 + sim.ul._.a._.tion = { 18 + nixos.sims = [ "theirs simulation" ]; 19 + }; 20 + 21 + }
-81
templates/examples/modules/_example/ci/angle-bracket-deep.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - ns, 5 - # deadnix: skip 6 - __findFile ? __findFile, 7 - ... 8 - }: 9 - let 10 - treeModule.nixos.options.tree = lib.mkOption { 11 - type = lib.types.listOf lib.types.str; 12 - }; 13 - inputX = { 14 - denful.ns.root = { 15 - nixos.tree = [ "X-root" ]; 16 - provides.branch.nixos.tree = [ "X-branch" ]; 17 - provides.branch.provides.leaf.nixos.tree = [ "X-leaf" ]; 18 - }; 19 - }; 20 - inputY = { 21 - denful.ns.root = { 22 - nixos.tree = [ "Y-root" ]; 23 - provides.branch.nixos.tree = [ "Y-branch" ]; 24 - provides.branch.provides.leaf.nixos.tree = [ "Y-leaf" ]; 25 - }; 26 - }; 27 - in 28 - { 29 - 30 - imports = [ 31 - (inputs.den.namespace "ns" [ 32 - true 33 - inputX 34 - inputY 35 - ]) 36 - ]; 37 - 38 - ns.root = { 39 - nixos.tree = [ "local-root" ]; 40 - provides.branch.nixos.tree = [ "local-branch" ]; 41 - provides.branch.provides.leaf.nixos.tree = [ "local-leaf" ]; 42 - }; 43 - 44 - den.aspects.rockhopper.includes = [ 45 - treeModule 46 - <ns/root> 47 - <ns/root/branch> 48 - <ns/root/branch/leaf> 49 - ]; 50 - 51 - perSystem = 52 - { checkCond, rockhopper, ... }: 53 - let 54 - vals = lib.sort (a: b: a < b) rockhopper.config.tree; 55 - in 56 - { 57 - checks.ns-angle-bracket-root = checkCond "angle-bracket access root" (<ns/root> == ns.root); 58 - 59 - checks.ns-angle-bracket-branch = checkCond "angle-bracket access branch" ( 60 - <ns/root/branch> == ns.root._.branch 61 - ); 62 - 63 - checks.ns-angle-bracket-leaf = checkCond "angle-bracket access leaf" ( 64 - <ns/root/branch/leaf> == ns.root._.branch._.leaf 65 - ); 66 - 67 - checks.ns-tree-all-levels-merged = checkCond "all tree levels merged" ( 68 - vals == [ 69 - "X-branch" 70 - "X-leaf" 71 - "X-root" 72 - "Y-branch" 73 - "Y-leaf" 74 - "Y-root" 75 - "local-branch" 76 - "local-leaf" 77 - "local-root" 78 - ] 79 - ); 80 - }; 81 - }
···
+1 -1
templates/examples/modules/_example/ci/base-conf-modules.nix
··· 9 den.base.host = 10 { host, ... }: 11 { 12 - options.capabilities.ssh-server = lib.mkEnableOption "Does host ${host.name} provide ssh?"; 13 }; 14 15 # This module is base for all user configs.
··· 9 den.base.host = 10 { host, ... }: 11 { 12 + options.capabilities.ssh-server = lib.mkEnableOption "Does host ${host.name} provides ssh?"; 13 }; 14 15 # This module is base for all user configs.
-67
templates/examples/modules/_example/ci/cross-flake-parametric.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - provider, 5 - ... 6 - }: 7 - let 8 - providerModule.nixos.options.providerVars = lib.mkOption { 9 - type = lib.types.attrsOf lib.types.str; 10 - default = { }; 11 - }; 12 - in 13 - { 14 - flake-file.inputs.provider = { 15 - url = "path:./provider"; 16 - inputs.den.follows = "den"; 17 - inputs.flake-aspects.follows = "flake-aspects"; 18 - inputs.flake-parts.follows = "flake-parts"; 19 - inputs.import-tree.follows = "import-tree"; 20 - inputs.nixpkgs.follows = "nixpkgs"; 21 - }; 22 - 23 - imports = [ 24 - (inputs.den.namespace "provider" [ 25 - true 26 - inputs.provider 27 - ]) 28 - ]; 29 - 30 - provider.tools._.dev._.editors = { 31 - nixos.providerVars.LOCAL_EDITOR = "emacs"; 32 - }; 33 - 34 - den.aspects.rockhopper.includes = [ 35 - providerModule 36 - provider.tools._.dev._.editors 37 - provider.tools._.dev._.shells 38 - ]; 39 - 40 - perSystem = 41 - { checkCond, rockhopper, ... }: 42 - let 43 - vars = rockhopper.config.providerVars; 44 - env = rockhopper.config.environment.variables; 45 - in 46 - { 47 - checks.cross-flake-provider-editor = checkCond "provider editor var set" ( 48 - env.PROVIDER_EDITOR == "vim" 49 - ); 50 - 51 - checks.cross-flake-provider-shell = checkCond "provider shell var set" ( 52 - env.PROVIDER_SHELL == "fish" 53 - ); 54 - 55 - checks.cross-flake-local-editor = checkCond "local editor var set" (vars.LOCAL_EDITOR == "emacs"); 56 - 57 - checks.cross-flake-namespace-merged = checkCond "namespace merged from provider input" ( 58 - provider.tools._.dev._.editors == inputs.self.denful.provider.tools._.dev._.editors 59 - && provider.tools._.dev._.shells == inputs.self.denful.provider.tools._.dev._.shells 60 - ); 61 - 62 - checks.cross-flake-input-denful = checkCond "input provider denful accessible" ( 63 - inputs.provider.denful.provider.tools._.dev._.editors.description 64 - == "Editor configurations from provider flake" 65 - ); 66 - }; 67 - }
···
-78
templates/examples/modules/_example/ci/deep-nested-namespace.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - deep, 5 - ... 6 - }: 7 - let 8 - deepModule.nixos.options.deepVals = lib.mkOption { 9 - type = lib.types.listOf lib.types.str; 10 - }; 11 - depthA = { 12 - denful.deep.a._.b._.c._.d._.e = { 13 - description = "5 levels deep from inputA"; 14 - nixos.deepVals = [ "inputA-5-levels" ]; 15 - provides.f.nixos.deepVals = [ "inputA-6-levels" ]; 16 - }; 17 - }; 18 - depthB = { 19 - denful.deep.a._.b._.c._.d._.e = { 20 - nixos.deepVals = [ "inputB-5-levels" ]; 21 - provides.f.nixos.deepVals = [ "inputB-6-levels" ]; 22 - }; 23 - }; 24 - in 25 - { 26 - imports = [ 27 - (inputs.den.namespace "deep" [ 28 - true 29 - depthA 30 - depthB 31 - ]) 32 - ]; 33 - 34 - deep.a._.b._.c._.d._.e = { 35 - nixos.deepVals = [ "local-5-levels" ]; 36 - provides.f.nixos.deepVals = [ "local-6-levels" ]; 37 - }; 38 - 39 - den.aspects.rockhopper.includes = [ 40 - deepModule 41 - deep.a._.b._.c._.d._.e 42 - deep.a._.b._.c._.d._.e._.f 43 - ]; 44 - 45 - perSystem = 46 - { checkCond, rockhopper, ... }: 47 - let 48 - vals = lib.sort (a: b: a < b) rockhopper.config.deepVals; 49 - in 50 - { 51 - checks.deep-nest-5-levels = checkCond "5 levels deep merged correctly" ( 52 - builtins.elem "inputA-5-levels" vals 53 - && builtins.elem "inputB-5-levels" vals 54 - && builtins.elem "local-5-levels" vals 55 - ); 56 - 57 - checks.deep-nest-6-levels = checkCond "6 levels deep merged correctly" ( 58 - builtins.elem "inputA-6-levels" vals 59 - && builtins.elem "inputB-6-levels" vals 60 - && builtins.elem "local-6-levels" vals 61 - ); 62 - 63 - checks.deep-nest-all-merged = checkCond "all values merged" ( 64 - vals == [ 65 - "inputA-5-levels" 66 - "inputA-6-levels" 67 - "inputB-5-levels" 68 - "inputB-6-levels" 69 - "local-5-levels" 70 - "local-6-levels" 71 - ] 72 - ); 73 - 74 - checks.deep-nest-flake-output = checkCond "deep namespace as flake output" ( 75 - inputs.self.denful.deep.a._.b._.c._.d._.e._.f == deep.a._.b._.c._.d._.e._.f 76 - ); 77 - }; 78 - }
···
+13 -1
templates/examples/modules/_example/ci/namespace.nix
··· 17 # enable <angle/bracket> syntax for finding aspects. 18 _module.args.__findFile = den.lib.__findFile; 19 20 imports = [ 21 # create a local namespace and output at flake.denful.eg 22 (inputs.den.namespace "eg" true) ··· 34 inputA 35 inputB 36 exposeToFlake 37 ] 38 ) 39 ]; ··· 71 "inputB simulation" 72 "local namespace" 73 "local simulation" 74 ]; 75 actual = lib.sort (a: b: a < b) rockhopper.config.sims; 76 in 77 - expected == actual 78 ); 79 80 };
··· 17 # enable <angle/bracket> syntax for finding aspects. 18 _module.args.__findFile = den.lib.__findFile; 19 20 + # example "external" flake to import some aspects from. 21 + flake-file.inputs.theirs = { 22 + url = "path:./modules/_example/ci/_theirs"; 23 + inputs.nixpkgs.follows = "nixpkgs"; 24 + inputs.flake-parts.follows = "flake-parts"; 25 + inputs.import-tree.follows = "import-tree"; 26 + inputs.flake-aspects.follows = "flake-aspects"; 27 + inputs.den.follows = "den"; 28 + }; 29 + 30 imports = [ 31 # create a local namespace and output at flake.denful.eg 32 (inputs.den.namespace "eg" true) ··· 44 inputA 45 inputB 46 exposeToFlake 47 + inputs.theirs # from actual external flake 48 ] 49 ) 50 ]; ··· 82 "inputB simulation" 83 "local namespace" 84 "local simulation" 85 + "theirs simulation" 86 ]; 87 actual = lib.sort (a: b: a < b) rockhopper.config.sims; 88 in 89 + expected == (builtins.trace actual actual) 90 ); 91 92 };
-53
templates/examples/modules/_example/ci/shared-parametric-aspects.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - shared, 5 - ... 6 - }: 7 - let 8 - dataModule.nixos.options.data = lib.mkOption { 9 - type = lib.types.listOf lib.types.str; 10 - }; 11 - mkInputFlake = name: { 12 - denful.shared.gaming._.retro._.sega = { 13 - nixos.data = [ "${name}-sega-static" ]; 14 - }; 15 - }; 16 - inputFoo = mkInputFlake "foo"; 17 - inputBar = mkInputFlake "bar"; 18 - in 19 - { 20 - imports = [ 21 - (inputs.den.namespace "shared" [ 22 - true 23 - inputFoo 24 - inputBar 25 - ]) 26 - ]; 27 - 28 - shared.gaming._.retro._.sega.nixos.data = [ "local-sega-static" ]; 29 - 30 - den.aspects.rockhopper.includes = [ 31 - dataModule 32 - shared.gaming._.retro._.sega 33 - ]; 34 - 35 - perSystem = 36 - { checkCond, rockhopper, ... }: 37 - let 38 - vals = lib.sort (a: b: a < b) rockhopper.config.data; 39 - in 40 - { 41 - checks.shared-parametric-all-merged = checkCond "all parametric merged" ( 42 - vals == [ 43 - "bar-sega-static" 44 - "foo-sega-static" 45 - "local-sega-static" 46 - ] 47 - ); 48 - 49 - checks.shared-flake-output-matches = checkCond "flake output matches" ( 50 - shared.gaming._.retro._.sega == inputs.self.denful.shared.gaming._.retro._.sega 51 - ); 52 - }; 53 - }
···
+3 -22
templates/examples/modules/_example/ci/unfree.nix
··· 1 { den, ... }: 2 - 3 - let 4 - codeAspect = { 5 - includes = [ (den._.unfree [ "vscode" ]) ]; 6 - homeManager.programs.vscode.enable = true; 7 - }; 8 - discordAspect = { 9 - includes = [ 10 - (den._.unfree [ "discord" ]) 11 - ]; 12 - homeManager = 13 - { pkgs, ... }: 14 - { 15 - home.packages = [ pkgs.discord ]; 16 - }; 17 - }; 18 - in 19 { 20 - # cam uses unfree vscode and discord loaded from different aspects. 21 - den.aspects.cam.includes = [ 22 - codeAspect 23 - discordAspect 24 - ]; 25 }
··· 1 { den, ... }: 2 { 3 + # cam uses unfree vscode. 4 + den.aspects.cam.homeManager.programs.vscode.enable = true; 5 + den.aspects.cam.includes = [ (den._.unfree [ "vscode" ]) ]; 6 }
-12
templates/examples/provider/flake.nix
··· 1 - { 2 - outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 3 - 4 - inputs = { 5 - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 6 - flake-parts.url = "github:hercules-ci/flake-parts"; 7 - flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 8 - flake-aspects.url = "github:vic/flake-aspects"; 9 - import-tree.url = "github:vic/import-tree"; 10 - den.url = "github:vic/den"; 11 - }; 12 - }
···
-28
templates/examples/provider/modules/den.nix
··· 1 - { inputs, ... }: 2 - { 3 - systems = [ 4 - "x86_64-linux" 5 - "aarch64-darwin" 6 - ]; 7 - 8 - imports = [ 9 - inputs.den.flakeModule 10 - (inputs.den.namespace "provider" true) 11 - ]; 12 - 13 - provider.tools._.dev._.editors = { 14 - description = "Editor configurations from provider flake"; 15 - nixos.environment.variables.PROVIDER_EDITOR = "vim"; 16 - homeManager = 17 - { pkgs, ... }: 18 - { 19 - home.packages = [ pkgs.vim ]; 20 - }; 21 - }; 22 - 23 - provider.tools._.dev._.shells = { 24 - description = "Shell configurations from provider flake"; 25 - nixos.environment.variables.PROVIDER_SHELL = "fish"; 26 - nixos.environment.systemPackages = [ ]; 27 - }; 28 - }
···
+3 -3
templates/minimal/flake.lock
··· 17 }, 18 "flake-aspects": { 19 "locked": { 20 - "lastModified": 1769717274, 21 - "narHash": "sha256-U15OaMr9AcJiB1wW2uCFzFO+DnQ3jJSvln+ZR/+Q0vE=", 22 "owner": "vic", 23 "repo": "flake-aspects", 24 - "rev": "a35ed5efc9a629694d659d606230ba18a76cefaa", 25 "type": "github" 26 }, 27 "original": {
··· 17 }, 18 "flake-aspects": { 19 "locked": { 20 + "lastModified": 1766081176, 21 + "narHash": "sha256-JrsuNSIEXPS3AiIxuWZw+sJ2Td6ni1OkqbW6mO/F4Rs=", 22 "owner": "vic", 23 "repo": "flake-aspects", 24 + "rev": "d0a226c84be2900d307aa1896e4e2c6e451844b2", 25 "type": "github" 26 }, 27 "original": {
-17
templates/noflake/README.md
··· 1 - # Den without flake-parts 2 - 3 - This template provides an example Den setup with stable Nix (no-flakes), no flake-parts and nix-maid instead of home-manager. 4 - 5 - It configures a NixOS host with one user. 6 - 7 - Try it with: 8 - 9 - ```shell 10 - nixos-rebuild build --file . -A nixosConfigurations.igloo 11 - ``` 12 - 13 - or 14 - 15 - ```shell 16 - nix-build -A nixosConfigurations.igloo.config.system.build.toplevel 17 - ```
···
-16
templates/noflake/default.nix
··· 1 - let 2 - 3 - outputs = 4 - inputs: 5 - (inputs.nixpkgs.lib.evalModules { 6 - modules = [ (inputs.import-tree ./modules) ]; 7 - specialArgs = { 8 - inherit inputs; 9 - inherit (inputs) self; 10 - }; 11 - }).config; 12 - 13 - in 14 - # Den outputs configurations at flake top-level attr 15 - # even when it does not depend on flakes or flake-parts. 16 - (import ./with-inputs.nix outputs).flake
···
-11
templates/noflake/modules/compat.nix
··· 1 - { inputs, lib, ... }: 2 - { 3 - # we can import this flakeModule even if we dont have flake-parts as input! 4 - imports = [ inputs.den.flakeModule ]; 5 - 6 - # NOTE: Currently Den needs a top-level attribute where to place configurations, 7 - # by default it is the `flake` attribute, even if Den uses no flake-parts at all. 8 - options.flake = lib.mkOption { 9 - type = lib.types.submodule { freeformType = lib.types.anything; }; 10 - }; 11 - }
···
-38
templates/noflake/modules/den.nix
··· 1 - { inputs, ... }: 2 - { 3 - # tux user on igloo host. 4 - den.hosts.x86_64-linux.igloo.users.tux = { }; 5 - 6 - # host aspect 7 - den.aspects.igloo = { 8 - nixos = 9 - { pkgs, ... }: 10 - { 11 - # remove these for a real bootable host 12 - boot.loader.grub.enable = false; 13 - fileSystems."/".device = "/dev/fake"; 14 - passthru = { }; 15 - 16 - environment.systemPackages = [ 17 - pkgs.vim 18 - ]; 19 - }; 20 - }; 21 - 22 - # user aspect 23 - den.aspects.tux = { 24 - # user configures the host it lives in 25 - nixos = { 26 - # hipster-tux uses nix-maid instead of home-manager. 27 - imports = [ inputs.nix-maid.nixosModules.default ]; 28 - 29 - users.users.tux = { 30 - isNormalUser = true; 31 - maid.file.home.".gitconfig".text = '' 32 - [user] 33 - name=Tux 34 - ''; 35 - }; 36 - }; 37 - }; 38 - }
···
-249
templates/noflake/npins/default.nix
··· 1 - /* 2 - This file is provided under the MIT licence: 3 - 4 - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the โ€œSoftwareโ€), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 - 6 - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 - 8 - THE SOFTWARE IS PROVIDED โ€œAS ISโ€, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 - */ 10 - # Generated by npins. Do not modify; will be overwritten regularly 11 - let 12 - # Backwards-compatibly make something that previously didn't take any arguments take some 13 - # The function must return an attrset, and will unfortunately be eagerly evaluated 14 - # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments 15 - mkFunctor = 16 - fn: 17 - let 18 - e = builtins.tryEval (fn { }); 19 - in 20 - (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; }; 21 - 22 - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 23 - range = 24 - first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); 25 - 26 - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 27 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); 28 - 29 - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 30 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); 31 - concatStrings = builtins.concatStringsSep ""; 32 - 33 - # If the environment variable NPINS_OVERRIDE_${name} is set, then use 34 - # the path directly as opposed to the fetched source. 35 - # (Taken from Niv for compatibility) 36 - mayOverride = 37 - name: path: 38 - let 39 - envVarName = "NPINS_OVERRIDE_${saneName}"; 40 - saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; 41 - ersatz = builtins.getEnv envVarName; 42 - in 43 - if ersatz == "" then 44 - path 45 - else 46 - # this turns the string into an actual Nix path (for both absolute and 47 - # relative paths) 48 - builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( 49 - if builtins.substring 0 1 ersatz == "/" then 50 - /. + ersatz 51 - else 52 - /. + builtins.getEnv "PWD" + "/${ersatz}" 53 - ); 54 - 55 - mkSource = 56 - name: spec: 57 - { 58 - pkgs ? null, 59 - }: 60 - assert spec ? type; 61 - let 62 - # Unify across builtin and pkgs fetchers. 63 - # `fetchGit` requires a wrapper because of slight API differences. 64 - fetchers = 65 - if pkgs == null then 66 - { 67 - inherit (builtins) fetchTarball fetchurl; 68 - # For some fucking reason, fetchGit has a different signature than the other builtin fetchers โ€ฆ 69 - fetchGit = args: (builtins.fetchGit args).outPath; 70 - } 71 - else 72 - { 73 - fetchTarball = 74 - { 75 - url, 76 - sha256, 77 - }: 78 - pkgs.fetchzip { 79 - inherit url sha256; 80 - extension = "tar"; 81 - }; 82 - inherit (pkgs) fetchurl; 83 - fetchGit = 84 - { 85 - url, 86 - submodules, 87 - rev, 88 - name, 89 - narHash, 90 - }: 91 - pkgs.fetchgit { 92 - inherit url rev name; 93 - fetchSubmodules = submodules; 94 - hash = narHash; 95 - }; 96 - }; 97 - 98 - # Dispatch to the correct code path based on the type 99 - path = 100 - if spec.type == "Git" then 101 - mkGitSource fetchers spec 102 - else if spec.type == "GitRelease" then 103 - mkGitSource fetchers spec 104 - else if spec.type == "PyPi" then 105 - mkPyPiSource fetchers spec 106 - else if spec.type == "Channel" then 107 - mkChannelSource fetchers spec 108 - else if spec.type == "Tarball" then 109 - mkTarballSource fetchers spec 110 - else if spec.type == "Container" then 111 - mkContainerSource pkgs spec 112 - else 113 - builtins.throw "Unknown source type ${spec.type}"; 114 - in 115 - spec // { outPath = mayOverride name path; }; 116 - 117 - mkGitSource = 118 - { 119 - fetchTarball, 120 - fetchGit, 121 - ... 122 - }: 123 - { 124 - repository, 125 - revision, 126 - url ? null, 127 - submodules, 128 - hash, 129 - ... 130 - }: 131 - assert repository ? type; 132 - # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository 133 - # In the latter case, there we will always be an url to the tarball 134 - if url != null && !submodules then 135 - fetchTarball { 136 - inherit url; 137 - sha256 = hash; 138 - } 139 - else 140 - let 141 - url = 142 - if repository.type == "Git" then 143 - repository.url 144 - else if repository.type == "GitHub" then 145 - "https://github.com/${repository.owner}/${repository.repo}.git" 146 - else if repository.type == "GitLab" then 147 - "${repository.server}/${repository.repo_path}.git" 148 - else if repository.type == "Forgejo" then 149 - "${repository.server}/${repository.owner}/${repository.repo}.git" 150 - else 151 - throw "Unrecognized repository type ${repository.type}"; 152 - urlToName = 153 - url: rev: 154 - let 155 - matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; 156 - 157 - short = builtins.substring 0 7 rev; 158 - 159 - appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; 160 - in 161 - "${if matched == null then "source" else builtins.head matched}${appendShort}"; 162 - name = urlToName url revision; 163 - in 164 - fetchGit { 165 - rev = revision; 166 - narHash = hash; 167 - 168 - inherit name submodules url; 169 - }; 170 - 171 - mkPyPiSource = 172 - { fetchurl, ... }: 173 - { 174 - url, 175 - hash, 176 - ... 177 - }: 178 - fetchurl { 179 - inherit url; 180 - sha256 = hash; 181 - }; 182 - 183 - mkChannelSource = 184 - { fetchTarball, ... }: 185 - { 186 - url, 187 - hash, 188 - ... 189 - }: 190 - fetchTarball { 191 - inherit url; 192 - sha256 = hash; 193 - }; 194 - 195 - mkTarballSource = 196 - { fetchTarball, ... }: 197 - { 198 - url, 199 - locked_url ? url, 200 - hash, 201 - ... 202 - }: 203 - fetchTarball { 204 - url = locked_url; 205 - sha256 = hash; 206 - }; 207 - 208 - mkContainerSource = 209 - pkgs: 210 - { 211 - image_name, 212 - image_tag, 213 - image_digest, 214 - ... 215 - }: 216 - if pkgs == null then 217 - builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" 218 - else 219 - pkgs.dockerTools.pullImage { 220 - imageName = image_name; 221 - imageDigest = image_digest; 222 - finalImageTag = image_tag; 223 - }; 224 - in 225 - mkFunctor ( 226 - { 227 - input ? ./sources.json, 228 - }: 229 - let 230 - data = 231 - if builtins.isPath input then 232 - # while `readFile` will throw an error anyways if the path doesn't exist, 233 - # we still need to check beforehand because *our* error can be caught but not the one from the builtin 234 - # *piegames sighs* 235 - if builtins.pathExists input then 236 - builtins.fromJSON (builtins.readFile input) 237 - else 238 - throw "Input path ${toString input} does not exist" 239 - else if builtins.isAttrs input then 240 - input 241 - else 242 - throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; 243 - version = data.version; 244 - in 245 - if version == 7 then 246 - builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins 247 - else 248 - throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" 249 - )
···
-63
templates/noflake/npins/sources.json
··· 1 - { 2 - "pins": { 3 - "den": { 4 - "type": "Git", 5 - "repository": { 6 - "type": "GitHub", 7 - "owner": "vic", 8 - "repo": "den" 9 - }, 10 - "branch": "main", 11 - "submodules": false, 12 - "revision": "2dab67aab2214b84f5ac15adc4e900e90d07f17b", 13 - "url": "https://github.com/vic/den/archive/2dab67aab2214b84f5ac15adc4e900e90d07f17b.tar.gz", 14 - "hash": "sha256-LKTq2QTXzA5lR0xhrG/hkWtjvKnr91mvIabBof0/M4A=" 15 - }, 16 - "flake-aspects": { 17 - "type": "Git", 18 - "repository": { 19 - "type": "GitHub", 20 - "owner": "vic", 21 - "repo": "flake-aspects" 22 - }, 23 - "branch": "main", 24 - "submodules": false, 25 - "revision": "61524836788ef6991a82e7d34ebb0ccc05d374ed", 26 - "url": "https://github.com/vic/flake-aspects/archive/61524836788ef6991a82e7d34ebb0ccc05d374ed.tar.gz", 27 - "hash": "sha256-U15OaMr9AcJiB1wW2uCFzFO+DnQ3jJSvln+ZR/+Q0vE=" 28 - }, 29 - "import-tree": { 30 - "type": "Git", 31 - "repository": { 32 - "type": "GitHub", 33 - "owner": "vic", 34 - "repo": "import-tree" 35 - }, 36 - "branch": "main", 37 - "submodules": false, 38 - "revision": "3c23749d8013ec6daa1d7255057590e9ca726646", 39 - "url": "https://github.com/vic/import-tree/archive/3c23749d8013ec6daa1d7255057590e9ca726646.tar.gz", 40 - "hash": "sha256-ZvYKbFib3AEwiNMLsejb/CWs/OL/srFQ8AogkebEPF0=" 41 - }, 42 - "nix-maid": { 43 - "type": "Git", 44 - "repository": { 45 - "type": "GitHub", 46 - "owner": "viperml", 47 - "repo": "nix-maid" 48 - }, 49 - "branch": "master", 50 - "submodules": false, 51 - "revision": "303e67a8c67d1ba1416abd8842d206a57b46f832", 52 - "url": "https://github.com/viperml/nix-maid/archive/303e67a8c67d1ba1416abd8842d206a57b46f832.tar.gz", 53 - "hash": "sha256-nvybtwQnyGeUbAq/iOMnt0rOGrp8nkyjnZTW9XIsrfI=" 54 - }, 55 - "nixpkgs": { 56 - "type": "Channel", 57 - "name": "nixpkgs-unstable", 58 - "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre937085.6308c3b21396/nixexprs.tar.xz", 59 - "hash": "sha256-RuGWBqXVEsZwwBvRGS/nRrA6PQyOQwVaAu139Z853Bk=" 60 - } 61 - }, 62 - "version": 7 63 - }
···
-42
templates/noflake/with-inputs.nix
··· 1 - # adapted from https://github.com/vic/dendritic-unflake 2 - let 3 - sources = (import ./npins) // { 4 - # uncomment for using local den checkout 5 - # den.outPath = ./../..; 6 - }; 7 - selfInputs = builtins.mapAttrs (name: value: mkInputs name value) sources; 8 - mkInputs = 9 - name: sourceInfo: 10 - let 11 - flakePath = sourceInfo.outPath + "/flake.nix"; 12 - isFlake = sources.${name}.flake or true; 13 - in 14 - if isFlake && builtins.pathExists flakePath then 15 - let 16 - flake = import (sourceInfo.outPath + "/flake.nix"); 17 - inputs = builtins.mapAttrs (name: _value: selfInputs.${name}) (flake.inputs or { }); 18 - outputs = flake.outputs (inputs // { inherit self; }); 19 - self = 20 - sourceInfo 21 - // outputs 22 - // { 23 - _type = "flake"; 24 - inherit inputs sourceInfo; 25 - }; 26 - in 27 - self 28 - else 29 - sourceInfo 30 - // { 31 - inherit sourceInfo; 32 - }; 33 - in 34 - selfInputs 35 - // { 36 - __functor = 37 - selfInputs: outputs: 38 - let 39 - self = outputs (selfInputs // { inherit self; }); 40 - in 41 - self; 42 - }
···