diff options
| author | outremonde <outremonde@vivaldi.net> | 2025-06-10 20:32:00 -0400 |
|---|---|---|
| committer | outremonde <outremonde@vivaldi.net> | 2025-06-10 20:32:00 -0400 |
| commit | 9786eb8672213344d8d1b7bdef12bc94510b20db (patch) | |
| tree | b7d79440800c92d32187ab32c636b0830c94a610 /lib | |
initialized repository
Former-commit-id: 84647f22b951a957b2b83885b612115d473f6626
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/helper.nix | 80 | ||||
| -rwxr-xr-x | lib/umport.nix | 52 |
2 files changed, 132 insertions, 0 deletions
diff --git a/lib/helper.nix b/lib/helper.nix new file mode 100644 index 0000000..5bea0f1 --- /dev/null +++ b/lib/helper.nix @@ -0,0 +1,80 @@ +{inputs}: let + helper = (import ./helper.nix) {inherit inputs;}; +in rec { + # Library to shorten flake. + + # Package Helpers + pkgsFor = sys: inputs.nixpkgs.legacyPackages.${sys}; + + # Miscellaneous + forAllSystems = inputs.nixpkgs.lib.genAttrs [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + + # Create a custom packages overlat for use in configs. IDK HOW THIS WORKS BUT IT DOES + customPackagesOverlay.nixpkgs.overlays = [ + (final: prev: + import ../pkgs { + pkgs = final; + inherit inputs; + }) + ]; + + # Create custom packages set for exposure via flake. + customPackages = forAllSystems ( + system: + import ../pkgs { + pkgs = inputs.nixpkgs.legacyPackages.${system}; + inherit inputs; + } + ); + + # Get Custom Libraries + umport = (import ./umport.nix {inherit (inputs.nixpkgs) lib;}).umport; + + # Configuration Buildables + mkSystem = system: architecture: ( + inputs.nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs helper; + }; + modules = + [ + ../systems/${system}/system.nix + customPackagesOverlay + ] + ++ umport { + paths = [ + ../modules/system + ../features/system + ]; + recursive = true; + }; + system = architecture; + } + ); + + mkHome = user: system: architecture: ( + inputs.home-manager.lib.homeManagerConfiguration { + pkgs = pkgsFor architecture; + extraSpecialArgs = { + inherit inputs helper; + }; + modules = + [ + ../users/${system}/${user}.nix + customPackagesOverlay + ] + ++ umport { + paths = [ + ../modules/user + ../features/user + ]; + recursive = true; + }; + } + ); +} diff --git a/lib/umport.nix b/lib/umport.nix new file mode 100755 index 0000000..f076d85 --- /dev/null +++ b/lib/umport.nix @@ -0,0 +1,52 @@ +{lib, ...}: let + umport = inputs @ { + path ? null, + paths ? [], + include ? [], + exclude ? [], + recursive ? true, + }: + with lib; + with fileset; let + excludedFiles = filter (path: pathIsRegularFile path) exclude; + excludedDirs = filter (path: pathIsDirectory path) exclude; + isExcluded = path: + if (elem path excludedFiles) || (hasSuffix "flake.nix" path) || (hasSuffix "shell.nix" path) + then true + else (filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != []; + in + unique ( + ( + filter + (file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file) + (concatMap ( + _path: + if recursive + then toList _path + else + mapAttrsToList ( + name: type: + _path + + ( + if type == "directory" + then "/${name}/default.nix" + else "/${name}" + ) + ) + (builtins.readDir _path) + ) + (unique ( + if path == null + then paths + else [path] ++ paths + ))) + ) + ++ ( + if recursive + then concatMap (path: toList path) (unique include) + else unique include + ) + ); +in { + inherit umport; +} |
