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,21 +167,29 @@
outputs outputs
hostname hostname
; ;
sopsRoot = ./secrets; sopsRoot = ./secrets;
} // vars; } // vars;
modules = [ modules =
./modules (lib.umport {
./config/base.nix paths = [ ./modules ];
./config/hosts/${hostname} exclude = [
inputs.chaotic.nixosModules.default ./modules/virt/types
inputs.sops-nix.nixosModules.sops ./modules/desktop/wm/niri/waybar
inputs.impermanence.nixosModules.impermanence ];
inputs.home-manager.nixosModules.default recursive = true;
inputs.niri.nixosModules.niri })
home ++ [
pkgsConf (lib.mkAliasOptionModule [ "my" "home" ] [ "home-manager" "users" vars.username ])
]; ./config/base.nix
./config/hosts/${hostname}
inputs.chaotic.nixosModules.default
inputs.sops-nix.nixosModules.sops
inputs.impermanence.nixosModules.impermanence
inputs.home-manager.nixosModules.default
inputs.niri.nixosModules.niri
home
pkgsConf
];
} }
); );
}; };

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,255 +5,257 @@
... ...
}: }:
{ {
my.home.programs.niri.settings = { config = lib.mkIf config.my.desktop.wm.niri.enable {
input = { my.home.programs.niri.settings = {
focus-follows-mouse = { input = {
enable = true; focus-follows-mouse = {
max-scroll-amount = "40%"; enable = true;
max-scroll-amount = "40%";
};
workspace-auto-back-and-forth = true;
}; };
workspace-auto-back-and-forth = true;
};
layout = { layout = {
gaps = 23; gaps = 23;
center-focused-column = "never"; center-focused-column = "never";
always-center-single-column = true; always-center-single-column = true;
focus-ring.enable = false; focus-ring.enable = false;
border = { border = {
enable = true;
width = 4;
inactive.color = "#2e2e3eee";
active.gradient = {
from = "#6186d6ee";
to = "#cba6f7ee";
angle = 180;
relative-to = "workspace-view";
};
};
preset-column-widths = [
{ proportion = 0.33333; }
{ proportion = 0.4; }
{ proportion = 0.5; }
{ proportion = 0.6; }
{ proportion = 0.66667; }
];
default-column-width.proportion = 0.4;
background-color = "transparent";
};
animations = {
enable = true; enable = true;
width = 4; slowdown = 1.5;
workspace-switch.kind.spring = {
inactive.color = "#2e2e3eee"; damping-ratio = 1.0;
active.gradient = { stiffness = 1000;
from = "#6186d6ee"; epsilon = 0.0001;
to = "#cba6f7ee";
angle = 180;
relative-to = "workspace-view";
}; };
}; };
preset-column-widths = [
{ proportion = 0.33333; } prefer-no-csd = true;
{ proportion = 0.4; } hotkey-overlay.skip-at-startup = true;
{ proportion = 0.5; }
{ proportion = 0.6; } clipboard.disable-primary = true;
{ proportion = 0.66667; }
layer-rules = [
{
matches = [ { namespace = "^wallpaper$"; } ];
place-within-backdrop = true;
}
]; ];
default-column-width.proportion = 0.4; overview.workspace-shadow.enable = false;
background-color = "transparent";
};
animations = { window-rules = [
enable = true; {
slowdown = 1.5; geometry-corner-radius = {
workspace-switch.kind.spring = { bottom-left = 14.;
damping-ratio = 1.0; bottom-right = 14.;
stiffness = 1000; top-left = 14.;
epsilon = 0.0001; top-right = 14.;
};
clip-to-geometry = true;
draw-border-with-background = false;
}
{
matches = [ { app-id = "kitty|foot|Alacritty|ghostty|chromium-browser|zen-beta|wofi"; } ];
opacity = 0.8;
}
{
matches = [ { app-id = "org.gnome.Nautilus|nemo"; } ];
opacity = 0.6;
}
];
environment = {
QT_QPA_PLATFORM = "wayland;xcb";
XDG_SESSION_TYPE = "wayland";
XDG_CURRENT_DESKTOP = "niri";
XDG_SESSION_DESKTOP = "niri";
QT_AUTO_SCREEN_SCALE_FACTOR = "1";
}; };
spawn-at-startup = map (c: { command = c; }) [
[ "${lib.getExe' pkgs.swaynotificationcenter "swaync"}" ]
[
"${lib.getExe pkgs.swaybg}"
"-m"
"fill"
"-i"
(toString ./wallpaper.png)
]
[
"wl-paste"
"--type"
"text"
"--watch"
"cliphist"
"store"
]
[
"wl-paste"
"--type"
"image"
"--watch"
"cliphist"
"store"
]
];
binds =
with config.my.home.lib.niri.actions;
{
"Ctrl+Alt+T".action.spawn = [
"kitty"
"-1"
];
"Mod+T".action.spawn = [
"kitty"
"-1"
];
"Mod+Return".action.spawn = [
"kitty"
"-1"
];
"Mod+G".action.spawn = [ "zen-beta" ];
"Mod+E".action.spawn = [ "nemo" ];
"Mod+R".action.spawn = [
"sh"
"-c"
"pkill wofi || wofi --color ~/.config/wal/colors"
];
"Mod+V".action.spawn = [
"sh"
"-c"
"pkill ${lib.getExe pkgs.wofi} || ${lib.getExe pkgs.cliphist} list | wofi --dmenu --color ~/.config/wal/colors | cliphist decode | wl-copy"
];
"XF86AudioRaiseVolume" = {
allow-when-locked = true;
action.spawn = [
"pamixer"
"-i"
"2"
];
};
"XF86AudioLowerVolume" = {
allow-when-locked = true;
action.spawn = [
"pamixer"
"-d"
"2"
];
};
"XF86AudioMute" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"play-pause"
];
};
"Mod+XF86AudioRaiseVolume" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"next"
];
};
"Mod+XF86AudioLowerVolume" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"previous"
];
};
"Mod+Q".action = close-window;
"Mod+Left".action = focus-column-left;
"Mod+Right".action = focus-column-right;
"Mod+Up".action = focus-window-up;
"Mod+Down".action = focus-window-down;
"Mod+Ctrl+Left".action = move-column-left;
"Mod+Ctrl+Right".action = move-column-right;
"Mod+Ctrl+Up".action = move-window-up;
"Mod+Ctrl+Down".action = move-window-down;
"Mod+Alt+Left".action = consume-or-expel-window-left;
"Mod+Alt+Right".action = consume-or-expel-window-right;
"Mod+Shift+Left".action = focus-monitor-left;
"Mod+Shift+Right".action = focus-monitor-right;
"Mod+Shift+Up".action = focus-monitor-up;
"Mod+Shift+Down".action = focus-monitor-down;
"Mod+Shift+Ctrl+Left".action = move-column-to-monitor-left;
"Mod+Shift+Ctrl+Right".action = move-column-to-monitor-right;
"Mod+Shift+Ctrl+Up".action = move-column-to-monitor-up;
"Mod+Shift+Ctrl+Down".action = move-column-to-monitor-down;
"Mod+Page_Up".action = focus-workspace-up;
"Mod+Page_Down".action = focus-workspace-down;
"Mod+Ctrl+Page_Up".action = move-column-to-workspace-up;
"Mod+Ctrl+Page_Down".action = move-column-to-workspace-down;
"Mod+Shift+Page_Up".action = move-workspace-up;
"Mod+Shift+Page_Down".action = move-workspace-down;
"Mod+L".action = switch-preset-column-width;
"Mod+Shift+L".action = reset-window-height;
"Mod+M".action = maximize-column;
"Mod+Shift+M".action = fullscreen-window;
"Mod+C".action = center-column;
"Mod+F".action = toggle-window-floating;
"Mod+H".action = expand-column-to-available-width;
"Mod+Minus".action.set-column-width = "-10%";
"Mod+Equal".action.set-column-width = "+10%";
"Mod+Shift+Minus".action.set-window-height = "-10%";
"Mod+Shift+Equal".action.set-window-height = "+10%";
"Ctrl+Alt+A".action = screenshot;
"Print".action.screenshot-screen = [ ];
"Alt+Print".action = screenshot-window;
"Mod+Shift+E".action = quit;
"Mod+O".action = toggle-overview;
"Super+Tab".action = toggle-overview;
}
// lib.attrsets.mergeAttrsList (
map (n: {
"Mod+${toString n}".action.focus-workspace = n;
"Mod+Shift+${toString n}".action.move-column-to-workspace = n;
}) (lib.range 0 9)
);
}; };
prefer-no-csd = true;
hotkey-overlay.skip-at-startup = true;
clipboard.disable-primary = true;
layer-rules = [
{
matches = [ { namespace = "^wallpaper$"; } ];
place-within-backdrop = true;
}
];
overview.workspace-shadow.enable = false;
window-rules = [
{
geometry-corner-radius = {
bottom-left = 14.;
bottom-right = 14.;
top-left = 14.;
top-right = 14.;
};
clip-to-geometry = true;
draw-border-with-background = false;
}
{
matches = [ { app-id = "kitty|foot|Alacritty|ghostty|chromium-browser|zen-beta|wofi"; } ];
opacity = 0.8;
}
{
matches = [ { app-id = "org.gnome.Nautilus|nemo"; } ];
opacity = 0.6;
}
];
environment = {
QT_QPA_PLATFORM = "wayland;xcb";
XDG_SESSION_TYPE = "wayland";
XDG_CURRENT_DESKTOP = "niri";
XDG_SESSION_DESKTOP = "niri";
QT_AUTO_SCREEN_SCALE_FACTOR = "1";
};
spawn-at-startup = map (c: { command = c; }) [
[ "${lib.getExe' pkgs.swaynotificationcenter "swaync"}" ]
[
"${lib.getExe pkgs.swaybg}"
"-m"
"fill"
"-i"
(toString ./wallpaper.png)
]
[
"wl-paste"
"--type"
"text"
"--watch"
"cliphist"
"store"
]
[
"wl-paste"
"--type"
"image"
"--watch"
"cliphist"
"store"
]
];
binds =
with config.my.home.lib.niri.actions;
{
"Ctrl+Alt+T".action.spawn = [
"kitty"
"-1"
];
"Mod+T".action.spawn = [
"kitty"
"-1"
];
"Mod+Return".action.spawn = [
"kitty"
"-1"
];
"Mod+G".action.spawn = [ "zen-beta" ];
"Mod+E".action.spawn = [ "nemo" ];
"Mod+R".action.spawn = [
"sh"
"-c"
"pkill wofi || wofi --color ~/.config/wal/colors"
];
"Mod+V".action.spawn = [
"sh"
"-c"
"pkill ${lib.getExe pkgs.wofi} || ${lib.getExe pkgs.cliphist} list | wofi --dmenu --color ~/.config/wal/colors | cliphist decode | wl-copy"
];
"XF86AudioRaiseVolume" = {
allow-when-locked = true;
action.spawn = [
"pamixer"
"-i"
"2"
];
};
"XF86AudioLowerVolume" = {
allow-when-locked = true;
action.spawn = [
"pamixer"
"-d"
"2"
];
};
"XF86AudioMute" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"play-pause"
];
};
"Mod+XF86AudioRaiseVolume" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"next"
];
};
"Mod+XF86AudioLowerVolume" = {
allow-when-locked = true;
action.spawn = [
"playerctl"
"-i"
"firefox,chromium,zen"
"previous"
];
};
"Mod+Q".action = close-window;
"Mod+Left".action = focus-column-left;
"Mod+Right".action = focus-column-right;
"Mod+Up".action = focus-window-up;
"Mod+Down".action = focus-window-down;
"Mod+Ctrl+Left".action = move-column-left;
"Mod+Ctrl+Right".action = move-column-right;
"Mod+Ctrl+Up".action = move-window-up;
"Mod+Ctrl+Down".action = move-window-down;
"Mod+Alt+Left".action = consume-or-expel-window-left;
"Mod+Alt+Right".action = consume-or-expel-window-right;
"Mod+Shift+Left".action = focus-monitor-left;
"Mod+Shift+Right".action = focus-monitor-right;
"Mod+Shift+Up".action = focus-monitor-up;
"Mod+Shift+Down".action = focus-monitor-down;
"Mod+Shift+Ctrl+Left".action = move-column-to-monitor-left;
"Mod+Shift+Ctrl+Right".action = move-column-to-monitor-right;
"Mod+Shift+Ctrl+Up".action = move-column-to-monitor-up;
"Mod+Shift+Ctrl+Down".action = move-column-to-monitor-down;
"Mod+Page_Up".action = focus-workspace-up;
"Mod+Page_Down".action = focus-workspace-down;
"Mod+Ctrl+Page_Up".action = move-column-to-workspace-up;
"Mod+Ctrl+Page_Down".action = move-column-to-workspace-down;
"Mod+Shift+Page_Up".action = move-workspace-up;
"Mod+Shift+Page_Down".action = move-workspace-down;
"Mod+L".action = switch-preset-column-width;
"Mod+Shift+L".action = reset-window-height;
"Mod+M".action = maximize-column;
"Mod+Shift+M".action = fullscreen-window;
"Mod+C".action = center-column;
"Mod+F".action = toggle-window-floating;
"Mod+H".action = expand-column-to-available-width;
"Mod+Minus".action.set-column-width = "-10%";
"Mod+Equal".action.set-column-width = "+10%";
"Mod+Shift+Minus".action.set-window-height = "-10%";
"Mod+Shift+Equal".action.set-window-height = "+10%";
"Ctrl+Alt+A".action = screenshot;
"Print".action.screenshot-screen = [ ];
"Alt+Print".action = screenshot-window;
"Mod+Shift+E".action = quit;
"Mod+O".action = toggle-overview;
"Super+Tab".action = toggle-overview;
}
// lib.attrsets.mergeAttrsList (
map (n: {
"Mod+${toString n}".action.focus-workspace = n;
"Mod+Shift+${toString n}".action.move-column-to-workspace = n;
}) (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
];
}