From d52f990f561e9c722df8ff889e0f1f535ea6636f Mon Sep 17 00:00:00 2001 From: Eric Carlson Date: Mon, 11 Mar 2024 20:59:50 +0000 Subject: [PATCH] abstract user configuration for general use, reorg, update readme --- README.md | 28 +++++++--- hosts/default.nix | 54 +++++++------------ hosts/desktop/configuration.nix | 14 +---- hosts/desktop/home.nix | 10 ---- hosts/nixos-wsl/configuration.nix | 19 ++----- hosts/nixos-wsl/home.nix | 8 --- modules/home/default.nix | 10 ++-- modules/system/desktop/default.nix | 2 +- .../{hyprland/default.nix => hyprland.nix} | 0 modules/system/home.nix | 21 ++++++++ modules/user/default.nix | 27 ++++++++++ 11 files changed, 98 insertions(+), 95 deletions(-) delete mode 100644 hosts/desktop/home.nix delete mode 100644 hosts/nixos-wsl/home.nix rename modules/system/desktop/{hyprland/default.nix => hyprland.nix} (100%) create mode 100644 modules/system/home.nix create mode 100644 modules/user/default.nix diff --git a/README.md b/README.md index a6804de..4086ca7 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,7 @@ If you have the repo installed locally at `~/gitrepos/dotnix`, you can rebuild w rebuild ``` -## System Modules - -### CLI - -#### [nvim](./modules/system/cli/nvim) +## [Nixvim Modules](./modules/nixvim) - Nvim Configuration using [Nixvim](https://github.com/nix-community/nixvim) - Available as a package @@ -75,13 +71,31 @@ rebuild nix run github:ecarlson94/dotnix/main#nvim ``` +## [User Module](./modules/user/default.nix) + +Configures a user for the NixOS using a dynamic user name that can be configured in `nixosConfiguration`. + +## System Modules + +### [Home](./modules/system/home.nix) + +Configures Home Manager to be managed by the system for the configured user. + +Downside: Changes to [home modules](./modules/home) require full system rebuild. + +Upside: ONE COMMAND TO RULE THEM ALL (rebuild). + ### Desktop -#### [Hyprland](./modules/system/desktop/hyprland) +#### [Hyprland](./modules/system/desktop/hyprland.nix) Bare bones installation of the [Hyprland](https://hyprland.org) dynamic tiling Wayland compositor. -This is the starting point for configuring a UI. +This is the starting point for configuring a UI for NixOS. + +#### [Sound](./modules/system/desktop/sound.nix) + +Configures sound for NixOS. ## [Home Modules](./modules/home) diff --git a/hosts/default.nix b/hosts/default.nix index b6a9fe8..0a4ce8b 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -2,53 +2,35 @@ let inherit (self) inputs packages; - desktop = ../modules/system/desktop; - - createHomeManager = { system, user, homeFile }: { - useGlobalPkgs = true; - useUserPackages = true; - users.${user} = import homeFile; - - # Optionally, use home-manager.extraSpecialArgs to pass - # arguments to home.nix - extraSpecialArgs = { - inherit (packages.${system}) nvim; - firefox-addons = inputs.firefox-addons.packages.${system}; - theme = import ../theme; - }; - }; + userHomeModules = [ + ../modules/user + inputs.home-manager.nixosModules.home-manager + ../modules/system/home.nix + ]; in { nixos-wsl = nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; modules = [ ./nixos-wsl/configuration.nix - inputs.home-manager.nixosModules.home-manager - { - home-manager = createHomeManager { - inherit system; - user = "walawren"; - homeFile = ./nixos-wsl/home.nix; - }; - } - ]; - specialArgs = { inherit inputs; }; + ] ++ userHomeModules; + specialArgs = { + inherit inputs system packages; + target = "nixos-wsl"; + homeOptions = { modules.cli.enable = true; }; + }; }; desktop = nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; modules = [ ./desktop/configuration.nix - desktop - inputs.home-manager.nixosModules.home-manager - { - home-manager = createHomeManager { - inherit system; - user = "walawren"; - homeFile = ./desktop/home.nix; - }; - } - ]; - specialArgs = { inherit inputs; }; + ../modules/system/desktop + ] ++ userHomeModules; + specialArgs = { + inherit inputs system packages; + target = "desktop"; + homeOptions = { modules.desktop.enable = true; }; + }; }; } diff --git a/hosts/desktop/configuration.nix b/hosts/desktop/configuration.nix index 7f7c75a..c92f35b 100644 --- a/hosts/desktop/configuration.nix +++ b/hosts/desktop/configuration.nix @@ -2,10 +2,7 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ pkgs, ... }: -let - target = "desktop"; -in +{ pkgs, target, ... }: { imports = [ @@ -53,15 +50,6 @@ in LC_TIME = "en_US.UTF-8"; }; - programs.zsh.enable = true; - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.walawren = { - shell = pkgs.zsh; - isNormalUser = true; - description = "Eric Carlson"; - extraGroups = [ "networkmanager" "wheel" "audio" "sound" "video" ]; - }; - # Allow unfree packages nixpkgs.config.allowUnfree = true; diff --git a/hosts/desktop/home.nix b/hosts/desktop/home.nix deleted file mode 100644 index 5829342..0000000 --- a/hosts/desktop/home.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - imports = [ ../../modules/home ]; - - home.username = "walawren"; - home.homeDirectory = "/home/walawren"; - - modules.desktop.enable = true; -} diff --git a/hosts/nixos-wsl/configuration.nix b/hosts/nixos-wsl/configuration.nix index 3f28a79..f6b36a7 100644 --- a/hosts/nixos-wsl/configuration.nix +++ b/hosts/nixos-wsl/configuration.nix @@ -5,10 +5,7 @@ # NixOS-WSL specific options are documented on the NixOS-WSL repository: # https://github.com/nix-community/NixOS-WSL -{ pkgs, inputs, ... }: -let - target = "nixos-wsl"; -in +{ pkgs, target, inputs, config, ... }: { imports = [ # include NixOS-WSL modules @@ -16,7 +13,7 @@ in ]; wsl.enable = true; - wsl.defaultUser = "walawren"; + wsl.defaultUser = config.user.name; # This value determines the NixOS release from which the default @@ -41,15 +38,5 @@ in setSocketVariable = true; }; - programs = { - zsh.enable = true; - dconf.enable = true; - }; - - users.users = { - walawren = { - shell = pkgs.zsh; - extraGroups = [ "docker" ]; - }; - }; + programs.dconf.enable = true; # Required for Home Manager } diff --git a/hosts/nixos-wsl/home.nix b/hosts/nixos-wsl/home.nix deleted file mode 100644 index 5decbaa..0000000 --- a/hosts/nixos-wsl/home.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ - imports = [ ../../modules/home ]; - - home.username = "walawren"; - home.homeDirectory = "/home/walawren"; - - modules.cli.enable = true; -} diff --git a/modules/home/default.nix b/modules/home/default.nix index b486c27..38ab295 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -8,8 +8,10 @@ ./desktop ]; - home.packages = [ - pkgs.curl - pkgs.wget - ]; + home = { + packages = [ + pkgs.curl + pkgs.wget + ]; + }; } diff --git a/modules/system/desktop/default.nix b/modules/system/desktop/default.nix index 0d6fa0b..1ae899f 100644 --- a/modules/system/desktop/default.nix +++ b/modules/system/desktop/default.nix @@ -1,6 +1,6 @@ { imports = [ - ./hyprland + ./hyprland.nix ./sound.nix ]; } diff --git a/modules/system/desktop/hyprland/default.nix b/modules/system/desktop/hyprland.nix similarity index 100% rename from modules/system/desktop/hyprland/default.nix rename to modules/system/desktop/hyprland.nix diff --git a/modules/system/home.nix b/modules/system/home.nix new file mode 100644 index 0000000..b6e9c83 --- /dev/null +++ b/modules/system/home.nix @@ -0,0 +1,21 @@ +{ system, inputs, packages, config, homeOptions ? { }, ... }: +{ + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + users.${config.user.name} = { + imports = [ ../home ]; # Home Options + + home.username = config.user.name; + home.homeDirectory = "/home/${config.user.name}"; + } // homeOptions; + + # Optionally, use home-manager.extraSpecialArgs to pass + # arguments to home.nix + extraSpecialArgs = { + inherit (packages.${system}) nvim; + firefox-addons = inputs.firefox-addons.packages.${system}; + theme = import ../../theme; + }; + }; +} diff --git a/modules/user/default.nix b/modules/user/default.nix new file mode 100644 index 0000000..3120cb7 --- /dev/null +++ b/modules/user/default.nix @@ -0,0 +1,27 @@ +{ lib, config, pkgs, ... }: +with lib; +let + cfg = config.user; + + mkOpt = type: default: description: + mkOption { inherit type default description; }; +in +{ + options.user = with types; { + name = mkOpt str "walawren" "The name to use for the user account"; + }; + + config = { + users.users.${cfg.name} = { + inherit (cfg) name; + shell = pkgs.zsh; + isNormalUser = true; + home = "/home/${cfg.name}"; + group = "users"; + + extraGroups = [ "wheel" "networkmanager" "audio" "sound" "video" "input" "tty" "docker" ]; + }; + + programs.zsh.enable = true; + }; +}