Merge pull request #31 from ryan4yin/modular

feat: refactoring configuration with `options` to make it more modular
This commit is contained in:
Ryan Yin
2023-12-23 21:36:09 +08:00
committed by GitHub
106 changed files with 289 additions and 279 deletions

View File

@@ -1,6 +1,3 @@
{...}: {
imports = [
./container.nix
./kubernetes.nix
];
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -1,16 +1,3 @@
{...}: {
imports = [
../server
./cloud
./container
./neovim
./terminal
./development.nix
./helix.nix
./media.nix
./shell.nix
./yazi.nix
];
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -11,7 +11,10 @@
{
xdg.configFile = {
# astronvim's config
"nvim".source = astronvim;
"nvim" = {
source = astronvim;
force = true;
};
# my custom astronvim config, astronvim will load it after base config
# https://github.com/AstroNvim/AstroNvim/blob/v3.32.0/lua/astronvim/bootstrap.lua#L15-L16

View File

@@ -1,7 +1,3 @@
{...}: {
imports = [
./alacritty.nix
./kitty.nix
./wezterm.nix
];
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -1,13 +1,3 @@
{...}: {
imports = [
./shells
./tmux
./zellij
./bat.nix
./btop.nix
./core.nix
./git.nix
./starship.nix
];
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -1,11 +1,8 @@
{username, ...}: {
imports = [
../base/desktop
../base/core.nix
./proxychains
./core.nix
./rime-squirrel.nix
./shell.nix
];
{mylib, ...}: {
imports =
(mylib.scanPaths ./.)
// [
../base/desktop
../base/core.nix
];
}

View File

@@ -1,6 +1,3 @@
{
imports = [
./shell.nix
./system-tools.nix
];
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -1,8 +1,4 @@
{
config,
nushell-scripts,
...
}: let
{config, ...}: let
d = config.xdg.dataHome;
c = config.xdg.configHome;
cache = config.xdg.cacheHome;

View File

@@ -1,10 +1,10 @@
{
imports = [
../base/server
../base/desktop
../base/core.nix
./base
./fcitx5
./desktop
];
}

View File

@@ -0,0 +1,3 @@
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -0,0 +1,30 @@
{
pkgs,
...
}: {
home.packages = with pkgs; [
# GUI apps
# e-book viewer(.epub/.mobi/...)
# do not support .pdf
foliate
# instant messaging
telegram-desktop
discord
qq # https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/networking/instant-messengers/qq
# remote desktop(rdp connect)
remmina
freerdp # required by remmina
# misc
flameshot
ventoy # multi-boot usb creator
];
# GitHub CLI tool
programs.gh = {
enable = true;
};
}

View File

@@ -1,38 +1,3 @@
{pkgs, ...}: {
imports = [
./wallpaper
./creative.nix
./gtk.nix
./immutable-file.nix
./media.nix
./ssh.nix
./xdg.nix
./eye-protection.nix
];
home.packages = with pkgs; [
# GUI apps
# e-book viewer(.epub/.mobi/...)
# do not support .pdf
foliate
# instant messaging
telegram-desktop
discord
qq # https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/networking/instant-messengers/qq
# remote desktop(rdp connect)
remmina
freerdp # required by remmina
# misc
flameshot
ventoy # multi-boot usb creator
];
# GitHub CLI tool
programs.gh = {
enable = true;
};
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -3,10 +3,6 @@
anyrun,
...
}: {
imports = [
anyrun.homeManagerModules.default
];
programs.anyrun = {
enable = true;
config = {

View File

@@ -0,0 +1,30 @@
{
pkgs,
config,
lib,
anyrun,
...
} @ args:
with lib; let
cfg = config.modules.desktop.hyprland;
in {
imports = [
anyrun.homeManagerModules.default
];
options.modules.desktop.hyprland = {
enable = mkEnableOption "hyprland compositor";
};
config = mkIf cfg.enable (
mkMerge
(map
(path: import path args)
[
./hyprland.nix
./packages.nix
./anyrun.nix
./wayland-apps.nix
])
);
}

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -1,16 +1,10 @@
{
lib,
pkgs,
lib,
hyprland,
nur-ryan4yin,
...
}: {
imports = [
./anyrun.nix
./wayland-apps.nix
./packages.nix
];
# NOTE:
# We have to enable hyprland/i3's systemd user service in home-manager,
# so that gammastep/wallpaper-switcher's user service can be start correctly!

View File

@@ -8,7 +8,7 @@
commandLineArgs = [
# make it use GTK_IM_MODULE if it runs with Gtk4, so fcitx5 can work with it.
# (only supported by chromium/chrome at this time, not electron)
"--gtk-version=5"
"--gtk-version=4"
"--enable-features=UseOzonePlatform"
"--ozone-platform=wayland"
# make it use text-input-v1, which works for kwin 5.27 and weston

View File

@@ -0,0 +1,24 @@
{
pkgs,
config,
lib,
...
} @ args:
with lib; let
cfg = config.modules.desktop.i3;
in {
options.modules.desktop.i3 = {
enable = mkEnableOption "i3 window manager";
};
config = mkIf cfg.enable (
mkMerge
(map
(path: import path args)
[
./i3.nix
./packages.nix
./x11-apps.nix
])
);
}

View File

@@ -1,11 +1,6 @@
_: {
# i3 window manager's config, based on https://github.com/endeavouros-team/endeavouros-i3wm-setup
imports = [
./packages.nix
./x11-apps.nix
];
# NOTE:
# We have to enable hyprland/i3's systemd user service in home-manager,
# so that gammastep/wallpaper-switcher's user service can be start correctly!
@@ -14,7 +9,7 @@ _: {
enable = true;
windowManager.i3 = {
enable = true;
extraConfig = builtins.readFile ./config;
extraConfig = builtins.readFile ./i3-config;
};
# Path, relative to HOME, where Home Manager should write the X session script.
# and NixOS will use it to start xorg session when system boot up

View File

@@ -1,6 +1,4 @@
{ lib, ... }:
rec {
{lib, ...}: {
# Generate an attribute set from a list.
#
# lib.genAttrs [ "foo" "bar" ] (name: "x_" + name)
@@ -8,7 +6,7 @@ rec {
listToAttrs = lib.genAttrs;
# Update only the values of the given attribute set.
#
#
# mapAttrs
# (name: value: ("bar-" + value))
# { x = "a"; y = "b"; }
@@ -16,7 +14,7 @@ rec {
mapAttrs = lib.attrsets.mapAttrs;
# Update both the names and values of the given attribute set.
#
#
# mapAttrs'
# (name: value: nameValuePair ("foo_" + name) ("bar-" + value))
# { x = "a"; y = "b"; }
@@ -24,6 +22,7 @@ rec {
mapAttrs' = lib.attrsets.mapAttrs';
# Merge a list of attribute sets into one. smilar to the operator `a // b`, but for a list of attribute sets.
# NOTE: the later attribute set overrides the former one!
#
# mergeAttrsList
# [ { x = "a"; y = "b"; } { x = "c"; z = "d"; } { g = "e"; } ]
@@ -31,7 +30,7 @@ rec {
mergeAttrsList = lib.attrsets.mergeAttrsList;
# Generate a string from an attribute set.
#
#
# attrsets.foldlAttrs
# (acc: name: value: acc + "\nexport ${name}=${value}")
# "# A shell script"

18
lib/default.nix Normal file
View File

@@ -0,0 +1,18 @@
{lib, ...}: {
colmenaSystem = import ./colmenaSystem.nix;
macosSystem = import ./macosSystem.nix;
nixosSystem = import ./nixosSystem.nix;
attrs = import ./attrs.nix {inherit lib;};
scanPaths = path:
builtins.map
(f: (path + "/${f}"))
(builtins.filter # find all overlay files in the current directory
(
f:
f
!= "default.nix" # ignore default.nix
&& f != "README.md" # ignore README.md
)
(builtins.attrNames (builtins.readDir path)));
}

View File

@@ -32,7 +32,4 @@
];
builders-use-substitutes = true;
};
# Allow unfree packages
nixpkgs.config.allowUnfree = lib.mkDefault false;
}

View File

@@ -0,0 +1,3 @@
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -11,7 +11,7 @@
###################################################################################
# to install chrome, you need to enable unfree packages
nixpkgs.config.allowUnfree = true;
nixpkgs.config.allowUnfree = lib.mkForce true;
# for nix server, we do not need to keep too much generations
boot.loader.systemd-boot.configurationLimit = lib.mkDefault 10;

103
modules/nixos/desktop.nix Normal file
View File

@@ -0,0 +1,103 @@
{
pkgs,
config,
lib,
username,
...
}:
with lib; let
cfgWayland = config.modules.desktop.wayland;
cfgXorg = config.modules.desktop.xorg;
in {
imports = [
./base
../base.nix
./desktop
];
options.modules.desktop = {
wayland = {
enable = mkEnableOption "Wayland Display Server";
};
xorg = {
enable = mkEnableOption "Xorg Display Server";
};
};
config = mkMerge [
(mkIf cfgWayland.enable {
####################################################################
# NixOS's Configuration for Wayland based Window Manager
####################################################################
xdg.portal = {
enable = true;
wlr.enable = true;
extraPortals = with pkgs; [
xdg-desktop-portal-wlr
];
};
services = {
xserver.enable = false; # disable xorg server
# https://wiki.archlinux.org/title/Greetd
greetd = {
enable = true;
settings = {
default_session = {
# Wayland Desktop Manager is installed only for user ryan via home-manager!
user = username;
# .wayland-session is a script generated by home-manager, which links to the current wayland compositor(sway/hyprland or others).
# with such a vendor-no-locking script, we can switch to another wayland compositor without modifying greetd's config here.
command = "$HOME/.wayland-session"; # start a wayland session directly without a login manager
# command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd $HOME/.wayland-session"; # start wayland session with a TUI login manager
};
};
};
};
# fix https://github.com/ryan4yin/nix-config/issues/10
security.pam.services.swaylock = {};
})
(mkIf cfgXorg.enable {
####################################################################
# NixOS's Configuration for Xorg Server
####################################################################
services = {
gvfs.enable = true; # Mount, trash, and other functionalities
tumbler.enable = true; # Thumbnail support for images
xserver = {
enable = true;
displayManager = {
lightdm.enable = true;
autoLogin = {
enable = true;
user = username;
};
# use a fake session to skip desktop manager
# and let Home Manager take care of the X session
defaultSession = "hm-session";
};
desktopManager = {
runXdgAutostartIfNone = true;
session = [
{
name = "hm-session";
manage = "window";
start = ''
${pkgs.runtimeShell} $HOME/.xsession &
waitPID=$!
'';
}
];
};
# Configure keymap in X11
xkb.layout = "us";
};
};
})
];
}

View File

@@ -1,12 +1,6 @@
{
imports = [
./base/i18n.nix
./base/misc.nix
./base/networking.nix
./base/remote-building.nix
./base/user-group.nix
./base/visualisation.nix
./base
../base.nix
];
}

View File

@@ -1,50 +0,0 @@
{pkgs, ...}: {
##########################################################################################################
#
# NixOS's Configuration for Wayland based Window Manager
#
# hyprland: project starts from 2022, support Wayland, envolving fast, good looking, support Nvidia GPU.
#
##########################################################################################################
imports = [
./base/i18n.nix
./base/misc.nix
./base/networking.nix
./base/remote-building.nix
./base/user-group.nix
./base/visualisation.nix
./desktop
../base.nix
];
xdg.portal = {
enable = true;
wlr.enable = true;
extraPortals = with pkgs; [
xdg-desktop-portal-wlr
];
};
services = {
xserver.enable = false; # disable xorg server
# https://wiki.archlinux.org/title/Greetd
greetd = {
enable = true;
settings = {
default_session = {
# Wayland Desktop Manager is installed only for user ryan via home-manager!
user = "ryan";
# .wayland-session is a script generated by home-manager, which links to the current wayland compositor(sway/hyprland or others).
# with such a vendor-no-locking script, we can switch to another wayland compositor without modifying greetd's config here.
command = "$HOME/.wayland-session"; # start a wayland session directly without a login manager
# command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd $HOME/.wayland-session"; # start wayland session with a TUI login manager
};
};
};
};
# fix https://github.com/ryan4yin/nix-config/issues/10
security.pam.services.swaylock = {};
}

Some files were not shown because too many files have changed in this diff Show More