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:
parent
5620569852
commit
3300b5d582
65
flake.nix
65
flake.nix
@ -13,76 +13,43 @@
|
||||
inherit (builtins) attrNames attrValues readDir;
|
||||
inherit (nixos) lib;
|
||||
inherit (lib) removeSuffix recursiveUpdate genAttrs filterAttrs;
|
||||
inherit (utils) pathsToImportedAttrs;
|
||||
inherit (utils) pathsToImportedAttrs genPkgset overlayPaths modules
|
||||
genPackages;
|
||||
|
||||
utils = import ./lib/utils.nix { inherit lib; };
|
||||
|
||||
system = "x86_64-linux";
|
||||
|
||||
pkgImport = pkgs:
|
||||
import pkgs {
|
||||
inherit system;
|
||||
overlays = attrValues self.overlays;
|
||||
config = { allowUnfree = true; };
|
||||
};
|
||||
externOverlays = [ ];
|
||||
|
||||
pkgset = {
|
||||
osPkgs = pkgImport nixos;
|
||||
pkgs = pkgImport master;
|
||||
pkgset =
|
||||
let overlays = (attrValues self.overlays) ++ externOverlays; in
|
||||
genPkgset {
|
||||
inherit master nixos overlays system;
|
||||
};
|
||||
|
||||
in
|
||||
with pkgset;
|
||||
{
|
||||
nixosConfigurations =
|
||||
import ./hosts (recursiveUpdate inputs {
|
||||
inherit lib pkgset system utils;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
devShell."${system}" = import ./shell.nix {
|
||||
inherit pkgs;
|
||||
pkgs = osPkgs;
|
||||
};
|
||||
|
||||
overlay = import ./pkgs;
|
||||
|
||||
overlays =
|
||||
let
|
||||
overlayDir = ./overlays;
|
||||
fullPath = name: overlayDir + "/${name}";
|
||||
overlayPaths = map fullPath (attrNames (readDir overlayDir));
|
||||
in
|
||||
pathsToImportedAttrs overlayPaths;
|
||||
overlays = pathsToImportedAttrs overlayPaths;
|
||||
|
||||
packages."${system}" =
|
||||
let
|
||||
packages = self.overlay osPkgs osPkgs;
|
||||
overlays = lib.filterAttrs (n: v: n != "pkgs") self.overlays;
|
||||
overlayPkgs =
|
||||
genAttrs
|
||||
(attrNames overlays)
|
||||
(name: (overlays."${name}" osPkgs osPkgs)."${name}");
|
||||
in
|
||||
recursiveUpdate packages overlayPkgs;
|
||||
packages."${system}" = genPackages {
|
||||
overlay = self.overlay;
|
||||
overlays = self.overlays;
|
||||
pkgs = osPkgs;
|
||||
};
|
||||
|
||||
nixosModules =
|
||||
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;
|
||||
nixosModules = modules;
|
||||
|
||||
templates.flk.path = ./.;
|
||||
templates.flk.description = "flk template";
|
||||
|
@ -11,7 +11,7 @@
|
||||
let
|
||||
inherit (utils) recImport;
|
||||
inherit (builtins) attrValues removeAttrs;
|
||||
inherit (pkgset) osPkgs pkgs;
|
||||
inherit (pkgset) osPkgs unstablePkgs;
|
||||
|
||||
config = hostName:
|
||||
lib.nixosSystem {
|
||||
@ -37,7 +37,7 @@ let
|
||||
"home-manager=${home}"
|
||||
];
|
||||
|
||||
nixpkgs = { pkgs = osPkgs; };
|
||||
nixpkgs.pkgs = osPkgs;
|
||||
|
||||
nix.registry = {
|
||||
master.flake = master;
|
||||
@ -52,7 +52,7 @@ let
|
||||
overrides = {
|
||||
nixpkgs.overlays =
|
||||
let
|
||||
override = import ../pkgs/override.nix pkgs;
|
||||
override = import ../pkgs/override.nix unstablePkgs;
|
||||
|
||||
overlay = pkg: final: prev: {
|
||||
"${pkg.pname}" = pkg;
|
||||
|
@ -2,7 +2,8 @@
|
||||
let
|
||||
inherit (builtins) attrNames isAttrs readDir listToAttrs;
|
||||
|
||||
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix;
|
||||
inherit (lib) filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
||||
recursiveUpdate genAttrs;
|
||||
|
||||
# mapFilterAttrs ::
|
||||
# (name -> value -> bool )
|
||||
@ -13,21 +14,11 @@ let
|
||||
# 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"
|
||||
then
|
||||
let name = removeSuffix ".nix" n; in nameValuePair (name) (_import name)
|
||||
|
||||
else
|
||||
nameValuePair ("") (null))
|
||||
(readDir dir);
|
||||
pkgImport = { pkgs, system, overlays }:
|
||||
import pkgs {
|
||||
inherit system overlays;
|
||||
config = { allowUnfree = true; };
|
||||
};
|
||||
|
||||
# Convert a list to file paths to attribute set
|
||||
# that has the filenames stripped of nix extension as keys
|
||||
@ -38,4 +29,68 @@ in
|
||||
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;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user