From 66e3a03d7d40b85c18b6ceecdd69838657166da1 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 1 Dec 2023 14:12:33 -0500 Subject: [PATCH] feat(vars): add hostName and big refactors --- common/default.nix | 16 +++++-------- common/home/bash/programs.nix | 6 ++++- common/modules/locate.nix | 35 +++++++++++++--------------- common/overlays/default.nix | 6 ++++- common/{device-vars.nix => vars.nix} | 26 +++++++++++++++------ devices/binto/default.nix | 32 ++++++++++++------------- devices/binto/modules/desktop.nix | 13 ++++++++--- devices/oksys/default.nix | 21 ++++++++--------- devices/oksys/modules/caddy.nix | 4 +--- devices/oksys/modules/headscale.nix | 3 +-- devices/oksys/modules/unbound.nix | 6 ++--- devices/wim/default.nix | 34 +++++++++++++-------------- devices/wim/home/dotfiles.nix | 4 ++-- devices/wim/modules/desktop.nix | 11 +++++++-- home/alacritty.nix | 2 +- home/hyprland/default.nix | 21 ++++++++++------- home/hyprland/theme.nix | 7 +++--- modules/ags/default.nix | 5 ++-- modules/greetd/default.nix | 18 +++++++++----- modules/tailscale.nix | 6 ++--- 20 files changed, 150 insertions(+), 126 deletions(-) rename common/{device-vars.nix => vars.nix} (65%) diff --git a/common/default.nix b/common/default.nix index 0da761f..873c497 100644 --- a/common/default.nix +++ b/common/default.nix @@ -3,14 +3,14 @@ lib, nixpkgs, nh, - nur, nix-melt, + nur, nurl, pkgs, ... }: { imports = [ - ./device-vars.nix + ./vars.nix ./modules ./overlays @@ -56,22 +56,18 @@ layout = "ca"; xkbVariant = "multix"; }; - }; home-manager.users = let - user = config.services.device-vars.username; - default = { imports = [ nur.hmModules.nur ./home - ./device-vars.nix - ({osConfig, ...}: { - services.device-vars = osConfig.services.device-vars; - }) + # Make the vars be the same on Nix and HM + ./vars.nix + ({osConfig, ...}: {vars = osConfig.vars;}) ]; home.packages = @@ -102,6 +98,6 @@ in { root = default; # TODO: make user an array? - ${user} = default; + ${config.vars.user} = default; }; } diff --git a/common/home/bash/programs.nix b/common/home/bash/programs.nix index e6afd37..14c6f4d 100644 --- a/common/home/bash/programs.nix +++ b/common/home/bash/programs.nix @@ -1,4 +1,8 @@ -{pkgs, config, ...}: { +{ + pkgs, + config, + ... +}: { programs = { fzf = { enable = true; diff --git a/common/modules/locate.nix b/common/modules/locate.nix index 3c8a6ad..c28bdb0 100644 --- a/common/modules/locate.nix +++ b/common/modules/locate.nix @@ -4,30 +4,31 @@ lib, ... }: let - vars = config.services.device-vars; - locateGroup = lib.getName config.services.locate.package.name; + cfg = config.services.locate; - locate = "${config.services.locate.package}/bin/locate"; - updatedb = "${config.services.locate.package}/bin/updatedb"; + locateGroup = lib.getName cfg.package.name; + + locate = "${cfg.package}/bin/locate"; + updatedb = "${cfg.package}/bin/updatedb"; database = "/var/lib/locate/locatedb"; - pruneFS = builtins.concatStringsSep " " config.services.locate.pruneFS; - pruneNames = builtins.concatStringsSep " " config.services.locate.pruneNames; - prunePaths = builtins.concatStringsSep " " config.services.locate.prunePaths; + pruneFS = builtins.concatStringsSep " " cfg.pruneFS; + pruneNames = builtins.concatStringsSep " " cfg.pruneNames; + prunePaths = builtins.concatStringsSep " " cfg.prunePaths; updatedbBin = '' ${updatedb} -o ${database} --prunefs "${pruneFS}" \ --prunepaths "${prunePaths}" --prunenames "${pruneNames}" ''; in { - users.users.${vars.username}.extraGroups = [ + users.users.${config.vars.user}.extraGroups = [ locateGroup ]; systemd.services.locate = { wantedBy = ["default.target"]; serviceConfig = { - User = vars.username; + User = config.vars.user; Group = locateGroup; StateDirectory = "locate"; StateDirectoryMode = "0770"; @@ -35,17 +36,13 @@ in { }; }; - home-manager.users.${vars.username}.imports = [ - { - programs.bash.shellAliases = { - locate = "${pkgs.writeShellScriptBin "lct" '' - exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb") - ''}/bin/lct"; + home-manager.users.${config.vars.user}.programs.bash.shellAliases = { + locate = "${pkgs.writeShellScriptBin "lct" '' + exec ${locate} -d ${database} "$@" 2> >(grep -v "/var/cache/locatedb") + ''}/bin/lct"; - updatedb = updatedbBin; - }; - } - ]; + updatedb = updatedbBin; + }; services.locate = { enable = true; diff --git a/common/overlays/default.nix b/common/overlays/default.nix index d1a76df..c2ea4a0 100644 --- a/common/overlays/default.nix +++ b/common/overlays/default.nix @@ -1,4 +1,8 @@ -{neovim-flake, nixpkgs-wayland, ...}: { +{ + neovim-flake, + nixpkgs-wayland, + ... +}: { imports = [ ./dracula-theme ./regreet diff --git a/common/device-vars.nix b/common/vars.nix similarity index 65% rename from common/device-vars.nix rename to common/vars.nix index 5a20d69..edc72d8 100644 --- a/common/device-vars.nix +++ b/common/vars.nix @@ -1,33 +1,45 @@ -{lib, ...}: { - options.services.device-vars = with lib; { - username = mkOption { +{ + config, + lib, + ... +}: { + options.vars = with lib; { + user = mkOption { + type = types.str; description = '' Username that was defined at the initial setup process ''; - type = types.nullOr types.str; + }; + + hostName = mkOption { + type = types.str; + description = '' + Hostname that was defined at the initial setup process + ''; }; configDir = mkOption { + type = types.str; + default = "/home/${config.vars.user}/.nix/devices/${config.vars.hostName}/config"; description = '' The path to where most of the devices' configs are in the .nix folder ''; - type = types.nullOr types.str; }; mainMonitor = mkOption { + type = types.nullOr types.str; description = '' The name of the main monitor used for Hyprland and Regreet ''; default = "null"; - type = types.nullOr types.str; }; greetdDupe = mkOption { + type = types.nullOr types.bool; description = '' If we should duplicate regreet on all monitors ''; default = true; - type = types.nullOr types.bool; }; fontSize = mkOption { diff --git a/devices/binto/default.nix b/devices/binto/default.nix index 30da64d..b38cf50 100644 --- a/devices/binto/default.nix +++ b/devices/binto/default.nix @@ -1,4 +1,4 @@ -{...}: { +{config, ...}: { imports = [ ./hardware-configuration.nix @@ -16,15 +16,15 @@ ./modules/nvidia.nix ]; - services.device-vars = { - username = "matt"; - configDir = "/home/matt/.nix/devices/binto/config"; + vars = { + user = "matt"; + hostName = "binto"; mainMonitor = "DP-5"; greetdDupe = false; fontSize = 12.5; }; - users.users.matt = { + users.users.${config.vars.user} = { isNormalUser = true; extraGroups = [ "wheel" @@ -35,23 +35,21 @@ "libvirtd" ]; }; - home-manager.users = { - matt = { - imports = [ - ../../home/dconf.nix - ../../home/firefox - ../../home/hyprland + home-manager.users.${config.vars.user} = { + imports = [ + ../../home/dconf.nix + ../../home/firefox + ../../home/hyprland - ./home/packages.nix - ]; + ./home/packages.nix + ]; - # No touchy - home.stateVersion = "23.11"; - }; + # No touchy + home.stateVersion = "23.11"; }; networking = { - hostName = "binto"; + inherit (config.vars) hostName; networkmanager.enable = true; firewall.enable = false; }; diff --git a/devices/binto/modules/desktop.nix b/devices/binto/modules/desktop.nix index c547bfd..465c1a1 100644 --- a/devices/binto/modules/desktop.nix +++ b/devices/binto/modules/desktop.nix @@ -3,8 +3,15 @@ config, ... }: let - user = config.services.device-vars.username; - hyprland = config.home-manager.users.${user}.wayland.windowManager.hyprland.finalPackage; + hyprland = + config + .home-manager + .users + .${config.vars.user} + .wayland + .windowManager + .hyprland + .finalPackage; in { programs.dconf.enable = true; @@ -21,7 +28,7 @@ in { settings = { initial_session = { command = "${hyprland}/bin/Hyprland"; - user = user; + user = config.vars.user; }; }; }; diff --git a/devices/oksys/default.nix b/devices/oksys/default.nix index da2d7e2..397d9d5 100644 --- a/devices/oksys/default.nix +++ b/devices/oksys/default.nix @@ -1,4 +1,4 @@ -{...}: { +{config, ...}: { imports = [ #./hardware-configuration.nix @@ -7,29 +7,28 @@ ./modules/headscale.nix ]; - services.device-vars = { - username = "matt"; + vars = { + user = "matt"; + hostName = "oksys"; }; - users.users.matt = { + users.users.${config.vars.user} = { isNormalUser = true; extraGroups = [ "wheel" "adm" ]; }; - home-manager.users = { - matt = { - imports = []; + home-manager.users.${config.vars.user} = { + imports = []; - # No touchy - home.stateVersion = "24.05"; - }; + # No touchy + home.stateVersion = "24.05"; }; networking = { - hostName = "oksys"; networkmanager = { + inherit (config.vars) hostName; enable = true; wifi.backend = "wpa_supplicant"; }; diff --git a/devices/oksys/modules/caddy.nix b/devices/oksys/modules/caddy.nix index eb11ed8..c6c7d01 100644 --- a/devices/oksys/modules/caddy.nix +++ b/devices/oksys/modules/caddy.nix @@ -4,8 +4,6 @@ config, ... }: let - user = config.services.device-vars.username; - caddy = caddy-plugins.packages.${pkgs.system}.default; # TODO: use agenix? @@ -13,7 +11,7 @@ in { imports = [caddy-plugins.nixosModules.default]; environment.systemPackages = [caddy]; - users.users.${user}.extraGroups = ["caddy"]; + users.users.${config.vars.user}.extraGroups = ["caddy"]; services.caddy = { enable = true; diff --git a/devices/oksys/modules/headscale.nix b/devices/oksys/modules/headscale.nix index 9e721df..5ce30fe 100644 --- a/devices/oksys/modules/headscale.nix +++ b/devices/oksys/modules/headscale.nix @@ -5,10 +5,9 @@ ... }: let headscale-flake = headscale.packages.${pkgs.system}.headscale; - user = config.services.device-vars.username; in { environment.systemPackages = [headscale-flake]; - users.users.${user}.extraGroups = ["headscale"]; + users.users.${config.vars.user}.extraGroups = ["headscale"]; services.headscale = { enable = true; diff --git a/devices/oksys/modules/unbound.nix b/devices/oksys/modules/unbound.nix index 4684d5a..53e46c1 100644 --- a/devices/oksys/modules/unbound.nix +++ b/devices/oksys/modules/unbound.nix @@ -1,10 +1,8 @@ -{config, ...}: let - user = config.services.device-vars.username; -in { +{config, ...}: { # https://github.com/MatthewVance/unbound-docker-rpi/issues/4#issuecomment-1001879602 boot.kernel.sysctl."net.core.rmem_max" = 1048576; - users.users.${user}.extraGroups = ["unbound"]; + users.users.${config.vars.user}.extraGroups = ["unbound"]; services.unbound = { enable = true; diff --git a/devices/wim/default.nix b/devices/wim/default.nix index 9208088..713a828 100644 --- a/devices/wim/default.nix +++ b/devices/wim/default.nix @@ -1,4 +1,4 @@ -{...}: { +{config, ...}: { imports = [ ./hardware-configuration.nix @@ -15,13 +15,13 @@ ./modules/security.nix ]; - services.device-vars = { - username = "matt"; - configDir = "/home/matt/.nix/devices/wim/config"; + vars = { + user = "matt"; + hostName = "wim"; fontSize = 12.5; }; - users.users.matt = { + users.users.${config.vars.user} = { isNormalUser = true; extraGroups = [ "wheel" @@ -32,24 +32,22 @@ "libvirtd" ]; }; - home-manager.users = { - matt = { - imports = [ - ../../home/dconf.nix - ../../home/firefox - ../../home/hyprland + home-manager.users .${config.vars.user} = { + imports = [ + ../../home/dconf.nix + ../../home/firefox + ../../home/hyprland - ./home/dotfiles.nix - ./home/packages.nix - ]; + ./home/dotfiles.nix + ./home/packages.nix + ]; - # No touchy - home.stateVersion = "23.05"; - }; + # No touchy + home.stateVersion = "23.05"; }; networking = { - hostName = "wim"; + inherit (config.vars) hostName; networkmanager = { enable = true; wifi.backend = "wpa_supplicant"; diff --git a/devices/wim/home/dotfiles.nix b/devices/wim/home/dotfiles.nix index 62f19a6..848fc2c 100644 --- a/devices/wim/home/dotfiles.nix +++ b/devices/wim/home/dotfiles.nix @@ -3,7 +3,7 @@ pkgs, ... }: let - configDir = config.services.device-vars.configDir; + configDir = config.vars.configDir; symlink = config.lib.file.mkOutOfStoreSymlink; in { wayland.windowManager.hyprland = { @@ -17,7 +17,7 @@ in { }; xdg.configFile = { - "gtklock/config.ini".text = '' + "gtklock/config.ini".text = '' [main] modules=${builtins.concatStringsSep ";" [ "${pkgs.gtklock-powerbar-module}/lib/gtklock/powerbar-module.so" diff --git a/devices/wim/modules/desktop.nix b/devices/wim/modules/desktop.nix index 2776518..fabc922 100644 --- a/devices/wim/modules/desktop.nix +++ b/devices/wim/modules/desktop.nix @@ -3,8 +3,15 @@ config, ... }: let - user = config.services.device-vars.username; - hyprland = config.home-manager.users.${user}.wayland.windowManager.hyprland.finalPackage; + hyprland = + config + .home-manager + .users + .${config.vars.user} + .wayland + .windowManager + .hyprland + .finalPackage; in { programs.dconf.enable = true; diff --git a/home/alacritty.nix b/home/alacritty.nix index fbd6ac9..b42622f 100644 --- a/home/alacritty.nix +++ b/home/alacritty.nix @@ -39,7 +39,7 @@ family = "JetBrainsMono Nerd Font"; style = "Italic"; }; - size = config.services.device-vars.fontSize; + size = config.vars.fontSize; }; # https://github.com/dracula/alacritty/blob/05faff15c0158712be87d200081633d9f4850a7d/dracula.yml diff --git a/home/hyprland/default.nix b/home/hyprland/default.nix index 97b097e..b136d06 100644 --- a/home/hyprland/default.nix +++ b/home/hyprland/default.nix @@ -7,11 +7,15 @@ lib, ... }: let - configDir = config.services.device-vars.configDir; + # Nix utils symlink = config.lib.file.mkOutOfStoreSymlink; optionals = lib.lists.optionals; + + # Config stuff isNvidia = osConfig.hardware.nvidia.modesetting.enable; isTouchscreen = osConfig.hardware.sensor.iio.enable; + confPath = "${config.vars.configDir}/hypr/main.conf"; + kdeconnect = osConfig.programs.kdeconnect; gset = pkgs.gsettings-desktop-schemas; polkit = pkgs.plasma5Packages.polkit-kde-agent; @@ -22,9 +26,10 @@ in { ../wofi ]; - xdg.configFile = lib.mkIf (configDir != null) { - "hypr/main.conf".source = symlink "${configDir}/hypr/main.conf"; - }; + xdg.configFile = with lib; + mkIf (pathExists confPath) { + "hypr/main.conf".source = symlink confPath; + }; wayland.windowManager.hyprland = { enable = true; @@ -32,7 +37,7 @@ in { plugins = [] - ++ (optionals (isTouchscreen) [ + ++ (optionals isTouchscreen [ hyprgrass.packages.${pkgs.system}.default ]); @@ -93,8 +98,8 @@ in { "swww init --no-cache && swww img -t none ${pkgs.dracula-theme}/wallpapers/waves.png" "wl-paste --watch cliphist store" ] - ++ (optionals (osConfig.programs.kdeconnect.enable) [ - "${osConfig.programs.kdeconnect.package}/libexec/kdeconnectd" + ++ (optionals (kdeconnect.enable) [ + "${kdeconnect.package}/libexec/kdeconnectd" "kdeconnect-indicator" ]) ++ (optionals (osConfig.services.gnome.gnome-keyring.enable) [ @@ -179,7 +184,7 @@ in { source = [] - ++ optionals (configDir != null) [ + ++ optionals (lib.pathExists confPath) [ "~/.config/hypr/main.conf" ]; }; diff --git a/home/hyprland/theme.nix b/home/hyprland/theme.nix index 47af092..dc4d261 100644 --- a/home/hyprland/theme.nix +++ b/home/hyprland/theme.nix @@ -4,7 +4,6 @@ config, ... }: let - fontSize = config.services.device-vars.fontSize; dracula-xresources = pkgs.fetchFromGitHub { owner = "dracula"; repo = "xresources"; @@ -39,7 +38,7 @@ in { font = { name = "Sans Serif"; - size = fontSize; + size = config.vars.fontSize; }; }; @@ -57,8 +56,8 @@ in { xdg.configFile = let qtconf = '' [Fonts] - fixed="Sans Serif,${lib.strings.floatToString fontSize},-1,5,50,0,0,0,0,0" - general="Sans Serif,${lib.strings.floatToString fontSize},-1,5,50,0,0,0,0,0" + fixed="Sans Serif,${lib.strings.floatToString config.vars.fontSize},-1,5,50,0,0,0,0,0" + general="Sans Serif,${lib.strings.floatToString config.vars.fontSize},-1,5,50,0,0,0,0,0" [Appearance] icon_theme=Flat-Remix-Violet-Dark diff --git a/modules/ags/default.nix b/modules/ags/default.nix index 2477b46..01b3e79 100644 --- a/modules/ags/default.nix +++ b/modules/ags/default.nix @@ -4,13 +4,12 @@ pkgs, ... }: let - vars = config.services.device-vars; isNvidia = config.hardware.nvidia.modesetting.enable; isTouchscreen = config.hardware.sensor.iio.enable; in { services.upower.enable = true; - home-manager.users.${vars.username}.imports = [ + home-manager.users.${config.vars.user}.imports = [ ags.homeManagerModules.default ({ @@ -23,7 +22,7 @@ in { in { programs.ags = { enable = true; - configDir = symlink "${vars.configDir}/ags"; + configDir = symlink "${config.vars.configDir}/ags"; package = ags.packages.x86_64-linux.default; extraPackages = [pkgs.libgudev]; }; diff --git a/modules/greetd/default.nix b/modules/greetd/default.nix index b183210..ef537a4 100644 --- a/modules/greetd/default.nix +++ b/modules/greetd/default.nix @@ -7,17 +7,22 @@ # Nix stuff optionals = lib.lists.optionals; isNvidia = config.hardware.nvidia.modesetting.enable; - vars = config.services.device-vars; # Executables' paths regreetBin = "${lib.getExe config.programs.regreet.package}"; - hyprBin = "${config.home-manager.users.${vars.username} - .wayland.windowManager.hyprland.finalPackage}/bin"; + hyprBin = "${config + .home-manager + .users + .${config.vars.user} + .wayland + .windowManager + .hyprland + .finalPackage}/bin"; # Show Regreet on all monitors dupeMonitors = pkgs.writeShellScriptBin "dupeMonitors" '' names=($(${hyprBin}/hyprctl -j monitors | ${pkgs.jq}/bin/jq -r '.[] .name')) - main="${vars.mainMonitor}" + main="${config.vars.mainMonitor}" if [[ $(echo "$main") == "null" ]]; then main="''${names[0]}" @@ -31,8 +36,9 @@ ''; # Check if user wants Regreet only on main monitor - setupMonitors = if vars.mainMonitor != null && !vars.greetdDupe - then "${hyprBin}/hyprctl dispatch focusmonitor ${vars.mainMonitor}" + setupMonitors = + if (config.vars.mainMonitor != null && !config.vars.greetdDupe) + then "${hyprBin}/hyprctl dispatch focusmonitor ${config.vars.mainMonitor}" else "${dupeMonitors}/bin/dupeMonitors"; # Get css for regreet diff --git a/modules/tailscale.nix b/modules/tailscale.nix index 687cf23..c0c0791 100644 --- a/modules/tailscale.nix +++ b/modules/tailscale.nix @@ -1,6 +1,4 @@ -{config, ...}: let - vars = config.services.device-vars; -in { +{config, ...}: { services = { tailscale = { enable = true; @@ -11,7 +9,7 @@ in { }; }; - home-manager.users.${vars.username}.programs.bash.shellAliases = { + home-manager.users.${config.vars.user}.programs.bash.shellAliases = { tup = "tailscale up --login-server https://headscale.nelim.org"; pc = "mosh matt@binto -- tmux -2u new -At laptop";