feat: refactoring configuration with options to make it more modular

This commit is contained in:
Ryan Yin
2023-12-23 19:34:13 +08:00
parent 1f08d10ac7
commit b75b79057b
106 changed files with 289 additions and 279 deletions

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 = {};
}

View File

@@ -1,53 +0,0 @@
{pkgs, ...}: {
####################################################################
#
# NixOS's Configuration for Xorg Server
#
####################################################################
imports = [
./base/i18n.nix
./base/misc.nix
./base/networking.nix
./base/remote-building.nix
./base/user-group.nix
./base/visualisation.nix
./desktop
../base.nix
];
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 = "ryan";
};
# 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";
};
};
}