Skip to content

Commit

Permalink
Merge pull request #33 from ryan4yin/modular-home
Browse files Browse the repository at this point in the history
feat: Modular home
  • Loading branch information
ryan4yin authored Dec 24, 2023
2 parents 2d44bc6 + 647f56d commit 1d6ffd7
Show file tree
Hide file tree
Showing 90 changed files with 285 additions and 194 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ i3:
nixos-rebuild switch --flake .#ai_i3 --use-remote-sudo

s-i3:
nixos-rebuild switch --flake .#shoekei_i3 --use-remote-sudo
nixos-rebuild switch --flake .#shoukei_i3 --use-remote-sudo

hypr:
nixos-rebuild switch --flake .#ai_hyprland --use-remote-sudo
Expand Down
4 changes: 2 additions & 2 deletions home/base/desktop/neovim/astronvim_user/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ return {
{ import = "astrocommunity.colorscheme.catppuccin" },
-- Highly experimental plugin that completely replaces
-- the UI for messages, cmdline and the popupmenu.
{ import = "astrocommunity.utility.noice-nvim" },
-- { import = "astrocommunity.utility.noice-nvim" },
-- Fully featured & enhanced replacement for copilot.vim
-- <Tab> work with both auto completion in cmp and copilot
{ import = "astrocommunity.media.vim-wakatime" },
Expand Down Expand Up @@ -77,7 +77,7 @@ return {
-- lazy-loading on events
event = { "InsertLeave", "TextChanged" },
opts = function(_, opts)
opts.prompt_style = "notify" -- or stdout
opts.prompt_style = "stdout" -- notify or stdout
end,
},

Expand Down
7 changes: 4 additions & 3 deletions home/base/desktop/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
vimAlias = true;

# currently we use lazy.nvim as neovim's package manager, so comment this one.
# plugins = with pkgs.vimPlugins; [
# # search all the plugins using https://search.nixos.org/packages
# ];
plugins = with pkgs.vimPlugins; [
# search all the plugins using https://search.nixos.org/packages
telescope-fzf-native-nvim
];

# Extra packages only available to nvim(won't pollute the global home environment)
extraPackages = with pkgs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{pkgs, ...}: {
_: {
programs.ssh = {
enable = true;

Expand All @@ -23,13 +23,6 @@
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host github.com
# github is controlled by gluttony~
IdentityFile ~/.ssh/gluttony
# Specifies that ssh should only use the identity file explicitly configured above
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host gtr5
HostName 192.168.5.172
Port 22
Expand Down
34 changes: 0 additions & 34 deletions home/darwin/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,4 @@
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
'';
};

programs.ssh = {
enable = true;

# all my ssh private key are generated by `ssh-keygen -t ed25519 -C "ryan@nickname"`
# the config's format:
# Host — given the pattern used to match against the host name given on the command line.
# HostName — specify nickname or abbreviation for host
# IdentityFile — the location of your SSH key authentication file for the account.
# format in details:
# https://www.ssh.com/academy/ssh/config
extraConfig = ''
# a private key that is used during authentication will be added to ssh-agent if it is running
AddKeysToAgent yes
Host 192.168.*
# allow to securely use local SSH agent to authenticate on the remote machine.
# It has the same effect as adding cli option `ssh -A user@host`
ForwardAgent yes
# romantic holds my homelab~
IdentityFile ~/.ssh/romantic
# Specifies that ssh should only use the identity file explicitly configured above
# required to prevent sending default identity files first.
IdentitiesOnly yes
Host github.com
Hostname github.com
# github is controlled by gluttony~
IdentityFile ~/.ssh/harmonica
# Specifies that ssh should only use the identity file explicitly configured above
# required to prevent sending default identity files first.
IdentitiesOnly yes
'';
};
}
6 changes: 2 additions & 4 deletions home/linux/base/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ in rec {

home.homeDirectory = "/home/${username}";

# add environment variables
systemd.user.sessionVariables = {
# environment variables that always set at login
home.sessionVariables = {
# clean up ~
LESSHISTFILE = cache + "/less/history";
LESSKEY = c + "/less/lesskey";
Expand All @@ -25,6 +25,4 @@ in rec {
# enable scrolling in git diff
DELTA_PAGER = "less -R";
};

home.sessionVariables = systemd.user.sessionVariables;
}
2 changes: 1 addition & 1 deletion home/linux/desktop/base/gtk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
gtk.enable = true;
x11.enable = true;
package = pkgs.bibata-cursors;
name = "Bibata-Modern-Classic";
name = "Bibata-Modern-Ice";
size = 24;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
## Hyprland configuration file

# color-scheme: cappuccin-mocha
source=~/.config/hypr/themes/mocha.conf

env = _JAVA_AWT_WM_NONREPARENTING,1
env = QT_WAYLAND_DISABLE_WINDOWDECORATION,1
# fix https://github.com/hyprwm/Hyprland/issues/1520
env = WLR_NO_HARDWARE_CURSORS,1

#-- Output ----------------------------------------------------
# Configure your Display resolution, offset, scale and Monitors here, use `hyprctl monitors` to get the info.

# format:
# monitor=name,resolution,position,scale
monitor=DP-2,3840x2160@144,0x0,1.6
workspace=DP-2,1

#-- Input ----------------------------------------------------
# Configure mouse and touchpad here.
input {
Expand Down Expand Up @@ -199,10 +181,9 @@ bind=SUPER,mouse_up,workspace,e-1
#-- Startup ----------------------------------------------------
exec-once=~/.config/hypr/scripts/startup


#-- Fcitx5 input method ----------------------------------------------------
# -- Fcitx5 input method
windowrule=pseudo,fcitx # enable this will make fcitx5 works, but fcitx5-configtool will not work!
exec-once=cp ~/.config/fcitx5/profile-bak ~/.config/fcitx5/profile # restore fcitx5 profile manged by nixos
exec-once=cp ~/.config/fcitx5/profile-bak ~/.config/fcitx5/profile # restore fcitx5 profile managed by nixos
exec-once=fcitx5 -d --replace # start fcitx5 daemon
bind=ALT,E,exec,pkill fcitx5 -9;sleep 1;fcitx5 -d --replace; sleep 1;fcitx5-remote -r

Expand All @@ -211,22 +192,3 @@ windowrulev2 = rounding 0, xwayland:1, floating:1
windowrulev2 = center, class:^(.*jetbrains.*)$, title:^(Confirm Exit|Open Project|win424|win201|splash)$
windowrulev2 = size 640 400, class:^(.*jetbrains.*)$, title:^(splash)$

# -- Fix input method in vscode
exec-once = hyprctl setcursor "Bibata-Modern-Ice" 24
# 效果是 wayland 原生窗口缩放完全正常
# xwayland 窗口先渲染到 200% 再降到 hyprland config 里 monitor 设置的值,看上去和原生没啥区别
# 相比较一开始的方案输入法字体大小也正确了.唯一有点问题的可能是 xwayland 窗口下的鼠标指针大小不对
exec-once = xprop -root -f _XWAYLAND_GLOBAL_OUTPUT_SCALE 32c -set _XWAYLAND_GLOBAL_OUTPUT_SCALE 2

-- Fix HiDPI - xwayland
# change monitor to high resolution, the last argument is the scale factor
monitor=,highres,auto,2

# unscale XWayland
xwayland {
force_zero_scaling = true
}

# toolkit-specific scale
env = GDK_SCALE,2
env = XCURSOR_SIZE,32
File renamed without changes.
35 changes: 26 additions & 9 deletions home/linux/desktop/hyprland/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,38 @@ with lib; let
in {
imports = [
anyrun.homeManagerModules.default
./options
];

options.modules.desktop.hyprland = {
enable = mkEnableOption "hyprland compositor";
settings = lib.mkOption {
type = with lib.types; let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "Hyprland configuration value";
};
in
valueType;
default = {};
};
};

config = mkIf cfg.enable (
mkMerge
(map
(path: import path args)
[
./hyprland.nix
./packages.nix
./anyrun.nix
./wayland-apps.nix
])
mkMerge ([
{
wayland.windowManager.hyprland.settings = cfg.settings;
}
]
++ (import ./values args))
);
}
3 changes: 3 additions & 0 deletions home/linux/desktop/hyprland/options/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}
24 changes: 24 additions & 0 deletions home/linux/desktop/hyprland/options/nvidia.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
config,
lib,
...
}:
with lib; let
cfg = config.modules.desktop.hyprland;
in {
options.modules.desktop.hyprland = {
nvidia = mkEnableOption "whether nvidia GPU is used";
};

config = mkIf (cfg.enable && cfg.nvidia) {
wayland.windowManager.hyprland.settings.env = [
# for hyprland with nvidia gpu, ref https://wiki.hyprland.org/Nvidia/
"LIBVA_DRIVER_NAME,nvidia"
"XDG_SESSION_TYPE,wayland"
"GBM_BACKEND,nvidia-drm"
"__GLX_VENDOR_LIBRARY_NAME,nvidia"
# fix https://github.com/hyprwm/Hyprland/issues/1520
"WLR_NO_HARDWARE_CURSORS,1"
];
};
}
File renamed without changes.
4 changes: 4 additions & 0 deletions home/linux/desktop/hyprland/values/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{mylib, ...} @ args:
map
(path: import path args)
(mylib.scanPaths ./.)
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@
# they are all depending on hyprland/i3's user graphical-session
wayland.windowManager.hyprland = {
enable = true;
settings = {
source = "${nur-ryan4yin.packages.${pkgs.system}.catppuccin-hyprland}/themes/mocha.conf";
env = [
"NIXOS_OZONE_WL,1" # for any ozone-based browser & electron apps to run on wayland
"MOZ_ENABLE_WAYLAND,1" # for firefox to run on wayland
"MOZ_WEBRENDER,1"
# misc
"_JAVA_AWT_WM_NONREPARENTING,1"
"QT_WAYLAND_DISABLE_WINDOWDECORATION,1"
];
};
package = hyprland.packages.${pkgs.system}.hyprland;
settings = lib.mkForce {};
extraConfig = builtins.readFile ./hypr-conf/hyprland.conf;
extraConfig = builtins.readFile ../conf/hyprland.conf;
# gammastep/wallpaper-switcher need this to be enabled.
systemd.enable = true;
};
Expand All @@ -28,47 +38,29 @@
# hyprland configs, based on https://github.com/notwidow/hyprland
xdg.configFile = {
"hypr/mako" = {
source = ./hypr-conf/mako;
source = ../conf/mako;
recursive = true;
};
"hypr/scripts" = {
source = ./hypr-conf/scripts;
source = ../conf/scripts;
recursive = true;
};
"hypr/waybar" = {
source = ./hypr-conf/waybar;
source = ../conf/waybar;
recursive = true;
};
"hypr/wlogout" = {
source = ./hypr-conf/wlogout;
recursive = true;
};
"hypr/themes" = {
source = "${nur-ryan4yin.packages.${pkgs.system}.catppuccin-hyprland}/themes";
source = ../conf/wlogout;
recursive = true;
};

# music player - mpd
"mpd" = {
source = ./mpd;
source = ../conf/mpd;
recursive = true;
};
};

# allow fontconfig to discover fonts and configurations installed through home.packages
fonts.fontconfig.enable = true;

systemd.user.sessionVariables = {
"NIXOS_OZONE_WL" = "1"; # for any ozone-based browser & electron apps to run on wayland
"MOZ_ENABLE_WAYLAND" = "1"; # for firefox to run on wayland
"MOZ_WEBRENDER" = "1";

# for hyprland with nvidia gpu, ref https://wiki.hyprland.org/Nvidia/
"LIBVA_DRIVER_NAME" = "nvidia";
"XDG_SESSION_TYPE" = "wayland";
"GBM_BACKEND" = "nvidia-drm";
"__GLX_VENDOR_LIBRARY_NAME" = "nvidia";
"WLR_NO_HARDWARE_CURSORS" = "1";
"WLR_EGL_NO_MODIFIRES" = "1";
};
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 5 additions & 8 deletions home/linux/desktop/i3/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
with lib; let
cfg = config.modules.desktop.i3;
in {
imports = [
./options
];

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
])
mkMerge (import ./values args)
);
}
3 changes: 3 additions & 0 deletions home/linux/desktop/i3/options/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}
27 changes: 27 additions & 0 deletions home/linux/desktop/i3/options/nvidia.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
config,
lib,
...
}:
with lib; let
cfg = config.modules.desktop.i3;
in {
options.modules.desktop.i3 = {
nvidia = mkEnableOption "whether nvidia GPU is used";
};

config = mkIf (cfg.enable && cfg.nvidia) (
let
env = {
"LIBVA_DRIVER_NAME" = "nvidia";
"GBM_BACKEND" = "nvidia-drm";
"__GLX_VENDOR_LIBRARY_NAME" = "nvidia";
};
in {
# environment set for systemd's user session
systemd.user.sessionVariables = env;
# environment set at user login
home.sessionVariables = env;
}
);
}
Loading

0 comments on commit 1d6ffd7

Please sign in to comment.