flake: clean up by moving implementation to utils

Fixes #28 by adding an `externOverlays` list to easily import overlays
from external flakes.
This commit is contained in:
Timothy DeHerrera 2020-12-25 12:53:57 -07:00
parent 5620569852
commit 3300b5d582
No known key found for this signature in database
GPG key ID: 8985725DB5B0C122
3 changed files with 91 additions and 69 deletions

View file

@ -13,76 +13,43 @@
inherit (builtins) attrNames attrValues readDir; inherit (builtins) attrNames attrValues readDir;
inherit (nixos) lib; inherit (nixos) lib;
inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs; inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs;
inherit (utils) pathsToImportedAttrs; inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
genPackages;
utils = import ./lib/utils.nix { inherit lib; }; utils = import ./lib/utils.nix { inherit lib; };
system = "x86_64-linux"; system = "x86_64-linux";
pkgImport = pkgs: externOverlays = [ ];
import pkgs {
inherit system;
overlays = attrValues self.overlays;
config = { allowUnfree = true; };
};
pkgset = { pkgset =
osPkgs = pkgImport nixos; let overlays = (attrValues self.overlays) ++ externOverlays; in
pkgs = pkgImport master; genPkgset {
inherit master nixos overlays system;
}; };
in in
with pkgset; with pkgset;
{ {
nixosConfigurations = nixosConfigurations =
import ./hosts (recursiveUpdate inputs { import ./hosts (recursiveUpdate inputs {
inherit lib pkgset system utils; inherit lib pkgset system utils;
} });
);
devShell."${system}" = import ./shell.nix { devShell."${system}" = import ./shell.nix {
inherit pkgs; pkgs = osPkgs;
}; };
overlay = import ./pkgs; overlay = import ./pkgs;
overlays = overlays = pathsToImportedAttrs overlayPaths;
let
overlayDir = ./overlays;
fullPath = name: overlayDir + "/${name}";
overlayPaths = map fullPath (attrNames (readDir overlayDir));
in
pathsToImportedAttrs overlayPaths;
packages."${system}" = packages."${system}" = genPackages {
let overlay = self.overlay;
packages = self.overlay osPkgs osPkgs; overlays = self.overlays;
overlays = lib.filterAttrs (n: v: n != "pkgs") self.overlays; pkgs = osPkgs;
overlayPkgs = };
genAttrs
(attrNames overlays)
(name: (overlays."${name}" osPkgs osPkgs)."${name}");
in
recursiveUpdate packages overlayPkgs;
nixosModules = nixosModules = modules;
let
# binary cache
cachix = import ./cachix.nix;
cachixAttrs = { inherit cachix; };
# modules
moduleList = import ./modules/list.nix;
modulesAttrs = pathsToImportedAttrs moduleList;
# profiles
profilesList = import ./profiles/list.nix;
profilesAttrs = { profiles = pathsToImportedAttrs profilesList; };
in
recursiveUpdate
(recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs;
templates.flk.path = ./.; templates.flk.path = ./.;
templates.flk.description = "flk template"; templates.flk.description = "flk template";

View file

@ -11,7 +11,7 @@
let let
inherit (utils) recImport; inherit (utils) recImport;
inherit (builtins) attrValues removeAttrs; inherit (builtins) attrValues removeAttrs;
inherit (pkgset) osPkgs pkgs; inherit (pkgset) osPkgs unstablePkgs;
config = hostName: config = hostName:
lib.nixosSystem { lib.nixosSystem {
@ -37,7 +37,7 @@ let
"home-manager=${home}" "home-manager=${home}"
]; ];
nixpkgs = { pkgs = osPkgs; }; nixpkgs.pkgs = osPkgs;
nix.registry = { nix.registry = {
master.flake = master; master.flake = master;
@ -52,7 +52,7 @@ let
overrides = { overrides = {
nixpkgs.overlays = nixpkgs.overlays =
let let
override = import ../pkgs/override.nix pkgs; override = import ../pkgs/override.nix unstablePkgs;
overlay = pkg: final: prev: { overlay = pkg: final: prev: {
"${pkg.pname}" = pkg; "${pkg.pname}" = pkg;

View file

@ -2,7 +2,8 @@
let let
inherit (builtins) attrNames isAttrs readDir listToAttrs; inherit (builtins) attrNames isAttrs readDir listToAttrs;
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix; inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
recursiveUpdate genAttrs;
# mapFilterAttrs :: # mapFilterAttrs ::
# (name -> value -> bool ) # (name -> value -> bool )
@ -13,21 +14,11 @@ let
# Generate an attribute set by mapping a function over a list of values. # Generate an attribute set by mapping a function over a list of values.
genAttrs' = values: f: listToAttrs (map f values); genAttrs' = values: f: listToAttrs (map f values);
in pkgImport = { pkgs, system, overlays }:
{ import pkgs {
inherit mapFilterAttrs genAttrs'; inherit system overlays;
config = { allowUnfree = true; };
recImport = { dir, _import ? base: import "${dir}/${base}.nix" }: };
mapFilterAttrs
(_: v: v != null)
(n: v:
if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
then
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
else
nameValuePair ("") (null))
(readDir dir);
# Convert a list to file paths to attribute set # Convert a list to file paths to attribute set
# that has the filenames stripped of nix extension as keys # that has the filenames stripped of nix extension as keys
@ -38,4 +29,68 @@ in
value = import path; value = import path;
}); });
in
{
inherit mapFilterAttrs genAttrs' pkgImport pathsToImportedAttrs;
genPkgset = { master, nixos, overlays, system }:
{
osPkgs = pkgImport {
inherit system overlays;
pkgs = nixos;
};
unstablePkgs = pkgImport {
inherit system overlays;
pkgs = master;
};
};
overlayPaths =
let
overlayDir = ../overlays;
fullPath = name: overlayDir + "/${name}";
in
map fullPath (attrNames (readDir overlayDir));
recImport = { dir, _import ? base: import "${dir}/${base}.nix" }:
mapFilterAttrs
(_: v: v != null)
(n: v:
if n != "default.nix" && hasSuffix ".nix" n && v == "regular"
then
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
else
nameValuePair ("") (null))
(readDir dir);
modules =
let
# binary cache
cachix = import ../cachix.nix;
cachixAttrs = { inherit cachix; };
# modules
moduleList = import ../modules/list.nix;
modulesAttrs = pathsToImportedAttrs moduleList;
# profiles
profilesList = import ../profiles/list.nix;
profilesAttrs = { profiles = pathsToImportedAttrs profilesList; };
in
recursiveUpdate
(recursiveUpdate cachixAttrs modulesAttrs)
profilesAttrs;
genPackages = { overlay, overlays, pkgs }:
let
packages = overlay pkgs pkgs;
overlays' = lib.filterAttrs (n: v: n != "pkgs") overlays;
overlayPkgs =
genAttrs
(attrNames overlays')
(name: (overlays'."${name}" pkgs pkgs)."${name}");
in
recursiveUpdate packages overlayPkgs;
} }