diff --git a/flake.lock b/flake.lock index 78717679..669d517a 100644 --- a/flake.lock +++ b/flake.lock @@ -87,7 +87,7 @@ "flakelib": { "inputs": { "fl-config": "fl-config", - "std": "std" + "std": "std_2" }, "locked": { "lastModified": 1683326042, @@ -175,7 +175,9 @@ "nixpkgs": "nixpkgs", "nur": "nur", "sops-nix": "sops-nix", - "systemd2mqtt": "systemd2mqtt" + "std": "std", + "systemd2mqtt": "systemd2mqtt", + "tree": "tree" } }, "rust": { @@ -221,6 +223,21 @@ } }, "std": { + "locked": { + "lastModified": 1701658249, + "narHash": "sha256-KIt1TUuBvldhaVRta010MI5FeQlB8WadjqljybjesN0=", + "owner": "chessai", + "repo": "nix-std", + "rev": "715db541ffff4194620e48d210b76f73a74b5b5d", + "type": "github" + }, + "original": { + "owner": "chessai", + "repo": "nix-std", + "type": "github" + } + }, + "std_2": { "inputs": { "nix-std": "nix-std" }, @@ -274,6 +291,29 @@ "repo": "default", "type": "github" } + }, + "tree": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "std": [ + "std" + ] + }, + "locked": { + "lastModified": 1676505934, + "narHash": "sha256-jeqZtNLOKXRSDmD1v+b9+v+hwVyH6kcKzZ9f0gcJpdk=", + "owner": "kittywitch", + "repo": "tree", + "rev": "a831f6fd209e3d00c5026303994de28d0031ab3b", + "type": "github" + }, + "original": { + "owner": "kittywitch", + "repo": "tree", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 1999f437..4b7c7306 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,9 @@ url = "github:arcnmx/nixexprs/master"; flake = false; }; + std = { + url = "github:chessai/nix-std"; + }; ci = { url = "github:arcnmx/ci/v0.6"; flake = false; @@ -20,6 +23,11 @@ url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + tree = { + url = "github:kittywitch/tree"; + inputs.std.follows = "std"; + inputs.nixpkgs.follows = "nixpkgs"; + }; systemd2mqtt = { url = "github:arcnmx/systemd2mqtt"; inputs = { diff --git a/mkTree.nix b/mkTree.nix deleted file mode 100644 index 027fc138..00000000 --- a/mkTree.nix +++ /dev/null @@ -1,130 +0,0 @@ -{ lib }: { config, folder, inputs, ... }@args: let - inherit (lib.attrsets) filterAttrs mapAttrs' mapAttrs isAttrs nameValuePair attrValues; - inherit (lib.strings) hasPrefix removeSuffix; - inherit (lib.lists) imap1 singleton optionals optional sublist; - inherit (lib.trivial) pipe; - inherit (lib.options) mkOption; - inherit (lib.modules) evalModules; - pureTreeGrab = { base, path }: let - realPath = toString path; - dirContents = builtins.readDir path; - isDirectory = entry: dirContents."${entry}" == "directory"; - isHidden = entry: hasPrefix "." entry; - isDir = entry: _: (isDirectory entry) && !(isHidden entry); - directories = filterAttrs isDir dirContents; - isNixFile = entry: _: let - result = builtins.match "(.*)\\.nix" entry; - in result != null && builtins.length result > 0; - nixFiles = filterAttrs isNixFile dirContents; - getPath = entry: "${realPath}/${entry}"; - getPaths = entries: mapAttrs' (n: v: - nameValuePair (removeSuffix ".nix" n) (getPath n) - ) entries; - nixFilePaths = getPaths nixFiles; - dirPaths = getPaths directories; - recursedPaths = mapAttrs (_: fullPath: pureTreeGrab { - inherit base; - path = fullPath; - }) dirPaths; - contents = recursedPaths // nixFilePaths; - in contents; - configTreeStruct = { config, ... }: { - options.treeConfig = mkOption { - type = lib.types.attrsOf (lib.types.submodule ({ name, options, config, ... }: { - options = { - evaluateDefault = mkOption { - type = lib.types.bool; - description = "Replace the contents of this branch or leaf with those provided by the evaluation of default.nix."; - default = false; - }; - aliasDefault = mkOption { - type = lib.types.bool; - description = "Replace the contents of this branch or leaf with the default.nix."; - default = false; - }; - excludes = mkOption { - type = lib.types.listOf lib.types.str; - description = "Exclude files or folders from the recurser."; - default = []; - }; - functor = { - enable = mkOption { - type = lib.types.bool; - description = "Provide a functor for the path provided"; - default = false; - }; - external = mkOption { - type = lib.types.listOf lib.types.unspecified; - description = "Add external imports into the functor."; - default = []; - }; - excludes = mkOption { - type = lib.types.listOf lib.types.str; - description = "Exclude files or folders from the functor."; - default = []; - }; - }; - }; - })); - }; - config.treeConfig = { - "*" = {}; - "/" = {}; - }; - }; - configTree.treeConfig = config; - configTreeModule = (evalModules { - modules = [ - configTreeStruct - configTree - ]; - }).config.treeConfig; - mapAttrsRecursive = f: set: let - recurse = path: set: let - g = name: value: if isAttrs value - then f (path ++ [name]) (recurse (path ++ [name]) value) - else f (path ++ [name]) value; - in mapAttrs g set; - in f [] (recurse [] set); - getPathString = path: builtins.concatStringsSep "/" path; - getConfig = path: default: configTreeModule.${getPathString path} or default; - revtail = path: sublist 0 (builtins.length path - 1) path; - getConfigRecursive = path: let - parentPath = revtail path; - in getConfig (path ++ singleton "*") (getConfigRecursive parentPath); - processLeaves = tree: config: mapAttrsRecursive (path: value: let - pathString = getPathString path; - leafConfig = if path == [] then - configTreeModule."/" - else getConfig path (getConfigRecursive (revtail path)); - processConfig = path: value: let - processFunctor = prev: prev // { - __functor = self: { ... }: { - imports = attrValues (removeAttrs prev leafConfig.functor.excludes) ++ leafConfig.functor.external; - }; - }; - processAliasDefault = prev: prev.default; - processDefault = prev: import prev.default (args // { - inherit lib; - tree = { - prev = removeAttrs prev (singleton "default"); - pure = pureTree; - impure = impureTree; - }; - }); - processExcludes = prev: removeAttrs prev leafConfig.excludes; - processes = optionals (isAttrs value) ( - optional (leafConfig.excludes != []) processExcludes - ++ optional leafConfig.evaluateDefault processDefault - ++ optional leafConfig.aliasDefault processAliasDefault - ++ optional leafConfig.functor.enable processFunctor - ); - in pipe value processes; - in processConfig path value) tree; - pureTree = pureTreeGrab { base = folder; path = folder; }; - impureTree = processLeaves pureTree configTreeModule; -in { - config = configTreeModule; - pure = pureTree; - impure = impureTree; -} diff --git a/tree.nix b/tree.nix index e3c3585b..ea1fa489 100644 --- a/tree.nix +++ b/tree.nix @@ -2,68 +2,63 @@ inputs, lib, ... -}: let - mkTree = import ./mkTree.nix {inherit lib;}; - tree = mkTree { - inherit inputs; - folder = ./.; - config = { - "/" = { - excludes = [ - "tf" - "inputs" - "default" - "patchedInputs" - "mkTree" - "outputs" - "tree" - "flake" - "meta" - "inputs" +}: (inputs.tree.tree { + inherit inputs; + folder = ./.; + config = { + "/" = { + excludes = [ + "tf" + "inputs" + "default" + "patchedInputs" + "mkTree" + "outputs" + "tree" + "flake" + "meta" + "inputs" + ]; + }; + "modules/nixos" = { + functor = { + external = with (import (inputs.arcexprs + "/modules")).nixos; [ + nix + systemd + dht22-exporter + glauth + modprobe + kernel + crypttab + mutable-state + common-root + pulseaudio + wireplumber + alsa + bindings + matrix-appservices + matrix-synapse-appservices + display + filebin + mosh + doc-warnings + inputs.systemd2mqtt.nixosModules.default ]; }; - "modules/nixos" = { - functor = { - external = - with (import (inputs.arcexprs + "/modules")).nixos; [ - nix - systemd - dht22-exporter - glauth - modprobe - kernel - crypttab - mutable-state - common-root - pulseaudio - wireplumber - alsa - bindings - matrix-appservices - matrix-synapse-appservices - display - filebin - mosh - doc-warnings - inputs.systemd2mqtt.nixosModules.default - ]; - }; - }; - "modules/nixos".functor.enable = true; - "modules/meta".functor.enable = true; - "modules/system".functor.enable = true; - "modules/home".functor.enable = true; - "modules/type".functor.enable = true; - "nixos/*".functor = { - enable = true; - }; - "system".functor.enable = true; - "hardware".evaluateDefault = true; - "nixos/cross".evaluateDefault = true; - "hardware/*".evaluateDefault = true; - "home".evaluateDefault = true; - "home/*".functor.enable = true; }; + "modules/nixos".functor.enable = true; + "modules/meta".functor.enable = true; + "modules/system".functor.enable = true; + "modules/home".functor.enable = true; + "modules/type".functor.enable = true; + "nixos/*".functor = { + enable = true; + }; + "system".functor.enable = true; + "hardware".evaluateDefault = true; + "nixos/cross".evaluateDefault = true; + "hardware/*".evaluateDefault = true; + "home".evaluateDefault = true; + "home/*".functor.enable = true; }; -in - tree +})