Example Dendritic Nix setup implemented without flakes nor flake-parts. dendrix.oeiuwq.com/Dendritic.html#no-dependencies
nix unflake dendritic

Compare changes

Choose any two refs to compare.

+4 -12
README.md
··· 9 9 10 10 This repo contains several non-flakes examples (one per branch): 11 11 12 - - [unflake](https://github.com/vic/dendritic-unflake/tree/main) **current** 12 + - [unflake](https://github.com/vic/dendritic-unflake/tree/main) 13 13 - [npins](https://github.com/vic/dendritic-unflake/tree/npins) 14 14 - [builtins](https://github.com/vic/dendritic-unflake/tree/builtins) 15 15 - [froyo](https://github.com/vic/dendritic-unflake/tree/froyo) 16 - - [falake](https://github.com/vic/dendritic-unflake/tree/falake) 16 + - [falake](https://github.com/vic/dendritic-unflake/tree/falake) **current** 17 17 - [flake-parts](https://github.com/vic/dendritic-unflake/tree/flake-parts) 18 18 19 - 20 - # Dendritic unflake 19 + # Dendritic Falake 21 20 22 21 This repository serves as an example Dendritic Nix implementation **without** flakes nor flake-parts. 23 22 ([discourse post](https://discourse.nixos.org/t/dendritic-unflake-example-dendritic-setup-without-flakes-nor-flake-parts/73069/5) and [context](https://github.com/mightyiam/dendritic/pull/15)) 24 - 25 23 26 24 Entry point is [default.nix](default.nix), [modules/example.nix](modules/example.nix) defines a nixosConfiguration. 27 25 28 26 29 - This example uses [unflake](https://discourse.nixos.org/t/unflake-flake-dependencies-for-non-flake-projects-and-a-way-to-stop-writing-follows/72611) to fetch dependencies and provide flake-like inputs. 27 + This example uses [falake](https://codeberg.org/FrdrCkII/falake) top-level modules. 30 28 31 29 32 30 ## Usage 33 - 34 - Regenerate [unflake.nix](unflake.nix) whenever [inputs.nix](inputs.nix) change: 35 - 36 - ```console 37 - nix-shell https://ln-s.sh/unflake -A unflake-shell --run unflake 38 - ``` 39 31 40 32 Build `my-laptop` nixos config: 41 33
+9 -18
default.nix
··· 1 1 let 2 - 3 - modules = 4 - { inputs, ... }: 5 - { 6 - imports = [ (inputs.import-tree ./modules) ]; 7 - }; 8 - 9 - outputs = 10 - inputs: 11 - (inputs.nixpkgs.lib.evalModules { 12 - modules = [ modules ]; 13 - specialArgs = { 14 - inherit inputs; 15 - inherit (inputs) self; 16 - }; 17 - }).config; 18 - 2 + pins = import ./npins; 3 + inherit (pins) nixpkgs falake; 4 + pkgs = import nixpkgs { }; 19 5 in 20 - import ./unflake.nix outputs 6 + (import falake).mkFalake pkgs.lib { inherit pins; } { 7 + inherit nixpkgs; 8 + imports = [ 9 + (import pins.import-tree ./modules) 10 + ]; 11 + }
-5
inputs.nix
··· 1 - let 2 - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; 3 - inputs.import-tree.url = "github:vic/import-tree"; 4 - in 5 - inputs
+6 -6
modules/example.nix
··· 1 - { lib, self, ... }: 1 + { pins, config, ... }: 2 2 { 3 - modules.nixos.no-boot = { 3 + flake.modules.nixos.no-boot = { 4 4 boot.loader.grub.enable = false; 5 5 fileSystems."/".device = "/dev/no-device"; 6 6 }; 7 7 8 - modules.nixos.statics = { 8 + flake.modules.nixos.statics = { 9 9 system.stateVersion = "25.11"; 10 10 nixpkgs.hostPlatform = "x86_64-linux"; 11 11 passthru = { }; 12 12 }; 13 13 14 - modules.nixos.my-laptop.imports = with self.modules.nixos; [ 14 + flake.modules.nixos.my-laptop.imports = with config.flake.modules.nixos; [ 15 15 statics 16 16 no-boot 17 17 ]; 18 18 19 - nixosConfigurations.my-laptop = lib.nixosSystem { 20 - modules = [ self.modules.nixos.my-laptop ]; 19 + flake.nixosConfigurations.my-laptop = import "${pins.nixpkgs}/nixos/lib/eval-config.nix" { 20 + modules = [ config.flake.modules.nixos.my-laptop ]; 21 21 }; 22 22 }
+2 -6
modules/options/modules.nix
··· 1 - { lib, ... }: 1 + { pins, ... }: 2 2 { 3 - options.modules = lib.mkOption { 4 - description = "<class>.<aspect> modules. akin to flake-parts' flake.modules"; 5 - default = { }; 6 - type = lib.types.lazyAttrsOf (lib.types.lazyAttrsOf lib.types.deferredModule); 7 - }; 3 + imports = [ (import pins.falake).flakeModules.modules ]; 8 4 }
-8
modules/options/nixos-configurations.nix
··· 1 - { lib, ... }: 2 - { 3 - options.nixosConfigurations = lib.mkOption { 4 - description = "NixOS configurations"; 5 - default = { }; 6 - type = lib.types.lazyAttrsOf lib.types.raw; 7 - }; 8 - }
+146
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 + data = builtins.fromJSON (builtins.readFile ./sources.json); 13 + version = data.version; 14 + 15 + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 16 + range = 17 + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); 18 + 19 + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 20 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); 21 + 22 + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 23 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); 24 + concatMapStrings = f: list: concatStrings (map f list); 25 + concatStrings = builtins.concatStringsSep ""; 26 + 27 + # If the environment variable NPINS_OVERRIDE_${name} is set, then use 28 + # the path directly as opposed to the fetched source. 29 + # (Taken from Niv for compatibility) 30 + mayOverride = 31 + name: path: 32 + let 33 + envVarName = "NPINS_OVERRIDE_${saneName}"; 34 + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; 35 + ersatz = builtins.getEnv envVarName; 36 + in 37 + if ersatz == "" then 38 + path 39 + else 40 + # this turns the string into an actual Nix path (for both absolute and 41 + # relative paths) 42 + builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( 43 + if builtins.substring 0 1 ersatz == "/" then 44 + /. + ersatz 45 + else 46 + /. + builtins.getEnv "PWD" + "/${ersatz}" 47 + ); 48 + 49 + mkSource = 50 + name: spec: 51 + assert spec ? type; 52 + let 53 + path = 54 + if spec.type == "Git" then 55 + mkGitSource spec 56 + else if spec.type == "GitRelease" then 57 + mkGitSource spec 58 + else if spec.type == "PyPi" then 59 + mkPyPiSource spec 60 + else if spec.type == "Channel" then 61 + mkChannelSource spec 62 + else if spec.type == "Tarball" then 63 + mkTarballSource spec 64 + else 65 + builtins.throw "Unknown source type ${spec.type}"; 66 + in 67 + spec // { outPath = mayOverride name path; }; 68 + 69 + mkGitSource = 70 + { 71 + repository, 72 + revision, 73 + url ? null, 74 + submodules, 75 + hash, 76 + branch ? null, 77 + ... 78 + }: 79 + assert repository ? type; 80 + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository 81 + # In the latter case, there we will always be an url to the tarball 82 + if url != null && !submodules then 83 + builtins.fetchTarball { 84 + inherit url; 85 + sha256 = hash; # FIXME: check nix version & use SRI hashes 86 + } 87 + else 88 + let 89 + url = 90 + if repository.type == "Git" then 91 + repository.url 92 + else if repository.type == "GitHub" then 93 + "https://github.com/${repository.owner}/${repository.repo}.git" 94 + else if repository.type == "GitLab" then 95 + "${repository.server}/${repository.repo_path}.git" 96 + else 97 + throw "Unrecognized repository type ${repository.type}"; 98 + urlToName = 99 + url: rev: 100 + let 101 + matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; 102 + 103 + short = builtins.substring 0 7 rev; 104 + 105 + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; 106 + in 107 + "${if matched == null then "source" else builtins.head matched}${appendShort}"; 108 + name = urlToName url revision; 109 + in 110 + builtins.fetchGit { 111 + rev = revision; 112 + inherit name; 113 + # hash = hash; 114 + inherit url submodules; 115 + }; 116 + 117 + mkPyPiSource = 118 + { url, hash, ... }: 119 + builtins.fetchurl { 120 + inherit url; 121 + sha256 = hash; 122 + }; 123 + 124 + mkChannelSource = 125 + { url, hash, ... }: 126 + builtins.fetchTarball { 127 + inherit url; 128 + sha256 = hash; 129 + }; 130 + 131 + mkTarballSource = 132 + { 133 + url, 134 + locked_url ? url, 135 + hash, 136 + ... 137 + }: 138 + builtins.fetchTarball { 139 + url = locked_url; 140 + sha256 = hash; 141 + }; 142 + in 143 + if version == 5 then 144 + builtins.mapAttrs mkSource data.pins 145 + else 146 + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
+38
npins/sources.json
··· 1 + { 2 + "pins": { 3 + "falake": { 4 + "type": "Git", 5 + "repository": { 6 + "type": "Forgejo", 7 + "server": "https://codeberg.org/", 8 + "owner": "FrdrCkII", 9 + "repo": "falake" 10 + }, 11 + "branch": "main", 12 + "submodules": false, 13 + "revision": "70761ee62e87537ad428903186146a8a773b7701", 14 + "url": "https://codeberg.org/FrdrCkII/falake/archive/70761ee62e87537ad428903186146a8a773b7701.tar.gz", 15 + "hash": "0yp7arsr15zvjhj63awmcx5n677kdxllmrwrx606rx505p99xzwa" 16 + }, 17 + "import-tree": { 18 + "type": "Git", 19 + "repository": { 20 + "type": "GitHub", 21 + "owner": "vic", 22 + "repo": "import-tree" 23 + }, 24 + "branch": "main", 25 + "submodules": false, 26 + "revision": "3c23749d8013ec6daa1d7255057590e9ca726646", 27 + "url": "https://github.com/vic/import-tree/archive/3c23749d8013ec6daa1d7255057590e9ca726646.tar.gz", 28 + "hash": "0p9wqkk9280ay18b3cpzwbyaq9gwvglb22yki0q03p4vb1n0mxk6" 29 + }, 30 + "nixpkgs": { 31 + "type": "Channel", 32 + "name": "nixpkgs-unstable", 33 + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre909321.677fbe97984e/nixexprs.tar.xz", 34 + "hash": "0i4jyr0xv8i90gxil1s36yqas4qfnp52bwr02fdx90chp31kchzv" 35 + } 36 + }, 37 + "version": 5 38 + }
-41
unflake.nix
··· 1 - let 2 - deps = rec { 3 - unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable = builtins.fetchTree { 4 - type = "github"; 5 - owner = "nixos"; 6 - repo = "nixpkgs"; 7 - rev = "677fbe97984e7af3175b6c121f3c39ee5c8d62c9"; 8 - narHash = "sha256-g2a4MhRKu4ymR4xwo+I+auTknXt/+j37Lnf0Mvfl1rE="; 9 - }; 10 - unflake_github_vic_import-tree = builtins.fetchTree { 11 - type = "github"; 12 - owner = "vic"; 13 - repo = "import-tree"; 14 - rev = "3c23749d8013ec6daa1d7255057590e9ca726646"; 15 - narHash = "sha256-ZvYKbFib3AEwiNMLsejb/CWs/OL/srFQ8AogkebEPF0="; 16 - }; 17 - }; 18 - universe = rec { 19 - unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable = ((import "${deps.unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable.outPath}/flake.nix").outputs { 20 - self = unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable; 21 - }) // deps.unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable // { 22 - _flake = true; 23 - outPath = "${deps.unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable.outPath}"; 24 - sourceInfo = deps.unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable; 25 - }; 26 - unflake_github_vic_import-tree = ((import "${deps.unflake_github_vic_import-tree.outPath}/flake.nix").outputs { 27 - self = unflake_github_vic_import-tree; 28 - }) // deps.unflake_github_vic_import-tree // { 29 - _flake = true; 30 - outPath = "${deps.unflake_github_vic_import-tree.outPath}"; 31 - sourceInfo = deps.unflake_github_vic_import-tree; 32 - }; 33 - }; 34 - inputs = { 35 - import-tree = universe.unflake_github_vic_import-tree; 36 - nixpkgs = universe.unflake_github_nixos_nixpkgs_ref_nixpkgs-unstable; 37 - self = throw "to use inputs.self, write `import ./unflake.nix (inputs: ...)`"; 38 - withInputs = outputs: let self = outputs (inputs // { inherit self; }); in self; 39 - __functor = self: self.withInputs; 40 - }; 41 - in inputs
+39
with-inputs.nix
··· 1 + let 2 + sources = import ./npins; 3 + selfInputs = builtins.mapAttrs (name: value: mkInputs name value) sources; 4 + # from Nixlock: https://codeberg.org/FrdrCkII/nixlock/src/branch/main/default.nix 5 + mkInputs = 6 + name: sourceInfo: 7 + let 8 + flakePath = sourceInfo.outPath + "/flake.nix"; 9 + isFlake = sources.${name}.flake or true; 10 + in 11 + if isFlake && builtins.pathExists flakePath then 12 + let 13 + flake = import (sourceInfo.outPath + "/flake.nix"); 14 + inputs = builtins.mapAttrs (name: value: selfInputs.${name}) (flake.inputs or { }); 15 + outputs = flake.outputs (inputs // { inherit self; }); 16 + self = 17 + sourceInfo 18 + // outputs 19 + // { 20 + _type = "flake"; 21 + inherit inputs sourceInfo; 22 + }; 23 + in 24 + self 25 + else 26 + sourceInfo 27 + // { 28 + inherit sourceInfo; 29 + }; 30 + in 31 + selfInputs 32 + // { 33 + __functor = 34 + selfInputs: outputs: 35 + let 36 + self = outputs (selfInputs // { inherit self; }); 37 + in 38 + self; 39 + }