···11<p align="right">
22 <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"/>
33 </a>
44+ <a href="https://deepwiki.com/vic/den"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
45 <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>
56 <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>
67 <a href="LICENSE"> <img src="https://img.shields.io/github/license/vic/den" alt="License"/> </a>
···19202021<img width="300" height="300" alt="den" src="https://github.com/user-attachments/assets/af9c9bca-ab8b-4682-8678-31a70d510bbb" />
21222222-- Dendritic: each module configures **same** concern over **different** Nix classes.
2323+- [Dendritic](https://github.com/mightyiam/dendritic): **same** concern across **different** Nix classes.
23242425- Create [DRY](modules/aspects/provides/unfree.nix) & [`class`-generic](modules/aspects/provides/primary-user.nix) modules.
25262627- [Parametric](modules/aspects/provides/define-user.nix) over `host`/`home`/`user`.
27282828-- [Share](templates/default/modules/namespace.nix) aspects across systems & repos.
2929+- Context-aware [dependencies](modules/aspects/dependencies.nix): user/host contributions.
3030+3131+- [templates/noflake](templates/noflake). Works with stable Nix (no-flakes) and needs no flake-parts.
29323030-- Context-aware [dependencies](modules/aspects/dependencies.nix): user/host contributions.
3333+- [Share](templates/default/modules/namespace.nix) aspects across systems & repos.
31343235- [Routable](templates/default/modules/aspects/eg/routes.nix) configurations.
3336···35383639- Use `stable`/`unstable` channels per config.
37403838-- Freeform `host`/`user`/`home` [schemas](modules/_types.nix) (no `specialArgs`).
4141+- Freeform `host`/`user`/`home` [schemas](modules/_types.nix) (no `specialArgs`) with base modules.
39424043- Multi-platform, multi-tenant hosts.
4144
+17
templates/noflake/README.md
···11+# Den without flake-parts
22+33+This template provides an example Den setup with stable Nix (no-flakes), no flake-parts and nix-maid instead of home-manager.
44+55+It configures a NixOS host with one user.
66+77+Try it with:
88+99+```shell
1010+nixos-rebuild build --file . -A nixosConfigurations.igloo
1111+```
1212+1313+or
1414+1515+```shell
1616+nix-build -A nixosConfigurations.igloo.config.system.build.toplevel
1717+```
+16
templates/noflake/default.nix
···11+let
22+33+ outputs =
44+ inputs:
55+ (inputs.nixpkgs.lib.evalModules {
66+ modules = [ (inputs.import-tree ./modules) ];
77+ specialArgs = {
88+ inherit inputs;
99+ inherit (inputs) self;
1010+ };
1111+ }).config;
1212+1313+in
1414+# Den outputs configurations at flake top-level attr
1515+# even when it does not depend on flakes or flake-parts.
1616+(import ./with-inputs.nix outputs).flake
+11
templates/noflake/modules/compat.nix
···11+{ inputs, lib, ... }:
22+{
33+ # we can import this flakeModule even if we dont have flake-parts as input!
44+ imports = [ inputs.den.flakeModule ];
55+66+ # NOTE: Currently Den needs a top-level attribute where to place configurations,
77+ # by default it is the `flake` attribute, even if Den uses no flake-parts at all.
88+ options.flake = lib.mkOption {
99+ type = lib.types.submodule { freeformType = lib.types.anything; };
1010+ };
1111+}
···11+/*
22+ This file is provided under the MIT licence:
33+44+ 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:
55+66+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77+88+ 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.
99+*/
1010+# Generated by npins. Do not modify; will be overwritten regularly
1111+let
1212+ # Backwards-compatibly make something that previously didn't take any arguments take some
1313+ # The function must return an attrset, and will unfortunately be eagerly evaluated
1414+ # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
1515+ mkFunctor =
1616+ fn:
1717+ let
1818+ e = builtins.tryEval (fn { });
1919+ in
2020+ (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
2121+2222+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
2323+ range =
2424+ first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
2525+2626+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
2727+ stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
2828+2929+ # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
3030+ stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
3131+ concatStrings = builtins.concatStringsSep "";
3232+3333+ # If the environment variable NPINS_OVERRIDE_${name} is set, then use
3434+ # the path directly as opposed to the fetched source.
3535+ # (Taken from Niv for compatibility)
3636+ mayOverride =
3737+ name: path:
3838+ let
3939+ envVarName = "NPINS_OVERRIDE_${saneName}";
4040+ saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
4141+ ersatz = builtins.getEnv envVarName;
4242+ in
4343+ if ersatz == "" then
4444+ path
4545+ else
4646+ # this turns the string into an actual Nix path (for both absolute and
4747+ # relative paths)
4848+ builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
4949+ if builtins.substring 0 1 ersatz == "/" then
5050+ /. + ersatz
5151+ else
5252+ /. + builtins.getEnv "PWD" + "/${ersatz}"
5353+ );
5454+5555+ mkSource =
5656+ name: spec:
5757+ {
5858+ pkgs ? null,
5959+ }:
6060+ assert spec ? type;
6161+ let
6262+ # Unify across builtin and pkgs fetchers.
6363+ # `fetchGit` requires a wrapper because of slight API differences.
6464+ fetchers =
6565+ if pkgs == null then
6666+ {
6767+ inherit (builtins) fetchTarball fetchurl;
6868+ # For some fucking reason, fetchGit has a different signature than the other builtin fetchers โฆ
6969+ fetchGit = args: (builtins.fetchGit args).outPath;
7070+ }
7171+ else
7272+ {
7373+ fetchTarball =
7474+ {
7575+ url,
7676+ sha256,
7777+ }:
7878+ pkgs.fetchzip {
7979+ inherit url sha256;
8080+ extension = "tar";
8181+ };
8282+ inherit (pkgs) fetchurl;
8383+ fetchGit =
8484+ {
8585+ url,
8686+ submodules,
8787+ rev,
8888+ name,
8989+ narHash,
9090+ }:
9191+ pkgs.fetchgit {
9292+ inherit url rev name;
9393+ fetchSubmodules = submodules;
9494+ hash = narHash;
9595+ };
9696+ };
9797+9898+ # Dispatch to the correct code path based on the type
9999+ path =
100100+ if spec.type == "Git" then
101101+ mkGitSource fetchers spec
102102+ else if spec.type == "GitRelease" then
103103+ mkGitSource fetchers spec
104104+ else if spec.type == "PyPi" then
105105+ mkPyPiSource fetchers spec
106106+ else if spec.type == "Channel" then
107107+ mkChannelSource fetchers spec
108108+ else if spec.type == "Tarball" then
109109+ mkTarballSource fetchers spec
110110+ else if spec.type == "Container" then
111111+ mkContainerSource pkgs spec
112112+ else
113113+ builtins.throw "Unknown source type ${spec.type}";
114114+ in
115115+ spec // { outPath = mayOverride name path; };
116116+117117+ mkGitSource =
118118+ {
119119+ fetchTarball,
120120+ fetchGit,
121121+ ...
122122+ }:
123123+ {
124124+ repository,
125125+ revision,
126126+ url ? null,
127127+ submodules,
128128+ hash,
129129+ ...
130130+ }:
131131+ assert repository ? type;
132132+ # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
133133+ # In the latter case, there we will always be an url to the tarball
134134+ if url != null && !submodules then
135135+ fetchTarball {
136136+ inherit url;
137137+ sha256 = hash;
138138+ }
139139+ else
140140+ let
141141+ url =
142142+ if repository.type == "Git" then
143143+ repository.url
144144+ else if repository.type == "GitHub" then
145145+ "https://github.com/${repository.owner}/${repository.repo}.git"
146146+ else if repository.type == "GitLab" then
147147+ "${repository.server}/${repository.repo_path}.git"
148148+ else if repository.type == "Forgejo" then
149149+ "${repository.server}/${repository.owner}/${repository.repo}.git"
150150+ else
151151+ throw "Unrecognized repository type ${repository.type}";
152152+ urlToName =
153153+ url: rev:
154154+ let
155155+ matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
156156+157157+ short = builtins.substring 0 7 rev;
158158+159159+ appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
160160+ in
161161+ "${if matched == null then "source" else builtins.head matched}${appendShort}";
162162+ name = urlToName url revision;
163163+ in
164164+ fetchGit {
165165+ rev = revision;
166166+ narHash = hash;
167167+168168+ inherit name submodules url;
169169+ };
170170+171171+ mkPyPiSource =
172172+ { fetchurl, ... }:
173173+ {
174174+ url,
175175+ hash,
176176+ ...
177177+ }:
178178+ fetchurl {
179179+ inherit url;
180180+ sha256 = hash;
181181+ };
182182+183183+ mkChannelSource =
184184+ { fetchTarball, ... }:
185185+ {
186186+ url,
187187+ hash,
188188+ ...
189189+ }:
190190+ fetchTarball {
191191+ inherit url;
192192+ sha256 = hash;
193193+ };
194194+195195+ mkTarballSource =
196196+ { fetchTarball, ... }:
197197+ {
198198+ url,
199199+ locked_url ? url,
200200+ hash,
201201+ ...
202202+ }:
203203+ fetchTarball {
204204+ url = locked_url;
205205+ sha256 = hash;
206206+ };
207207+208208+ mkContainerSource =
209209+ pkgs:
210210+ {
211211+ image_name,
212212+ image_tag,
213213+ image_digest,
214214+ ...
215215+ }:
216216+ if pkgs == null then
217217+ builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
218218+ else
219219+ pkgs.dockerTools.pullImage {
220220+ imageName = image_name;
221221+ imageDigest = image_digest;
222222+ finalImageTag = image_tag;
223223+ };
224224+in
225225+mkFunctor (
226226+ {
227227+ input ? ./sources.json,
228228+ }:
229229+ let
230230+ data =
231231+ if builtins.isPath input then
232232+ # while `readFile` will throw an error anyways if the path doesn't exist,
233233+ # we still need to check beforehand because *our* error can be caught but not the one from the builtin
234234+ # *piegames sighs*
235235+ if builtins.pathExists input then
236236+ builtins.fromJSON (builtins.readFile input)
237237+ else
238238+ throw "Input path ${toString input} does not exist"
239239+ else if builtins.isAttrs input then
240240+ input
241241+ else
242242+ throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
243243+ version = data.version;
244244+ in
245245+ if version == 7 then
246246+ builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
247247+ else
248248+ throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
249249+)