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 }: outputs = inputs@{ self, home, nixpkgs, unstable }:
let let
inherit (builtins) listToAttrs baseNameOf attrNames attrValues readDir; inherit (builtins) attrNames attrValues readDir;
inherit (nixpkgs.lib) removeSuffix; inherit (nixpkgs) lib;
inherit (lib) removeSuffix;
inherit (utils) pathsToImportedAttrs;
utils = import ./lib/utils.nix { inherit lib; };
system = "x86_64-linux"; 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: pkgImport = pkgs:
import pkgs { import pkgs {
inherit system; inherit system;
@ -31,14 +24,11 @@
}; };
pkgs = pkgImport nixpkgs; pkgs = pkgImport nixpkgs;
unstablePkgs = pkgImport unstable; unstablePkgs = pkgImport unstable;
in { in {
nixosConfigurations = let nixosConfigurations =
configs = import ./hosts (inputs // { inherit system pkgs unstablePkgs utils; });
import ./hosts (inputs // { inherit system pkgs unstablePkgs; });
in configs;
devShell."${system}" = import ./shell.nix { inherit pkgs; }; 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 let
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
utils = import ../lib/utils.nix { inherit lib; };
inherit (utils) recImport; inherit (utils) recImport;
inherit (builtins) attrValues removeAttrs; inherit (builtins) attrValues removeAttrs;
config = hostName: config = hostName:
@ -30,7 +26,7 @@ let
nix.registry = { nix.registry = {
nixpkgs.flake = nixpkgs; nixpkgs.flake = nixpkgs;
nixflk.flake = self; nixflk.flake = self;
master.flake = inputs.unstable; master.flake = unstable;
}; };
}; };

View File

@ -1,16 +1,21 @@
{ lib, ... }: { lib, ... }:
let let
inherit (builtins) attrNames isAttrs readDir; inherit (builtins) attrNames isAttrs readDir listToAttrs;
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix; inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
in rec {
# mapFilterAttrs :: # mapFilterAttrs ::
# (name -> value -> bool ) # (name -> value -> bool )
# (name -> value -> { name = any; value = any; }) # (name -> value -> { name = any; value = any; })
# attrs # attrs
mapFilterAttrs = seive: f: attrs: filterAttrs seive (mapAttrs' f 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" }: recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
mapFilterAttrs (_: v: v != null) (n: v: mapFilterAttrs (_: v: v != null) (n: v:
if n != "default.nix" && hasSuffix ".nix" n && v == "regular" if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
@ -20,4 +25,14 @@ in rec {
else else
nameValuePair ("") (null)) (readDir dir); 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;
});
} }