flake: move pathsToImportedAttrs to utils

This commit is contained in:
Timothy DeHerrera 2020-07-30 15:29:58 -06:00
parent 2d5471681d
commit 7e93ef7ccf
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
3 changed files with 28 additions and 27 deletions

View File

@ -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; };

View File

@ -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;
};
};

View File

@ -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;
});
}