feat: move to umport for automatic module import

This commit is contained in:
2025-06-21 11:30:35 +08:00
parent 89aa6186f2
commit 13cc8234e1
22 changed files with 314 additions and 416 deletions

View File

@@ -77,11 +77,10 @@
}) (builtins.attrNames (builtins.readDir ./config/hosts)) }) (builtins.attrNames (builtins.readDir ./config/hosts))
); );
lib = nixpkgs.lib.extend ( lib = (import ./lib/stdlib-extended.nix nixpkgs.lib).extend (
final: prev: { final: prev: {
inherit (inputs.home-manager.lib) hm; inherit (inputs.home-manager.lib) hm;
inherit infuse; inherit infuse;
my = import ./lib { lib = final; };
} }
); );
infuse = (import inputs.infuse { inherit (nixpkgs) lib; }).v1.infuse; infuse = (import inputs.infuse { inherit (nixpkgs) lib; }).v1.infuse;
@@ -168,11 +167,19 @@
outputs outputs
hostname hostname
; ;
sopsRoot = ./secrets; sopsRoot = ./secrets;
} // vars; } // vars;
modules = [ modules =
./modules (lib.umport {
paths = [ ./modules ];
exclude = [
./modules/virt/types
./modules/desktop/wm/niri/waybar
];
recursive = true;
})
++ [
(lib.mkAliasOptionModule [ "my" "home" ] [ "home-manager" "users" vars.username ])
./config/base.nix ./config/base.nix
./config/hosts/${hostname} ./config/hosts/${hostname}
inputs.chaotic.nixosModules.default inputs.chaotic.nixosModules.default

View File

@@ -9,5 +9,6 @@ in
stdlib.extend ( stdlib.extend (
self: super: { self: super: {
my = mkMyLib { lib = self; }; my = mkMyLib { lib = self; };
umport = import ./umport.nix { lib = self; };
} }
) )

48
lib/umport.nix Normal file
View File

@@ -0,0 +1,48 @@
# This function is modified from:
# https://github.com/yunfachi/nypkgs/blob/master/lib/umport.nix
#
# !!! REMOVING THIS NOTICE VIOLATES THE MIT LICENSE OF THE UMPORT PROJECT !!!
# This notice must be retained in all copies of this function, including modified versions!
# The MIT License can be found here:
# https://github.com/yunfachi/nypkgs/blob/master/LICENSE
{ lib, ... }:
let
umport =
{
path ? null,
paths ? [ ],
include ? [ ],
exclude ? [ ],
recursive ? true,
}:
with lib;
with fileset;
let
excludedFiles = filter (path: pathIsRegularFile path) exclude;
excludedDirs = filter (path: pathIsDirectory path) exclude;
isExcluded =
path:
if elem path excludedFiles then
true
else
(filter (excludedDir: lib.path.hasPrefix excludedDir path) excludedDirs) != [ ];
in
unique (
(filter
(file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file)
(
concatMap (
_path:
if recursive then
toList _path
else
mapAttrsToList (
name: type: _path + (if type == "directory" then "/${name}/default.nix" else "/${name}")
) (builtins.readDir _path)
) (unique (if path == null then paths else [ path ] ++ paths))
)
)
++ (if recursive then concatMap (path: toList path) (unique include) else unique include)
);
in
umport

View File

@@ -1,9 +0,0 @@
{
imports = [
./all.nix
./media
./misc
./monitor
./shell
];
}

View File

@@ -1,9 +0,0 @@
{
imports = [
./all.nix
./ffmpeg.nix
./mpd
./cava
./go-musicfox
];
}

View File

@@ -1,6 +0,0 @@
{
imports = [
./all.nix
./btop
];
}

View File

@@ -1,6 +0,0 @@
{
imports = [
./all.nix
./zsh.nix
];
}

View File

@@ -1,8 +0,0 @@
{
imports = [
./all.nix
./misc.nix
./langs
./editor
];
}

View File

@@ -1,7 +0,0 @@
{
imports = [
./all.nix
./neovim
./vscode
];
}

View File

@@ -1,11 +0,0 @@
{
imports = [
./all.nix
./c.nix
./go.nix
./js.nix
./rust.nix
./python.nix
./lua.nix
];
}

View File

@@ -1,24 +0,0 @@
{
lib,
username,
...
}:
{
imports = [
./cli
./coding
./virt
./desktop
./i18n
./nix.nix
./sops.nix
./gpg.nix
./time.nix
./user.nix
./xdg.nix
./persist.nix
./getty-autologin.nix
(lib.mkAliasOptionModule [ "my" "home" ] [ "home-manager" "users" username ])
];
}

View File

@@ -1,9 +0,0 @@
{
imports = [
./all.nix
./firefox.nix
./librewolf.nix
./chromium.nix
./zen.nix
];
}

View File

@@ -1,14 +0,0 @@
{
imports = [
./all.nix
./browser
./gaming
./media
./notify
./screencast
./terminal
./wm
./style
./quickshell
];
}

View File

@@ -1,7 +0,0 @@
{
imports = [
./all.nix
./minecraft.nix
./steam.nix
];
}

View File

@@ -1,11 +0,0 @@
{
imports = [
./all.nix
./mpv.nix
./shotwell.nix
./thunderbird.nix
./vlc.nix
./spotify.nix
./spotube.nix
];
}

View File

@@ -1,7 +0,0 @@
{
imports = [
./all.nix
./dunst
./swaync
];
}

View File

@@ -1,6 +0,0 @@
{
imports = [
./all.nix
./obs-studio.nix
];
}

View File

@@ -1,9 +0,0 @@
{
imports = [
./all.nix
./alacritty
./foot
./kitty
./ghostty
];
}

View File

@@ -1,7 +0,0 @@
{
imports = [
./all.nix
./cage.nix
./niri
];
}

View File

@@ -5,6 +5,7 @@
... ...
}: }:
{ {
config = lib.mkIf config.my.desktop.wm.niri.enable {
my.home.programs.niri.settings = { my.home.programs.niri.settings = {
input = { input = {
focus-follows-mouse = { focus-follows-mouse = {
@@ -256,4 +257,5 @@
}) (lib.range 0 9) }) (lib.range 0 9)
); );
}; };
};
} }

View File

@@ -14,10 +14,6 @@ in
enable = lib.mkEnableOption "Niri"; enable = lib.mkEnableOption "Niri";
}; };
imports = [
(lib.mkIf cfg.enable (import ./config.nix args))
];
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
security.pam.services.login.enableGnomeKeyring = true; security.pam.services.login.enableGnomeKeyring = true;
my.persist.homeDirs = [ my.persist.homeDirs = [

View File

@@ -1,6 +0,0 @@
{
imports = [
./fcitx5.nix
./locale.nix
];
}