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.

feat(template): forward classes for 3rd-party flake-parts modules (#351)

authored by

Victor Borja and committed by
GitHub
75660e94 66677bf5

+472 -2
+1 -1
.github/workflows/test.yml
··· 84 84 # max-parallel: 2 85 85 strategy: 86 86 matrix: 87 - template: [bogus, minimal, microvm, nvf-standalone] 87 + template: [bogus, minimal, microvm, nvf-standalone, flake-parts-modules] 88 88 os: [ubuntu-latest] 89 89 name: Check template ${{matrix.template}} ${{matrix.os}} 90 90 runs-on: ${{matrix.os}}
+2
nix/default.nix
··· 19 19 microvm.description = "MicroVM example"; 20 20 nvf-standalone.path = ../templates/nvf-standalone; 21 21 nvf-standalone.description = "Standalone NVF"; 22 + flake-parts-modules.path = ../templates/flake-parts-modules; 23 + flake-parts-modules.description = "flake-parts classes"; 22 24 ci.path = ../templates/ci; 23 25 ci.description = "Feature Tests"; 24 26 bogus.path = ../templates/bogus;
+1 -1
nix/lib/forward.nix
··· 33 33 }; 34 34 35 35 freeformMod = { 36 - config._module.freeformType = lib.types.lazyAttrsOf lib.types.anything; 36 + config._module.freeformType = lib.types.lazyAttrsOf lib.types.unspecified; 37 37 }; 38 38 39 39 adapterMods = [
+7
templates/flake-parts-modules/README.md
··· 1 + # Example Den custom classes for flake-parts modules and perSystem outputs. 2 + 3 + This example showcases Den forward classes for third-party flake-parts modules. 4 + 5 + This README is generated by `nix run .#write-files`. 6 + 7 + See den.nix, custom-classes.nix and perSystem-forward.nix
+206
templates/flake-parts-modules/flake.lock
··· 1 + { 2 + "nodes": { 3 + "den": { 4 + "locked": { 5 + "lastModified": 1774981725, 6 + "narHash": "sha256-eaNpxQLoNpALVyiolZQEIoi6eH529jcXeQ7LfuwtHIY=", 7 + "owner": "vic", 8 + "repo": "den", 9 + "rev": "66677bf5f235c5f5fe742e3839f6c184d66065df", 10 + "type": "github" 11 + }, 12 + "original": { 13 + "owner": "vic", 14 + "repo": "den", 15 + "type": "github" 16 + } 17 + }, 18 + "devshell": { 19 + "inputs": { 20 + "nixpkgs": [ 21 + "nixpkgs" 22 + ] 23 + }, 24 + "locked": { 25 + "lastModified": 1768818222, 26 + "narHash": "sha256-460jc0+CZfyaO8+w8JNtlClB2n4ui1RbHfPTLkpwhU8=", 27 + "owner": "numtide", 28 + "repo": "devshell", 29 + "rev": "255a2b1725a20d060f566e4755dbf571bbbb5f76", 30 + "type": "github" 31 + }, 32 + "original": { 33 + "owner": "numtide", 34 + "repo": "devshell", 35 + "type": "github" 36 + } 37 + }, 38 + "files": { 39 + "locked": { 40 + "lastModified": 1762767848, 41 + "narHash": "sha256-trF2WXzH57uSkA1zeI8FTz8tU6vPYrklkTjh/7DZy/M=", 42 + "owner": "mightyiam", 43 + "repo": "files", 44 + "rev": "2d9d4937e94006ad8f165dfab9dff87cfab7eb2b", 45 + "type": "github" 46 + }, 47 + "original": { 48 + "owner": "mightyiam", 49 + "repo": "files", 50 + "type": "github" 51 + } 52 + }, 53 + "flake-parts": { 54 + "inputs": { 55 + "nixpkgs-lib": [ 56 + "nixpkgs" 57 + ] 58 + }, 59 + "locked": { 60 + "lastModified": 1772408722, 61 + "narHash": "sha256-rHuJtdcOjK7rAHpHphUb1iCvgkU3GpfvicLMwwnfMT0=", 62 + "owner": "hercules-ci", 63 + "repo": "flake-parts", 64 + "rev": "f20dc5d9b8027381c474144ecabc9034d6a839a3", 65 + "type": "github" 66 + }, 67 + "original": { 68 + "owner": "hercules-ci", 69 + "repo": "flake-parts", 70 + "type": "github" 71 + } 72 + }, 73 + "import-tree": { 74 + "locked": { 75 + "lastModified": 1773693634, 76 + "narHash": "sha256-BtZ2dtkBdSUnFPPFc+n0kcMbgaTxzFNPv2iaO326Ffg=", 77 + "owner": "vic", 78 + "repo": "import-tree", 79 + "rev": "c41e7d58045f9057880b0d85e1152d6a4430dbf1", 80 + "type": "github" 81 + }, 82 + "original": { 83 + "owner": "vic", 84 + "repo": "import-tree", 85 + "type": "github" 86 + } 87 + }, 88 + "nix-topology": { 89 + "inputs": { 90 + "flake-parts": [ 91 + "flake-parts" 92 + ], 93 + "nixpkgs": [ 94 + "nixpkgs" 95 + ] 96 + }, 97 + "locked": { 98 + "lastModified": 1774824790, 99 + "narHash": "sha256-3R2aoykbutdJ7YQaZiU7uO8w4O8b6RjztTPNo8isLTI=", 100 + "owner": "oddlama", 101 + "repo": "nix-topology", 102 + "rev": "5765ce41be8a4fb5471a57671c2b740a350c5da0", 103 + "type": "github" 104 + }, 105 + "original": { 106 + "owner": "oddlama", 107 + "repo": "nix-topology", 108 + "type": "github" 109 + } 110 + }, 111 + "nix-unit": { 112 + "inputs": { 113 + "flake-parts": [ 114 + "flake-parts" 115 + ], 116 + "nix-github-actions": [], 117 + "nixpkgs": [ 118 + "nixpkgs" 119 + ], 120 + "treefmt-nix": [ 121 + "treefmt-nix" 122 + ] 123 + }, 124 + "locked": { 125 + "lastModified": 1762774186, 126 + "narHash": "sha256-hRADkHjNt41+JUHw2EiSkMaL4owL83g5ZppjYUdF/Dc=", 127 + "owner": "nix-community", 128 + "repo": "nix-unit", 129 + "rev": "1c9ab50554eed0b768f9e5b6f646d63c9673f0f7", 130 + "type": "github" 131 + }, 132 + "original": { 133 + "owner": "nix-community", 134 + "repo": "nix-unit", 135 + "type": "github" 136 + } 137 + }, 138 + "nixpkgs": { 139 + "locked": { 140 + "lastModified": 1774855581, 141 + "narHash": "sha256-YkreHeMgTCYvJ5fESV0YyqQK49bHGe2B51tH6claUh4=", 142 + "owner": "nixos", 143 + "repo": "nixpkgs", 144 + "rev": "15c6719d8c604779cf59e03c245ea61d3d7ab69b", 145 + "type": "github" 146 + }, 147 + "original": { 148 + "owner": "nixos", 149 + "ref": "nixpkgs-unstable", 150 + "repo": "nixpkgs", 151 + "type": "github" 152 + } 153 + }, 154 + "pkgs-by-name-for-flake-parts": { 155 + "locked": { 156 + "lastModified": 1769286518, 157 + "narHash": "sha256-F7VlUICvYp2wJKyQqM6d46BNEZCzMQ6dMH9zbmjuybc=", 158 + "owner": "drupol", 159 + "repo": "pkgs-by-name-for-flake-parts", 160 + "rev": "7ba1cd4a9a72c9c6c272018a63f090f2c912a171", 161 + "type": "github" 162 + }, 163 + "original": { 164 + "owner": "drupol", 165 + "repo": "pkgs-by-name-for-flake-parts", 166 + "type": "github" 167 + } 168 + }, 169 + "root": { 170 + "inputs": { 171 + "den": "den", 172 + "devshell": "devshell", 173 + "files": "files", 174 + "flake-parts": "flake-parts", 175 + "import-tree": "import-tree", 176 + "nix-topology": "nix-topology", 177 + "nix-unit": "nix-unit", 178 + "nixpkgs": "nixpkgs", 179 + "pkgs-by-name-for-flake-parts": "pkgs-by-name-for-flake-parts", 180 + "treefmt-nix": "treefmt-nix" 181 + } 182 + }, 183 + "treefmt-nix": { 184 + "inputs": { 185 + "nixpkgs": [ 186 + "nixpkgs" 187 + ] 188 + }, 189 + "locked": { 190 + "lastModified": 1773297127, 191 + "narHash": "sha256-6E/yhXP7Oy/NbXtf1ktzmU8SdVqJQ09HC/48ebEGBpk=", 192 + "owner": "numtide", 193 + "repo": "treefmt-nix", 194 + "rev": "71b125cd05fbfd78cab3e070b73544abe24c5016", 195 + "type": "github" 196 + }, 197 + "original": { 198 + "owner": "numtide", 199 + "repo": "treefmt-nix", 200 + "type": "github" 201 + } 202 + } 203 + }, 204 + "root": "root", 205 + "version": 7 206 + }
+38
templates/flake-parts-modules/flake.nix
··· 1 + { 2 + description = "Using flake-parts modules from Den"; 3 + 4 + outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); 5 + 6 + inputs = { 7 + den.url = "github:vic/den"; 8 + import-tree.url = "github:vic/import-tree"; 9 + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 10 + flake-parts.url = "github:hercules-ci/flake-parts"; 11 + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 12 + 13 + pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts"; 14 + 15 + files.url = "github:mightyiam/files"; 16 + 17 + devshell.url = "github:numtide/devshell"; 18 + devshell.inputs.nixpkgs.follows = "nixpkgs"; 19 + 20 + treefmt-nix.url = "github:numtide/treefmt-nix"; 21 + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; 22 + 23 + nix-unit.url = "github:nix-community/nix-unit"; 24 + nix-unit.inputs = { 25 + nixpkgs.follows = "nixpkgs"; 26 + flake-parts.follows = "flake-parts"; 27 + nix-github-actions.follows = ""; 28 + treefmt-nix.follows = "treefmt-nix"; 29 + }; 30 + 31 + nix-topology.url = "github:oddlama/nix-topology"; 32 + nix-topology.inputs = { 33 + nixpkgs.follows = "nixpkgs"; 34 + flake-parts.follows = "flake-parts"; 35 + }; 36 + 37 + }; 38 + }
+94
templates/flake-parts-modules/modules/custom-classes.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + config, 6 + ... 7 + }: 8 + { 9 + systems = builtins.attrNames den.hosts; 10 + 11 + # Some third-party flake-parts modules for demo purposes. 12 + # Read their documentation at https://flake.parts for usage. 13 + imports = [ 14 + inputs.devshell.flakeModule 15 + inputs.files.flakeModules.default 16 + inputs.nix-topology.flakeModule 17 + inputs.nix-unit.modules.flake.default 18 + inputs.pkgs-by-name-for-flake-parts.flakeModule 19 + inputs.treefmt-nix.flakeModule 20 + ]; 21 + 22 + # some globals 23 + perSystem = { 24 + pkgsDirectory = ../packages; 25 + nix-unit = { 26 + allowNetwork = true; 27 + inputs = inputs; 28 + }; 29 + }; 30 + 31 + # den.ctx.flake-parts transformations define which 32 + # custom classes exist and where to read them. 33 + den.ctx.flake-parts.into = _: { 34 + 35 + # Read flake-parts classes from hosts and their includes 36 + host = map (host: { inherit host; }) ( 37 + builtins.concatMap builtins.attrValues (builtins.attrValues den.hosts) 38 + ); 39 + 40 + # Our custom flake-parts perSystem classes. 41 + # These are partial params for `den._.forward`. 42 + # See ./perSystem-forward.nix 43 + flake-parts-system = [ 44 + 45 + # A class for flake-parts' perSystem.packages 46 + # NOTE: this is different from Den's flake-packages class. 47 + { 48 + fromClass = _: "packages"; 49 + intoPath = _: [ "packages" ]; 50 + } 51 + 52 + { 53 + fromClass = _: "files"; 54 + intoPath = _: [ 55 + "files" 56 + ]; 57 + adapterModule = { }; 58 + } 59 + 60 + # a default `devshell` class 61 + { 62 + fromClass = _: "devshell"; 63 + intoPath = _: [ 64 + "devshells" 65 + "default" 66 + ]; 67 + } 68 + 69 + { 70 + fromClass = _: "treefmt"; 71 + intoPath = _: [ "treefmt" ]; 72 + } 73 + 74 + { 75 + fromClass = _: "tests"; 76 + intoPath = _: [ 77 + "nix-unit" 78 + "tests" 79 + ]; 80 + # test helpers 81 + adaptArgs = 82 + { pkgs, ... }: 83 + let 84 + igloo = config.flake.nixosConfigurations.igloo.config; 85 + tux = igloo.users.users.tux; 86 + in 87 + { 88 + inherit pkgs igloo tux; 89 + }; 90 + } 91 + ]; 92 + }; 93 + 94 + }
+98
templates/flake-parts-modules/modules/den.nix
··· 1 + { 2 + den, 3 + lib, 4 + inputs, 5 + config, 6 + ... 7 + }: 8 + { 9 + imports = [ inputs.den.flakeModule ]; 10 + 11 + den.hosts.x86_64-linux.igloo.users.tux = { }; 12 + 13 + den.aspects.igloo = { 14 + # User TODO: Remove for real host 15 + nixos.fileSystems."/".device = "/dev/no-boot"; 16 + nixos.boot.loader.grub.enable = false; 17 + }; 18 + 19 + den.aspects.tux = { 20 + includes = [ den._.define-user ]; 21 + user.description = "Bird"; 22 + 23 + tests = 24 + { tux, ... }: 25 + { 26 + test-tux-is-bird = { 27 + expr = tux.description; 28 + expected = "Bird"; 29 + }; 30 + }; 31 + }; 32 + 33 + # Read flake-parts classes from foo aspect and its includes 34 + den.ctx.flake-parts.includes = [ den.aspects.foo ]; 35 + 36 + den.aspects.foo = { 37 + includes = [ den.aspects.bar ]; 38 + 39 + treefmt.settings.on-unmatched = "warn"; 40 + 41 + devshell.commands = [ { package = "cowsay"; } ]; 42 + 43 + packages = 44 + { pkgs, ... }: 45 + { 46 + topology = config.flake.topology.${pkgs.stdenv.targetPlatform.system}.config.output; 47 + }; 48 + }; 49 + 50 + den.aspects.bar = { 51 + treefmt.programs.nixfmt.enable = true; 52 + 53 + tests.test-math-works = { 54 + expr = 22 * 2; 55 + expected = 44; 56 + }; 57 + 58 + packages = 59 + { config, ... }: 60 + { 61 + write-files = config.files.writer.drv; 62 + }; 63 + 64 + files = 65 + { pkgs, ... }: 66 + { 67 + files = [ 68 + { 69 + path_ = "README.md"; 70 + drv = pkgs.writeText "README.md" '' 71 + # Example Den custom classes for flake-parts modules and perSystem outputs. 72 + 73 + This example showcases Den forward classes for third-party flake-parts modules. 74 + 75 + This README is generated by `nix run .#write-files`. 76 + 77 + See den.nix, custom-classes.nix and perSystem-forward.nix 78 + ''; 79 + } 80 + ]; 81 + }; 82 + 83 + devshell = 84 + { pkgs, self', ... }: 85 + { 86 + commands = [ 87 + { 88 + package = self'.packages.write-files; 89 + } 90 + ]; 91 + packages = [ 92 + pkgs.hello 93 + ]; 94 + }; 95 + 96 + }; 97 + 98 + }
+24
templates/flake-parts-modules/modules/perSystem-forward.nix
··· 1 + { den, lib, ... }: 2 + let 3 + 4 + perSystemFwd = 5 + forwardArgs: 6 + { class, aspect-chain }: 7 + den._.forward ( 8 + { 9 + each = lib.optional (class == "flake-parts") forwardArgs; 10 + intoClass = _: "flake-parts"; 11 + fromAspect = _: lib.head aspect-chain; 12 + adaptArgs = { config, ... }: config.allModuleArgs; 13 + } 14 + // forwardArgs 15 + ); 16 + 17 + ctx.flake-parts = { }; 18 + ctx.flake-parts-system.provides.flake-parts-system = perSystemFwd; 19 + perSystemModule = den.lib.aspects.resolve "flake-parts" (den.ctx.flake-parts { }); 20 + in 21 + { 22 + den.ctx = ctx; 23 + perSystem.imports = [ perSystemModule ]; 24 + }
+1
templates/flake-parts-modules/packages/hola.nix
··· 1 + { hello }: hello