diff --git a/flake.nix b/flake.nix index 4e09cff..60cd03c 100644 --- a/flake.nix +++ b/flake.nix @@ -7,22 +7,15 @@ outputs = inputs@{ self, home, nixpkgs, unstable }: let - inherit (builtins) listToAttrs baseNameOf attrNames attrValues readDir; - inherit (nixpkgs.lib) removeSuffix; + inherit (builtins) attrNames attrValues readDir; + inherit (nixpkgs) lib; + inherit (lib) removeSuffix; + inherit (utils) pathsToImportedAttrs; + + utils = import ./lib/utils.nix { inherit lib; }; + system = "x86_64-linux"; - # Generate an attribute set by mapping a function over a list of values. - genAttrs' = values: f: listToAttrs (map f values); - - # Convert a list to file paths to attribute set - # that has the filenames stripped of nix extension as keys - # and imported content of the file as value. - pathsToImportedAttrs = paths: - genAttrs' paths (path: { - name = removeSuffix ".nix" (baseNameOf path); - value = import path; - }); - pkgImport = pkgs: import pkgs { inherit system; @@ -31,14 +24,11 @@ }; pkgs = pkgImport nixpkgs; - unstablePkgs = pkgImport unstable; in { - nixosConfigurations = let - configs = - import ./hosts (inputs // { inherit system pkgs unstablePkgs; }); - in configs; + nixosConfigurations = + import ./hosts (inputs // { inherit system pkgs unstablePkgs utils; }); devShell."${system}" = import ./shell.nix { inherit pkgs; }; diff --git a/hosts/default.nix b/hosts/default.nix index 7ea7e31..f51e1c3 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,11 +1,7 @@ -inputs@{ home, nixpkgs, unstablePkgs, self, pkgs, system, ... }: +{ home, nixpkgs, unstable, unstablePkgs, self, pkgs, system, utils, ... }: let inherit (nixpkgs) lib; - - utils = import ../lib/utils.nix { inherit lib; }; - inherit (utils) recImport; - inherit (builtins) attrValues removeAttrs; config = hostName: @@ -30,7 +26,7 @@ let nix.registry = { nixpkgs.flake = nixpkgs; nixflk.flake = self; - master.flake = inputs.unstable; + master.flake = unstable; }; }; diff --git a/lib/utils.nix b/lib/utils.nix index 53d92c4..bd55d9a 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -1,16 +1,21 @@ { lib, ... }: let - inherit (builtins) attrNames isAttrs readDir; + inherit (builtins) attrNames isAttrs readDir listToAttrs; inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix; -in rec { # mapFilterAttrs :: # (name -> value -> bool ) # (name -> value -> { name = any; value = any; }) # attrs mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f attrs); + # Generate an attribute set by mapping a function over a list of values. + genAttrs' = values: f: listToAttrs (map f values); + +in { + inherit mapFilterAttrs genAttrs'; + recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: mapFilterAttrs (_: v: v != null) (n: v: if n != "default.nix" && hasSuffix ".nix" n && v == "regular" @@ -20,4 +25,14 @@ in rec { else nameValuePair ("") (null)) (readDir dir); + + # Convert a list to file paths to attribute set + # that has the filenames stripped of nix extension as keys + # and imported content of the file as value. + pathsToImportedAttrs = paths: + genAttrs' paths (path: { + name = removeSuffix ".nix" (baseNameOf path); + value = import path; + }); + }