Disable additional imports as it causes conflicts.

But this successfully will load all modules recursively.
This commit is contained in:
James Patrick 2022-08-11 23:55:18 -04:00
parent 9a1142962a
commit 72b31a08ea
15 changed files with 150 additions and 60 deletions

View File

@ -28,8 +28,17 @@
outputs = inputs@{ self, utils, nixpkgs, nixos-hardware, nur, home-manager
, emacs-overlay, ... }:
let inherit (utils.lib) mkFlake exportModules;
let
inherit (utils.lib) mkFlake;
inherit (self.lib.my) mapModules mapModulesRec';
in mkFlake {
lib = nixpkgs.lib.extend (self: super: {
my = import ./lib {
inherit inputs;
pkgs = nixpkgs;
lib = self;
};
});
inherit self inputs;
supportedSystems = [ "x86_64-linux" ];
@ -48,7 +57,7 @@
sharedOverlays = [ nur.overlay emacs-overlay.overlay ];
hostDefaults = {
modules = [
modules = mapModulesRec' ./modules import ++ [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;

26
lib/attrs.nix Normal file
View File

@ -0,0 +1,26 @@
{ lib, ... }:
with builtins;
with lib;
rec {
# attrsToList
attrsToList = attrs:
mapAttrsToList (name: value: { inherit name value; }) attrs;
# mapFilterAttrs ::
# (name -> value -> bool)
# (name -> value -> { name = any; value = any; })
# attrs
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
# Generate an attribute set by mapping a function over a list of values.
genAttrs' = values: f: listToAttrs (map f values);
# anyAttrs :: (name -> value -> bool) attrs
anyAttrs = pred: attrs:
any (attr: pred attr.name attr.value) (attrsToList attrs);
# countAttrs :: (name -> value -> bool) attrs
countAttrs = pred: attrs:
count (attr: pred attr.name attr.value) (attrsToList attrs);
}

19
lib/default.nix Normal file
View File

@ -0,0 +1,19 @@
{ inputs, lib, pkgs, ... }:
let
inherit (lib) makeExtensible attrValues foldr;
inherit (modules) mapModules;
modules = import ./modules.nix {
inherit lib;
self.attrs = import ./attrs.nix {
inherit lib;
self = { };
};
};
mylib = makeExtensible (self:
with self;
mapModules ./. (file: import file { inherit self lib pkgs inputs; }));
in mylib.extend (self: super: foldr (a: b: a // b) { } (attrValues super))

40
lib/modules.nix Normal file
View File

@ -0,0 +1,40 @@
{ self, lib, ... }:
let
inherit (builtins) attrValues readDir pathExists concatLists;
inherit (lib)
id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair
removeSuffix;
inherit (self.attrs) mapFilterAttrs;
in rec {
mapModules = dir: fn:
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v:
let path = "${toString dir}/${n}";
in if v == "directory" && pathExists "${path}/default.nix" then
nameValuePair n (fn path)
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n then
nameValuePair (removeSuffix ".nix" n) (fn path)
else
nameValuePair "" null) (readDir dir);
mapModules' = dir: fn: attrValues (mapModules dir fn);
mapModulesRec = dir: fn:
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v:
let path = "${toString dir}/${n}";
in if v == "directory" then
nameValuePair n (mapModulesRec path fn)
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n then
nameValuePair (removeSuffix ".nix" n) (fn path)
else
nameValuePair "" null) (readDir dir);
mapModulesRec' = dir: fn:
let
dirs = mapAttrsToList (k: _: "${dir}/${k}")
(filterAttrs (n: v: v == "directory" && !(hasPrefix "_" n))
(readDir dir));
files = attrValues (mapModules dir id);
paths = files ++ concatLists (map (d: mapModulesRec' d id) dirs);
in map fn paths;
}

25
lib/nixos.nix Normal file
View File

@ -0,0 +1,25 @@
{ inputs, lib, pkgs, ... }:
with lib;
with lib.my;
let sys = "x86_64-linux";
in {
mkHost = path: attrs @ { system ? sys, ... }:
nixosSystem {
inherit system;
specialArgs = { inherit lib inputs system; };
modules = [
{
nixpkgs.pkgs = pkgs;
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
}
(filterAttrs (n: v: !elem n [ "system" ]) attrs)
../. # /default.nix
(import path)
];
};
mapHosts = dir: attrs @ { system ? system, ... }:
mapModules dir
(hostPath: mkHost hostPath attrs);
}

16
lib/options.nix Normal file
View File

@ -0,0 +1,16 @@
{ lib, ... }:
let inherit (lib) mkOption types;
in rec {
mkOpt = type: default: mkOption { inherit type default; };
mkOpt' = type: default: description:
mkOption { inherit type default description; };
mkBoolOpt = default:
mkOption {
inherit default;
type = types.bool;
example = true;
};
}

View File

@ -1,20 +0,0 @@
{ config, pkgs, ... }: {
imports = [
./1password.nix
./blueman.nix
./dunst.nix
./emacs.nix
./gammastep.nix
./gnome-common.nix
./kdeconnect.nix
./kitty.nix
./media.nix
./nextcloud.nix
./spotify.nix
./zathura.nix
./zeal.nix
./i3
./firefox
];
}

View File

@ -3,7 +3,6 @@ let
cfg = config.this.application.firefox;
graphical = config.this.graphical;
in with lib; {
imports = [ ./tridactyl.nix ];
options.this.application.firefox = {
enable = mkOption {
default = graphical.enable;

View File

@ -1,3 +0,0 @@
{ config, pkgs, ... }: {
imports = [ ./i3.nix ./picom.nix ./polybar.nix ./rofi.nix ];
}

View File

@ -1,11 +0,0 @@
{ config, pkgs, lib, ... }:
with lib;
let
in {
options.this.graphical = {
enable = mkEnableOption "Does this actually need X/Wayland";
};
imports = [ ./applications ./lang ./system ];
}

View File

@ -1,3 +0,0 @@
{ config, pkgs, ... }: {
imports = [ ./golang.nix ./javascript.nix ./bash.nix ];
}

8
modules/options.nix Normal file
View File

@ -0,0 +1,8 @@
{ config, pkgs, lib, ... }: {
options.this.graphical = {
enable = lib.mkEnableOption "Does this actually need X/Wayland";
};
# imports = [ ./applications ./lang ./system ];
}

View File

@ -1,15 +0,0 @@
{ config, pkgs, ... }: {
imports = [
./boot.nix
./cli.nix
./displaymanager.nix
./flatpak.nix
./fonts.nix
./gtk.nix
./keyring.nix
./power.nix
./xdg.nix
./yubikey.nix
./zfs.nix
];
}

View File

@ -1,10 +1,10 @@
{ config, lib, pkgs, ... }:
let
cfg = config.system.displaymanager;
cfg = config.this.system.displaymanager;
graphical = config.this.graphical;
in with lib; {
options = {
system.displaymanager.enable = mkOption {
this.system.displaymanager.enable = mkOption {
default = graphical.enable;
type = with types; bool;
};

View File

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ inputs, config, pkgs, ... }:
let
publicKey = pkgs.fetchurl {
@ -8,8 +8,8 @@ let
in {
imports = [
../modules/. # This imports /modules/default.nix
../modules/system/xdg.nix
#../modules/. # This imports /modules/default.nix
#../modules/system/xdg.nix
];
# Allow Cleanup, nix, & flakes
nix = {