dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
commit f7dde14c5181427ef1052949ead04d22d706ce34 parent 6276d998a52691043f35e864c521d781644fb957 Author: maydayv7 <maydayv7@gmail.com> Date: Tue, 24 Oct 2023 10:43:32 +0530 feat(`lib`): Add Conditional to `map.files`
Diffstat:
| M | README.md | | | 2 | ++ |
| M | configuration.nix | | | 7 | ++++--- |
| R | systems.nix -> devices/systems.nix | | | 0 | |
| M | flake.lock | | | 4 | ++-- |
| M | flake.nix | | | 16 | ++++++++++------ |
| M | lib/README.md | | | 4 | +++- |
| M | lib/map.nix | | | 31 | ++++++++++++++++++++----------- |
7 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md @@ -144,6 +144,7 @@ github:maydayv7/dotfiles ├── repl.nix ├── users ├── devices +│ ├── systems.nix │ └── vm ├── scripts │ └── nixos.nix @@ -175,6 +176,7 @@ github:maydayv7/dotfiles - `repl.nix`: interactive shell to explore syntax and configuration - [`users`](./users/README.md): individual user-specific configuration - [`devices`](./devices/README.md): system configuration for various devices +- `systems.nix`: list of supported system architectures - [`vm`](./devices/vm/README.md): declarative configuration to build multiple virtual machines - [`scripts`](./scripts/README.md): useful system management scripts - [`packages`](./packages/README.md): locally built custom packages diff --git a/configuration.nix b/configuration.nix @@ -57,7 +57,9 @@ in }; # Custom Packages - apps = map.modules ./scripts (name: lib.mkApp {drv = call name;}) // {default = self.apps."${system}".nixos;}; + apps = + map.modules ./scripts (name: lib.mkApp {drv = call name;}) + // {default = self.apps."${system}".nixos;}; packages = map.modules ./packages call // map.modules ./scripts call @@ -90,8 +92,7 @@ in templates = import ./.templates lib; ## Device Configuration ## - nixosConfigurations = - map.modules ./devices (name: build.device (import name)); + nixosConfigurations = map.modules ./devices (name: build.device (import name)); ## Virtual Machines ## vmConfigurations = diff --git a/systems.nix b/devices/systems.nix diff --git a/flake.lock b/flake.lock @@ -673,11 +673,11 @@ "locked": { "lastModified": 1, "narHash": "sha256-yJg569/Wc8hgG64XgA72/nLsZthk+InI5N+Hhmcc+kA=", - "path": "./systems.nix", + "path": "devices/systems.nix", "type": "path" }, "original": { - "path": "./systems.nix", + "path": "devices/systems.nix", "type": "path" } }, diff --git a/flake.nix b/flake.nix @@ -78,7 +78,7 @@ ## Language Addendum # Supported Architectures systems = { - url = "path:./systems.nix"; + url = "path:devices/systems.nix"; flake = false; }; @@ -98,9 +98,11 @@ # Pre-Commit Hooks hooks = { url = "github:cachix/pre-commit-hooks.nix"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "utils/flake-utils"; - inputs.gitignore.follows = "ignore"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "utils/flake-utils"; + gitignore.follows = "ignore"; + }; }; ## Feature Modules @@ -131,8 +133,10 @@ # Base16 Theming stylix = { url = "github:danth/stylix"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.home-manager.follows = "home"; + inputs = { + nixpkgs.follows = "nixpkgs"; + home-manager.follows = "home"; + }; }; # Windows VM Creator diff --git a/lib/README.md b/lib/README.md @@ -16,9 +16,11 @@ The `lib` directory contains custom-made pure Flakes-compatible utility function - [`map`](./map.nix): Mapping functions primarily aimed at shortening code complexity - - `array`: Maps required parameter to all elements present in `list` + - `checkAttr`: Checks if file contains an attrset - `filter`: Filters out unneeded `attrs` and maps required ones to specified function - `list`: Lists all toplevel `attrs` of `attrset` and returns a space-separated string - - `files`: Maps all files with a particular extension stored in a directory as an `attrset` acted upon by specified function. Use `files'` in order to recursively search inside directories + - `file`: Maps all files with a particular extension adhering to a particular condition stored in a directory as an `attrset` acted upon by specified function. Use `file'` in order to recursively search inside directories + - `files`: Same as `file` but without additional conditional - `patches`: Maps all file patches stored in a directory, if available - `module`: Maps all configuration files stored in a directory into a list for easy import. Use `module'` in order to map file names instead of paths - `modules`: Maps all configuration modules stored in a directory as an `attrset` acted upon by specified function. Use `modules'` in order to recursively search inside directories diff --git a/lib/map.nix b/lib/map.nix @@ -8,6 +8,7 @@ pathExists readDir toString + typeOf ; inherit @@ -33,14 +34,15 @@ in rec { ## Files Map # Top Level - files = dir: func: extension: + files = dir: func: ext: file dir func ext (_: true); + file = dir: func: ext: cond: filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let path = "${toString dir}/${name}"; in if (type == "directory" || type == "symlink") && ( - if (extension == ".nix") + if (ext == ".nix") then pathExists "${path}/default.nix" else true ) @@ -49,16 +51,18 @@ in rec { type == "regular" && ( - if (extension == ".nix") + if (ext == ".nix") then name != "default.nix" else true ) - && hasSuffix extension name - then nameValuePair (removeSuffix extension name) (func path) + && hasSuffix ext name + && (cond path) + then nameValuePair (removeSuffix ext name) (func path) else nameValuePair "" null) (readDir dir); # Recursive - files' = dir: func: extension: + files' = dir: func: ext: file' dir func ext (_: true); + file' = dir: func: ext: cond: filter (name: type: type != null && !(hasPrefix "_" name)) (name: type: let path = "${toString dir}/${name}"; in @@ -68,12 +72,13 @@ in rec { type == "regular" && ( - if (extension == ".nix") + if (ext == ".nix") then name != "default.nix" else true ) - && hasSuffix extension name - then nameValuePair (removeSuffix extension name) (func path) + && hasSuffix ext name + && (cond path) + then nameValuePair (removeSuffix ext name) (func path) else nameValuePair "" null) (readDir dir); # Package Patches @@ -90,10 +95,14 @@ in rec { else patch; # Module Imports + checkAttr = name: let + file = import name; + in + typeOf file == "set" || typeOf file == "lambda"; module = dir: attrValues (modules dir id); module' = dir: attrNames (modules dir id); - modules = dir: func: files dir func ".nix"; - modules' = dir: func: files' dir func ".nix"; + modules = dir: func: file dir func ".nix" checkAttr; + modules' = dir: func: file' dir func ".nix" checkAttr; # 'sops' Encrypted Secrets secrets = dir: neededForUsers: