From 0c4ce3e93630c35d1fff016002fc2be77a4399c9 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Tue, 3 Jan 2023 21:17:49 -0500 Subject: [PATCH] Refactor config to merge modules from platforms --- common/config/login.nix | 30 ------------------ {laptop/config => config}/battery.nix | 4 +-- {common/config => config}/config.nix | 15 +++++++++ {common/config => config}/default.nix | 3 +- config/login.nix | 31 +++++++++++++++++++ {common/config => config}/packages.nix | 0 .../tokyo-night-sddm/theme.conf | 0 desktop/config/default.nix | 11 ------- desktop/home-manager/default.nix | 7 ----- desktop/home-manager/waybar.nix | 8 ----- flake.nix | 30 ++++++++++++------ .../desktop.nix | 6 +--- .../laptop.nix | 5 +-- .../home-manager => home-manager}/default.nix | 0 .../shell/alacritty.nix | 0 .../shell/default.nix | 0 .../shell/starship.nix | 0 .../wayland/default.nix | 1 + .../wayland/mako.nix | 0 .../wayland/rofi.nix | 0 .../wayland/rofi/config.rasi | 0 .../wayland/rofi/noicons.rasi | 0 .../wayland/rofi/tokyonight.rasi | 0 .../wayland/rofi/window.sh | 0 .../wayland/rofi/workspace.sh | 0 .../wayland/sway.nix | 2 +- .../wayland/swaylock.nix | 0 .../wayland/waybar.nix | 18 +++++++---- laptop/config/default.nix | 18 ----------- laptop/home-manager/default.nix | 7 ----- laptop/home-manager/waybar.nix | 8 ----- platform.nix | 7 +++++ 32 files changed, 95 insertions(+), 116 deletions(-) delete mode 100644 common/config/login.nix rename {laptop/config => config}/battery.nix (66%) rename {common/config => config}/config.nix (76%) rename {common/config => config}/default.nix (66%) create mode 100644 config/login.nix rename {common/config => config}/packages.nix (100%) rename {common/config => config}/tokyo-night-sddm/theme.conf (100%) delete mode 100644 desktop/config/default.nix delete mode 100644 desktop/home-manager/default.nix delete mode 100644 desktop/home-manager/waybar.nix rename desktop/config/hardware-configuration.nix => hardware-configuration/desktop.nix (90%) rename laptop/config/hardware-configuration.nix => hardware-configuration/laptop.nix (88%) rename {common/home-manager => home-manager}/default.nix (100%) rename {common/home-manager => home-manager}/shell/alacritty.nix (100%) rename {common/home-manager => home-manager}/shell/default.nix (100%) rename {common/home-manager => home-manager}/shell/starship.nix (100%) rename {common/home-manager => home-manager}/wayland/default.nix (91%) rename {common/home-manager => home-manager}/wayland/mako.nix (100%) rename {common/home-manager => home-manager}/wayland/rofi.nix (100%) rename {common/home-manager => home-manager}/wayland/rofi/config.rasi (100%) rename {common/home-manager => home-manager}/wayland/rofi/noicons.rasi (100%) rename {common/home-manager => home-manager}/wayland/rofi/tokyonight.rasi (100%) rename {common/home-manager => home-manager}/wayland/rofi/window.sh (100%) rename {common/home-manager => home-manager}/wayland/rofi/workspace.sh (100%) rename {common/home-manager => home-manager}/wayland/sway.nix (98%) rename {common/home-manager => home-manager}/wayland/swaylock.nix (100%) rename {common/home-manager => home-manager}/wayland/waybar.nix (95%) delete mode 100644 laptop/config/default.nix delete mode 100644 laptop/home-manager/default.nix delete mode 100644 laptop/home-manager/waybar.nix create mode 100644 platform.nix diff --git a/common/config/login.nix b/common/config/login.nix deleted file mode 100644 index 053cc30..0000000 --- a/common/config/login.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ config, pkgs, tokyo-night-sddm-src, ... }: -let - tokyo-night-sddm = with pkgs.libsForQt5; pkgs.stdenv.mkDerivation { - name = "tokyo-night-sddm"; - src = tokyo-night-sddm-src; - installPhase = '' - cp -f ${./tokyo-night-sddm/theme.conf} ./theme.conf - mkdir -p $out/share/sddm/themes/tokyo-night-sddm - mv * $out/share/sddm/themes/tokyo-night-sddm - ''; - }; -in { - environment.systemPackages = with pkgs.libsForQt5; [ - tokyo-night-sddm # Theme - qtbase - qtsvg - qtquickcontrols2 - qtgraphicaleffects - ]; - - services.xserver = { - enable = true; - - displayManager.defaultSession = "sway"; - displayManager.sddm = { - enable = true; - theme = "tokyo-night-sddm"; - }; - }; -} diff --git a/laptop/config/battery.nix b/config/battery.nix similarity index 66% rename from laptop/config/battery.nix rename to config/battery.nix index 5d6dbfd..2f67a61 100644 --- a/laptop/config/battery.nix +++ b/config/battery.nix @@ -1,5 +1,5 @@ -{ ... }: -{ +{ config, lib, ... }: +lib.mkIf (config.custom.platform == "laptop") { services.upower = { enable = true; diff --git a/common/config/config.nix b/config/config.nix similarity index 76% rename from common/config/config.nix rename to config/config.nix index bfac348..48d1de4 100644 --- a/common/config/config.nix +++ b/config/config.nix @@ -1,4 +1,15 @@ { config, pkgs, nur, username, fullname, ... }: +let + inherit (config.custom) platform; + + hashedPassword = + if platform == "desktop" then + "$6$HYibiGhDN.JgLtw6$cecU7NjfumTUJSkFNFQG4uVgdd3tTPLGxK0zHAwYn3un/V43IUlyVBNKoRMLCQk65RckbD/.AjsLFVFKUUHVA/" + else if platform == "laptop" then + "$6$y3eb1phxFWnParRT$w1LNfxJ2ByHoiBa5ywh4STGuIK/r4Tnyxx2Xe/nlovrE6LuuLAVdKRFAroUTtUI/d2BNGI9ErjZ2z2Dl7w/t00" + else + "$6$vmmMT7pEY1W0Bj9R$Kb6nuwdg/KzCrGcUPkEo2jJ6a2NJRikiOeN8/I8ObU1K6rVYvgYqPVgPg9NkLaUScdh1PWcabuvaHCFLMw14A0"; +in { nix.package = pkgs.nixFlakes; nix.extraOptions = '' @@ -12,6 +23,7 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; + networking.hostName = "kiana-${platform}"; networking.wireless.enable = false; networking.networkmanager.enable = true; @@ -33,8 +45,11 @@ description = fullname; extraGroups = [ "wheel" "networkmanager" ]; # Enable ‘sudo’ for the user. shell = pkgs.fish; + inherit hashedPassword; }; + users.users.root = { inherit hashedPassword; }; + fonts = { enableDefaultFonts = true; diff --git a/common/config/default.nix b/config/default.nix similarity index 66% rename from common/config/default.nix rename to config/default.nix index e4ac18a..7b277f3 100644 --- a/common/config/default.nix +++ b/config/default.nix @@ -1,8 +1,9 @@ -{ config, pkgs, ... }: +{ pkgs, lib, ... }: { imports = [ ./config.nix ./packages.nix ./login.nix + ./battery.nix ]; } diff --git a/config/login.nix b/config/login.nix new file mode 100644 index 0000000..865fe70 --- /dev/null +++ b/config/login.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, tokyo-night-sddm-src, ... }: +lib.mkIf (config.custom.platform != "mobile") + (let + tokyo-night-sddm = with pkgs.libsForQt5; pkgs.stdenv.mkDerivation { + name = "tokyo-night-sddm"; + src = tokyo-night-sddm-src; + installPhase = '' + cp -f ${./tokyo-night-sddm/theme.conf} ./theme.conf + mkdir -p $out/share/sddm/themes/tokyo-night-sddm + mv * $out/share/sddm/themes/tokyo-night-sddm + ''; + }; + in { + environment.systemPackages = with pkgs.libsForQt5; [ + tokyo-night-sddm # Theme + qtbase + qtsvg + qtquickcontrols2 + qtgraphicaleffects + ]; + + services.xserver = { + enable = true; + + displayManager.defaultSession = "sway"; + displayManager.sddm = { + enable = true; + theme = "tokyo-night-sddm"; + }; + }; + }) diff --git a/common/config/packages.nix b/config/packages.nix similarity index 100% rename from common/config/packages.nix rename to config/packages.nix diff --git a/common/config/tokyo-night-sddm/theme.conf b/config/tokyo-night-sddm/theme.conf similarity index 100% rename from common/config/tokyo-night-sddm/theme.conf rename to config/tokyo-night-sddm/theme.conf diff --git a/desktop/config/default.nix b/desktop/config/default.nix deleted file mode 100644 index 7836707..0000000 --- a/desktop/config/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ config, pkgs, ... }: -let hashedPassword = "$6$HYibiGhDN.JgLtw6$cecU7NjfumTUJSkFNFQG4uVgdd3tTPLGxK0zHAwYn3un/V43IUlyVBNKoRMLCQk65RckbD/.AjsLFVFKUUHVA/"; -in { - imports = [ - ./hardware-configuration.nix - ]; - - # Passwords - users.users.kiana = { inherit hashedPassword; }; - users.users.root = { inherit hashedPassword; }; -} diff --git a/desktop/home-manager/default.nix b/desktop/home-manager/default.nix deleted file mode 100644 index ec046a1..0000000 --- a/desktop/home-manager/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: -{ - imports = [ - ../../common/home-manager - ./waybar.nix - ]; -} diff --git a/desktop/home-manager/waybar.nix b/desktop/home-manager/waybar.nix deleted file mode 100644 index 203c55e..0000000 --- a/desktop/home-manager/waybar.nix +++ /dev/null @@ -1,8 +0,0 @@ -# Home manager is being weird about conflicts, -# so I'm doing this. It sucks, but so does home -# manager, so it's fine. - -import ../../common/home-manager/wayland/waybar.nix -[ "sway/workspaces" "sway/mode" "custom/sep" "cpu" "memory" "temperature" ] -[ "sway/window" ] -[ "pulseaudio" "network" "clock" "idle_inhibitor" ] diff --git a/flake.nix b/flake.nix index e7cf2f2..333df13 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { description = "System conf"; -inputs = rec { +inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nur.url = "github:nix-community/NUR"; nixos-hardware.url = "github:NixOS/nixos-hardware"; @@ -20,21 +20,26 @@ outputs = { self, system = "x86_64-linux"; username = "kiana"; fullname = "Kiana Sheibani"; - moduleArgs = inputs // { inherit system username fullname; }; + moduleArgs = { inherit system username fullname; } // inputs; lib = nixpkgs.lib; in { nixosConfigurations = { "${username}-desktop" = lib.makeOverridable lib.nixosSystem { inherit system; modules = [ - { _module.args = moduleArgs; } - ./desktop/config - ./common/config + ./config + + ./platform.nix + ./hardware-configuration/desktop.nix + { _module.args = moduleArgs; + custom.platform = "desktop"; } home-manager.nixosModules.home-manager { + home-manager.users.${username} = import ./home-manager; + home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.${username} = import ./desktop/home-manager; + home-manager.sharedModules = [ ./platform.nix { custom.platform = "desktop"; } ]; home-manager.extraSpecialArgs = moduleArgs; } ]; @@ -43,15 +48,20 @@ outputs = { self, "${username}-laptop" = lib.makeOverridable lib.nixosSystem { inherit system; modules = [ - { _module.args = moduleArgs; } - ./laptop/config - ./common/config + ./config + + { _module.args = moduleArgs; + custom.platform = "laptop"; } + ./platform.nix + ./hardware-configuration/laptop.nix home-manager.nixosModules.home-manager nixos-hardware.nixosModules.microsoft-surface { + home-manager.users.${username} = import ./home-manager; + home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.${username} = import ./laptop/home-manager; + home-manager.sharedModules = [ ./platform.nix { custom.platform = "laptop"; } ]; home-manager.extraSpecialArgs = moduleArgs; } ]; diff --git a/desktop/config/hardware-configuration.nix b/hardware-configuration/desktop.nix similarity index 90% rename from desktop/config/hardware-configuration.nix rename to hardware-configuration/desktop.nix index c413b4a..e4f5aea 100644 --- a/desktop/config/hardware-configuration.nix +++ b/hardware-configuration/desktop.nix @@ -2,12 +2,7 @@ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: - { - imports = - [ (modulesPath + "/installer/scan/not-detected.nix") - ]; - boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-amd" ]; @@ -25,5 +20,6 @@ swapDevices = [ ]; + hardware.enableRedistributableFirmware = lib.mkDefault true; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; } diff --git a/laptop/config/hardware-configuration.nix b/hardware-configuration/laptop.nix similarity index 88% rename from laptop/config/hardware-configuration.nix rename to hardware-configuration/laptop.nix index 7e03bad..a9b285e 100644 --- a/laptop/config/hardware-configuration.nix +++ b/hardware-configuration/laptop.nix @@ -2,9 +2,10 @@ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: - { - imports = [ ]; + boot.loader.grub.useOSProber = true; + hardware.enableRedistributableFirmware = true; + hardware.enableAllFirmware = true; boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "nvme" "usbhid" "usb_storage" "sd_mod" ]; boot.initrd.kernelModules = [ ]; diff --git a/common/home-manager/default.nix b/home-manager/default.nix similarity index 100% rename from common/home-manager/default.nix rename to home-manager/default.nix diff --git a/common/home-manager/shell/alacritty.nix b/home-manager/shell/alacritty.nix similarity index 100% rename from common/home-manager/shell/alacritty.nix rename to home-manager/shell/alacritty.nix diff --git a/common/home-manager/shell/default.nix b/home-manager/shell/default.nix similarity index 100% rename from common/home-manager/shell/default.nix rename to home-manager/shell/default.nix diff --git a/common/home-manager/shell/starship.nix b/home-manager/shell/starship.nix similarity index 100% rename from common/home-manager/shell/starship.nix rename to home-manager/shell/starship.nix diff --git a/common/home-manager/wayland/default.nix b/home-manager/wayland/default.nix similarity index 91% rename from common/home-manager/wayland/default.nix rename to home-manager/wayland/default.nix index 90c9386..40e6e15 100644 --- a/common/home-manager/wayland/default.nix +++ b/home-manager/wayland/default.nix @@ -10,5 +10,6 @@ ./swaylock.nix ./mako.nix ./rofi.nix + ./waybar.nix ]; } diff --git a/common/home-manager/wayland/mako.nix b/home-manager/wayland/mako.nix similarity index 100% rename from common/home-manager/wayland/mako.nix rename to home-manager/wayland/mako.nix diff --git a/common/home-manager/wayland/rofi.nix b/home-manager/wayland/rofi.nix similarity index 100% rename from common/home-manager/wayland/rofi.nix rename to home-manager/wayland/rofi.nix diff --git a/common/home-manager/wayland/rofi/config.rasi b/home-manager/wayland/rofi/config.rasi similarity index 100% rename from common/home-manager/wayland/rofi/config.rasi rename to home-manager/wayland/rofi/config.rasi diff --git a/common/home-manager/wayland/rofi/noicons.rasi b/home-manager/wayland/rofi/noicons.rasi similarity index 100% rename from common/home-manager/wayland/rofi/noicons.rasi rename to home-manager/wayland/rofi/noicons.rasi diff --git a/common/home-manager/wayland/rofi/tokyonight.rasi b/home-manager/wayland/rofi/tokyonight.rasi similarity index 100% rename from common/home-manager/wayland/rofi/tokyonight.rasi rename to home-manager/wayland/rofi/tokyonight.rasi diff --git a/common/home-manager/wayland/rofi/window.sh b/home-manager/wayland/rofi/window.sh similarity index 100% rename from common/home-manager/wayland/rofi/window.sh rename to home-manager/wayland/rofi/window.sh diff --git a/common/home-manager/wayland/rofi/workspace.sh b/home-manager/wayland/rofi/workspace.sh similarity index 100% rename from common/home-manager/wayland/rofi/workspace.sh rename to home-manager/wayland/rofi/workspace.sh diff --git a/common/home-manager/wayland/sway.nix b/home-manager/wayland/sway.nix similarity index 98% rename from common/home-manager/wayland/sway.nix rename to home-manager/wayland/sway.nix index 1d5b619..1f36b99 100644 --- a/common/home-manager/wayland/sway.nix +++ b/home-manager/wayland/sway.nix @@ -124,7 +124,7 @@ in { }; output."*" = { - bg = "${../../../assets/background.png} fill"; + bg = "${../../assets/background.png} fill"; }; }; }; diff --git a/common/home-manager/wayland/swaylock.nix b/home-manager/wayland/swaylock.nix similarity index 100% rename from common/home-manager/wayland/swaylock.nix rename to home-manager/wayland/swaylock.nix diff --git a/common/home-manager/wayland/waybar.nix b/home-manager/wayland/waybar.nix similarity index 95% rename from common/home-manager/wayland/waybar.nix rename to home-manager/wayland/waybar.nix index 0d3056a..0d3d9a1 100644 --- a/common/home-manager/wayland/waybar.nix +++ b/home-manager/wayland/waybar.nix @@ -1,7 +1,4 @@ -modules-left: -modules-center: -modules-right: -{ pkgs, ... }: +{ config, pkgs, ... }: { programs.waybar = { enable = true; @@ -12,7 +9,16 @@ modules-right: height = 32; margin = "8 8 0"; - inherit modules-left modules-center modules-right; + + modules-left = [ "sway/workspaces" "sway/mode" "custom/sep" "cpu" "memory" "temperature" ]; + modules-center = [ "sway/window" ]; + + modules-right = + if config.custom.platform == "laptop" then + [ "battery" "pulseaudio" "backlight" "network" "clock" "idle_inhibitor" ] + else + [ "pulseaudio" "network" "clock" "idle_inhibitor" ]; + modules = { "sway/workspaces" = { @@ -237,7 +243,7 @@ modules-right: #pulseaudio { background-color: @altblend; ${ - if builtins.elem "backlight" modules-right then + if config.custom.platform == "laptop" then '' margin: 3px 0px 3px 2px; padding-right: 5px; diff --git a/laptop/config/default.nix b/laptop/config/default.nix deleted file mode 100644 index 77b8291..0000000 --- a/laptop/config/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ ... }: -let hashedPassword = "$6$y3eb1phxFWnParRT$w1LNfxJ2ByHoiBa5ywh4STGuIK/r4Tnyxx2Xe/nlovrE6LuuLAVdKRFAroUTtUI/d2BNGI9ErjZ2z2Dl7w/t00"; -in { - imports = [ - ./hardware-configuration.nix - ./battery.nix - ]; - - networking.hostName = "kiana-laptop"; - - boot.loader.grub.useOSProber = true; - hardware.enableRedistributableFirmware = true; - hardware.enableAllFirmware = true; - - # Passwords - users.users.kiana = { inherit hashedPassword; }; - users.users.root = { inherit hashedPassword; }; -} diff --git a/laptop/home-manager/default.nix b/laptop/home-manager/default.nix deleted file mode 100644 index ec046a1..0000000 --- a/laptop/home-manager/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: -{ - imports = [ - ../../common/home-manager - ./waybar.nix - ]; -} diff --git a/laptop/home-manager/waybar.nix b/laptop/home-manager/waybar.nix deleted file mode 100644 index 453da44..0000000 --- a/laptop/home-manager/waybar.nix +++ /dev/null @@ -1,8 +0,0 @@ -# Home manager is being weird about conflicts, -# so I'm doing this. It sucks, but so does home -# manager, so it's fine. - -import ../../common/home-manager/wayland/waybar.nix -[ "sway/workspaces" "sway/mode" "custom/sep" "cpu" "memory" "temperature" ] -[ "sway/window" ] -[ "battery" "pulseaudio" "backlight" "network" "clock" "idle_inhibitor" ] diff --git a/platform.nix b/platform.nix new file mode 100644 index 0000000..1316d6d --- /dev/null +++ b/platform.nix @@ -0,0 +1,7 @@ +{ lib, ... }: +{ + options.custom.platform = lib.mkOption { + description = "The platform to configure for"; + type = lib.types.enum [ "desktop" "laptop" "mobile" ]; + }; +}