Unified home and system modules!

This commit is contained in:
marc
2022-11-19 11:58:21 +01:00
parent cfcc374a69
commit 890b05d352
45 changed files with 389 additions and 566 deletions

View File

@@ -0,0 +1,68 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.samfelag.modules.desktop;
laptopPkgs = with pkgs; [
];
in
{
options.samfelag.modules.desktop = {
enable = mkEnableOption "desktop environment";
laptop = mkOption {
description = "Enable features for a laptop (trackpad, battery, etc...)";
type = types.bool;
default = false;
};
};
config = mkIf cfg.enable {
# - Packages ---------------------------------
environment.systemPackages = with pkgs; [
pamixer
i3lock-blur
brightnessctl
playerctl
feh
rofi
firefox
] ++ optionals cfg.laptop laptopPkgs;
# - Audio ------------------------------------
sound.enable = true;
hardware = {
pulseaudio = {
enable = true;
support32Bit = true;
package = pkgs.pulseaudioFull;
};
};
# - Compositor -------------------------------
services.picom.enable = true;
# - Modules ----------------------------------
samfelag.modules = {
app.alacritty.enable = true;
desktop.polybar.enable = true;
desktop.i3 = {
enable = true;
laptop = cfg.laptop;
launcher.command = "${pkgs.rofi}/bin/rofi rofi -show run";
terminal.command = "${pkgs.alacritty}/bin/alacritty";
browser.command = "${pkgs.firefox}/bin/firefox";
locker.command = "${pkgs.i3lock-blur}/bin/i3lock-color -c 808F85 && sleep 1";
};
};
};
}

257
modules/desktop/i3.nix Normal file
View File

@@ -0,0 +1,257 @@
{ config, lib, pkgs, ... }:
let
cfg = config.samfelag.modules.desktop.i3;
mod = "Mod4";
cmdModule = lib.types.submodule ({ ... }: {
options = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
};
command = lib.mkOption {
type = lib.types.str;
example = "${pkgs.rofi}/bin/rofi rofi -show run";
};
};
});
system_mode = "System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown";
bg_colour = "#808F85";
paths = {
wallpapers = ../../data/wallpapers;
};
in {
options.samfelag.modules.desktop.i3 = {
enable = lib.mkEnableOption "i3 window manager";
laptop = lib.mkOption {
description = "Enable features for a laptop (trackpad, battery, etc...)";
type = lib.types.bool;
default = false;
};
launcher = lib.mkOption {
type = cmdModule;
};
terminal = lib.mkOption {
type = cmdModule;
};
browser = lib.mkOption {
type = cmdModule;
};
locker = lib.mkOption {
type = cmdModule;
};
};
config = lib.mkIf cfg.enable {
# - Dependencies -----------------------------
environment.systemPackages = with pkgs; [
(nerdfonts.override { fonts = [ "Iosevka" ]; })
];
hm.xdg.dataFile."wallpapers".source = paths.wallpapers;
services.xserver = {
enable = true;
libinput = lib.mkIf cfg.laptop {
enable = true;
touchpad.tapping = true;
};
desktopManager = {
xterm.enable = false;
};
displayManager = {
defaultSession = "none+i3";
lightdm = {
enable = true;
greeters.mini = {
enable = true;
user = "marc";
extraConfig = ''
[greeter]
show-sys-info = true
'';
};
};
};
windowManager.i3.enable = true;
};
# - Configuration ----------------------------
hm.xsession.windowManager.i3 = {
enable = true;
config = {
modifier = mod;
fonts = {
names = ["DejaVu Sans Mono" "Iosevka Nerd Font"];
style = "regular";
size = 12.0;
};
focus.followMouse = false;
bars = [ ];
window = {
border = 1;
titlebar = false;
};
# gaps = {
# inner = 10;
# outer = 5;
# };
startup = [
{ command = "i3-msg workspace 1"; }
{ command = "systemctl --user restart polybar"; always = true; notification = false; }
{ command = "feh --bg-center -B \"${bg_colour}\" -z --no-fehbg ${paths.wallpapers}/flors"; always = true; notification = false; }
];
modes = {
"resize" = {
"h" = "resize shrink width 10 px or 10 ppt";
"j" = "resize grow height 10 px or 10 ppt";
"k" = "resize shrink height 10 px or 10 ppt";
"l" = "resize grow width 10 px or 10 ppt";
"Left" = "resize shrink width 10 px or 10 ppt";
"Down" = "resize grow height 10 px or 10 ppt";
"Up" = "resize shrink height 10 px or 10 ppt";
"Right" = "resize grow width 10 px or 10 ppt";
"Return" = "mode \"default\"";
"Escape" = "mode \"default\"";
};
"${system_mode}" = {
"l" = "exec --no-startup-id ${cfg.locker.command}, mode \"default\"";
"e" = "exec --no-startup-id i3-msg exit, mode \"default\"";
"s" = "exec --no-startup-id ${cfg.locker.command} && systemctl suspend, mode \"default\"";
"h" = "exec --no-startup-id ${cfg.locker.command} && systemctl hibernate, mode \"default\"";
"r" = "exec --no-startup-id systemctl reboot, mode \"default\"";
"Shift+s" = "exec --no-startup-id systemctl poweroff -i, mode \"default\"";
"Return" = "mode \"default\"";
"Escape" = "mode \"default\"";
};
};
keybindings = {
"${mod}+q" = "kill";
# Focus
"${mod}+h" = "focus left";
"${mod}+j" = "focus down";
"${mod}+k" = "focus up";
"${mod}+l" = "focus right";
"${mod}+Left" = "focus left";
"${mod}+Down" = "focus down";
"${mod}+Up" = "focus up";
"${mod}+Right" = "focus right";
# Move
"${mod}+Shift+h" = "move left";
"${mod}+Shift+j" = "move down";
"${mod}+Shift+k" = "move up";
"${mod}+Shift+l" = "move right";
"${mod}+Shift+Left" = "move left";
"${mod}+Shift+Down" = "move down";
"${mod}+Shift+Up" = "move up";
"${mod}+Shift+Right" = "move right";
# split orientation
"${mod}+z" = "split h;exec notify-send 'tile horizontally'";
"${mod}+v" = "split v;exec notify-send 'tile vertically'";
# enter fullscreen mode for the focused container
"${mod}+f" = "fullscreen toggle";
# change container layout (stacked, tabbed, toggle split)
"${mod}+s" = "layout stacking";
"${mod}+w" = "layout tabbed";
"${mod}+e" = "layout toggle split";
# toggle tiling / floating
"${mod}+Shift+space" = "floating toggle";
# focus the parent container
"${mod}+a" = "focus parent";
# Reload config + restart i3
"${mod}+Shift+c" = "reload";
"${mod}+Shift+r" = "restart";
# - Modes ------------------------------
"${mod}+r" = "mode \"resize\"";
"${mod}+End" = "mode \"${system_mode}\"";
# - Media ------------------------------
# Pulse Audio controls
"XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5%";
"XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -5%";
"Shift+XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +1%";
"Shift+XF86AudioLowerVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -1%";
"XF86AudioMute" = "exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle";
# Media player controls
"XF86AudioPlay" = "exec playerctl play-pause";
"XF86AudioPause" = "exec playerctl play-pause";
"XF86AudioNext" = "exec playerctl next";
"XF86AudioPrev" = "exec playerctl previous";
"XF86AudioStop" = "exec playerctl stop";
# - Workspaces -------------------------
"${mod}+1" = "workspace 1";
"${mod}+2" = "workspace 2";
"${mod}+3" = "workspace 3";
"${mod}+4" = "workspace 4";
"${mod}+5" = "workspace 5";
"${mod}+6" = "workspace 6";
"${mod}+7" = "workspace 7";
"${mod}+8" = "workspace 8";
"${mod}+9" = "workspace 9";
"${mod}+0" = "workspace 10";
"${mod}+Shift+1" = "move container to workspace 1; workspace 1";
"${mod}+Shift+2" = "move container to workspace 2; workspace 2";
"${mod}+Shift+3" = "move container to workspace 3; workspace 3";
"${mod}+Shift+4" = "move container to workspace 4; workspace 4";
"${mod}+Shift+5" = "move container to workspace 5; workspace 5";
"${mod}+Shift+6" = "move container to workspace 6; workspace 6";
"${mod}+Shift+7" = "move container to workspace 7; workspace 7";
"${mod}+Shift+8" = "move container to workspace 8; workspace 8";
"${mod}+Shift+9" = "move container to workspace 9; workspace 9";
"${mod}+Shift+0" = "move container to workspace 10; workspace 10";
}
// (if cfg.terminal.enable then {
"${mod}+Return" = "exec ${cfg.terminal.command}";
} else {})
// (if cfg.launcher.enable then {
"${mod}+space" = "exec ${cfg.launcher.command}";
} else {})
// (if cfg.browser.enable then {
"${mod}+Control+3" = "exec ${cfg.browser.command}";
} else {});
};
};
};
}

View File

@@ -0,0 +1,56 @@
{ config, lib, pkgs, ... }:
let
cfg = config.samfelag.modules.desktop.polybar;
polybar_pkg = pkgs.polybar.override {
i3Support = true;
pulseSupport = true;
};
script = ''
polybar top &
polybar bottom &
'';
# Paths
paths = {
config = ../../config/.config/polybar/config.ini;
bars = ../../config/.config/polybar/bars;
scripts = ../../config/.config/polybar/scripts;
};
in {
options.samfelag.modules.desktop.polybar = {
enable = lib.mkEnableOption "polybar";
};
config = lib.mkIf cfg.enable {
# - Configuration ----------------------------
environment.systemPackages = [
polybar_pkg
];
hm.xdg.configFile."polybar/config.ini".source = paths.config;
hm.xdg.configFile."polybar/bars".source = paths.bars;
hm.xdg.configFile."polybar/scripts".source = paths.scripts;
hm.systemd.user.services.polybar = {
Unit = {
Description = "Polybar status bar";
PartOf = [ "tray.target" ];
X-Restart-Triggers = [ "${paths.config}" ];
};
Service = {
Type = "forking";
PassEnvironment = "PATH";
ExecStart =
let scriptPkg = pkgs.writeShellScriptBin "polybar-start" script;
in "${scriptPkg}/bin/polybar-start";
Restart = "on-failure";
};
Install = { WantedBy = [ "tray.target" ]; };
};
};
}