### Per-User Module Configuration Example (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code illustrates how to configure modules on a per-user basis using hierarchical enables. It shows how to enable entire categories of modules (e.g., browsers, editors) or specific individual modules. ```nix hostUsers.dgarifullin = importUser "dgarifullin" // { enable = true; modules = { # Enable entire categories home.browsers.enable = true; # enables vivaldi, chromium, etc. home.editors.enable = true; # enables neovim, cursor, etc. # Or enable specific modules home.media.vlc.enable = true; # just vlc home.media.spotify.enable = true; }; }; ``` -------------------------------- ### Apply Nix Configuration (Bash) Source: https://github.com/gdr/dot/blob/master/README.md This snippet demonstrates how to clone the repository and apply the Nix configuration for both NixOS and macOS systems. It requires Git to be installed and uses `nixos-rebuild` for NixOS or `darwin-rebuild` for macOS, specifying the hostname. ```bash # Clone the repository git clone https://github.com/gdr/dot.git ~/Workspaces/gdr/dot cd ~/Workspaces/gdr/dot # Apply configuration # NixOS: sudo nixos-rebuild switch --flake .# # macOS: darwin-rebuild switch --flake .# ``` -------------------------------- ### Generate NixOS Hardware Configuration (Bash) Source: https://github.com/gdr/dot/blob/master/README.md This command generates the hardware configuration file for NixOS, which is essential for a new host setup. The output is redirected to the hardware-configuration.nix file. ```bash nixos-generate-config --show-hardware-config > hosts/machines/my-new-host/hardware-configuration.nix ``` -------------------------------- ### Enter Nix Development Shell Source: https://context7.com/gdr/dot/llms.txt Enters the development shell environment for the project, which automatically installs and configures pre-commit hooks. This shell provides tools for linting and formatting Nix files. ```bash # Enter development shell (auto-installs pre-commit hooks) nix develop # Or use direnv for automatic shell activation # .envrc file contents: use flake direnv allow # Development shell includes: # - nixpkgs-fmt for Nix file formatting # - pre-commit for git hooks ``` -------------------------------- ### Configure Ghostty Terminal Emulator with Nix Source: https://context7.com/gdr/dot/llms.txt Installs the Ghostty terminal emulator on Linux via nixpkgs and on macOS via Homebrew cask. It also sets up dotfiles for live editing. ```nix # modules/home/terminal/ghostty/ghostty.nix { lib, pkgs, ... }@args: lib.my.mkModuleV2 args { description = "Ghostty terminal emulator"; platforms = [ "linux" "darwin" ]; # Optional, defaults to both module = { # Linux: install via nixpkgs nixosSystems.home.packages = [ pkgs.ghostty ]; # macOS: install via Homebrew cask darwinSystems.homebrew.casks = [ "ghostty" ]; }; # Symlink dotfiles for live editing (changes apply without rebuild) dotfiles = { path = "ghostty"; # ~/.config/ghostty source = "modules/home/terminal/ghostty/dotfiles"; # repo path }; } # Enable in host config: # hostUsers.myuser.modules.home.terminal.ghostty.enable = true; # Or enable all terminal modules: # hostUsers.myuser.modules.home.terminal.enable = true; ``` -------------------------------- ### Create a New System Module (Linux) (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code defines a new system module specifically for Linux. It includes system-level service configurations and user package installations via home-manager, filtering for enabled users. ```nix # modules/systems/linux/services/my-service.nix { lib, pkgs, config, ... }@args: let enabledUsers = lib.filterAttrs (_: u: u.enable) config.hostUsers; in lib.my.mkSystemModuleV2 args { namespace = "linux"; description = "My service"; module = _: { # System-level NixOS options services.my-service.enable = true; # User packages via home-manager home-manager.users = lib.mapAttrs (name: _: { home.packages = [ pkgs.my-tool-client ]; }) enabledUsers; }; } ``` -------------------------------- ### Create a New Host Directory (Bash) Source: https://github.com/gdr/dot/blob/master/README.md This command creates a new directory for a host machine within the dotfiles project structure. It ensures the parent directories exist. ```bash mkdir -p hosts/machines/my-new-host ``` -------------------------------- ### Enable New User in Host Config (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code snippet demonstrates how to enable a newly defined user within a specific host's configuration. It also specifies user keys and hierarchical module enables for the user's environment. ```nix # hosts/machines/my-host/default.nix hostUsers.newuser = importUser "newuser" // { enable = true; keys = [{ name = "my-host"; type = "rsa"; purpose = [ "git" "ssh" ]; isDefault = true; }]; # Hierarchical module enables modules = { home.core.enable = true; home.shell.enable = true; home.media.vlc.enable = true; # specific module }; }; ``` -------------------------------- ### Configure Zsh Shell with Oh-My-Zsh and Zplug using Nix Source: https://context7.com/gdr/dot/llms.txt Sets up the Zsh shell with oh-my-zsh, zplug, and custom prompt configurations. It allows overriding options like showing the hostname. Includes system and user-level configurations. ```nix # modules/home/shell/zsh/zsh.nix { lib, pkgs, config, system, self, _modulePath, ... }@args: with lib; let isDarwin = system == "aarch64-darwin" || system == "x86_64-darwin"; in lib.my.mkModuleV2 args { description = "Zsh shell configuration with oh-my-zsh and zplug"; extraOptions = { showHostname = mkOption { default = true; type = types.bool; description = "Show hostname in the prompt"; }; }; # System-level configuration (runs as root) systemModule = { allSystems = { programs.zsh.enable = true; environment.systemPackages = [ pkgs.eza ]; users.users = lib.my.mkUsersAttrs { inherit config _modulePath; } (username: { shell = pkgs.zsh; }); }; }; # User-level configuration (runs via home-manager) module = cfg: { allSystems = { programs.zsh = { enable = true; enableCompletion = true; autosuggestion.enable = true; oh-my-zsh.enable = true; zplug = { enable = true; plugins = [ { name = "romkatv/powerlevel10k"; tags = [ "as:theme" "depth:1" ]; } { name = "zsh-users/zsh-syntax-highlighting"; } ]; }; initContent = '' source ~/.config/zsh/.p10k.zsh '' + lib.optionalString (!cfg.showHostname) '' typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE='%n' ''; shellAliases = { vim = "nvim"; ls = "eza -l"; }; }; }; }; dotfiles = { path = "zsh"; source = "modules/home/shell/zsh/dotfiles"; }; } ``` -------------------------------- ### Build macOS Nix Configuration with mkDarwinConfiguration Source: https://context7.com/gdr/dot/llms.txt Creates a complete nix-darwin system configuration for macOS, integrating home-manager, nixvim, and other module configurations. It utilizes flake helpers to define the Darwin configuration. ```nix # flake.nix { outputs = inputs@{ self, nixpkgs, nix-darwin, home-manager, ... }: let lib = nixpkgs.lib.extend (lib: _: { my = import ./lib { inherit inputs lib; }; }); overlays = import ./overlays { inherit inputs lib; }; flakeHelpers = lib.my.mkFlakeHelpers { inherit self overlays; }; in { darwinConfigurations.mac-brightstar = flakeHelpers.mkDarwinConfiguration ./hosts/machines/mac-brightstar; }; } # Apply configuration: # darwin-rebuild switch --flake .#mac-brightstar ``` -------------------------------- ### Build NixOS Configuration with mkNixosConfiguration Source: https://context7.com/gdr/dot/llms.txt Creates a complete NixOS system configuration, including home-manager, hardware support, and module integrations. It leverages flake helpers for defining the NixOS configuration. ```nix # flake.nix { outputs = inputs@{ self, nixpkgs, home-manager, hardware, ... }: let lib = nixpkgs.lib.extend (lib: _: { my = import ./lib { inherit inputs lib; }; }); overlays = import ./overlays { inherit inputs lib; }; flakeHelpers = lib.my.mkFlakeHelpers { inherit self overlays; }; in { nixosConfigurations.nix-goldstar = flakeHelpers.mkNixosConfiguration ./hosts/machines/nix-goldstar; }; } # Apply configuration: # sudo nixos-rebuild switch --flake .#nix-goldstar ``` -------------------------------- ### NixOS and nix-darwin Directory Structure (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This snippet outlines the directory structure of the Nix configuration project. It shows the organization of flake entry points, host configurations, library functions, modules (categorized by system and user), and custom packages. ```nix . ├── flake.nix # Entry point - defines hosts and imports ├── hosts/ │ ├── users/ # User defaults (imported by machines) │ │ └── dgarifullin.nix │ └── machines/ # Machine configurations │ ├── nix-goldstar/ # NixOS host │ │ ├── default.nix │ │ └── hardware-configuration.nix │ └── mac-brightstar/ # Darwin host │ └── default.nix ├── lib/ │ └── default.nix # Helper functions (mkModule, mkDotfilesSymlink) ├── modules/ │ ├── _core/ # Core module infrastructure │ │ ├── registry.nix # Module registry builder │ │ └── user.nix # hostUsers options & home-manager setup │ ├── systems/ │ │ ├── all/ # Cross-platform system modules │ │ │ ├── fonts.nix │ │ │ ├── nix/ │ │ │ │ ├── gc.nix │ │ │ │ └── settings.nix │ │ │ └── shell/ │ │ │ ├── git.nix │ │ │ └── ssh.nix │ │ ├── linux/ # Linux-only system modules │ │ │ ├── desktop/ │ │ │ │ ├── awesomewm/ │ │ │ │ └── hyprland/ │ │ │ ├── graphics/ │ │ │ ├── keyboards/ │ │ │ ├── networking/ │ │ │ └── sound.nix │ │ └── darwin/ # macOS-only system modules │ └── home/ # User-level modules (enabled hierarchically) │ ├── browsers/ │ ├── cli/ │ ├── desktop/ │ │ ├── appearance/ │ │ ├── services/ │ │ ├── utils/ │ │ └── widgets/ │ ├── editors/ │ ├── games/ │ ├── media/ │ ├── messengers/ │ ├── security/ │ ├── shell/ │ └── terminal/ └── pkgs/ # Custom packages ``` -------------------------------- ### Configure OpenSSH Server with Charon-Key using Nix Source: https://context7.com/gdr/dot/llms.txt Sets up the OpenSSH server on Linux systems, integrating with charon-key for managing authorized keys based on GitHub usernames. It allows mapping NixOS usernames to GitHub usernames. ```nix # modules/systems/linux/networking/openssh.nix { lib, config, ... }@args: let cfg = config.systemLinux.networking.openssh or { }; userMap = cfg.userMap or { }; in lib.my.mkSystemModuleV2 args { namespace = "linux"; description = "OpenSSH server with charon-key for authorized keys"; extraOptions = { userMap = lib.mkOption { type = lib.types.attrsOf lib.types.str; default = { }; example = lib.literalExpression ''{ "nixuser" = "github-username"; }''; description = "Map NixOS usernames to GitHub usernames for charon-key"; }; }; module = _: lib.mkMerge [ { services.openssh.enable = true; } (lib.mkIf (userMap != { }) { services.charon-key = { enable = true; userMap = lib.mapAttrs (_: ghUser: [ ghUser ]) userMap; }; }) ]; } # Enable in host config: # systemLinux.networking.openssh = { enable = true; userMap = { "*" = "gdr"; }; }; ``` -------------------------------- ### New User Defaults Configuration (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code defines default settings for a new user, including their full name, email, GitHub username, and additional groups. These defaults can be overridden in the host configuration. ```nix # hosts/users/newuser.nix { lib, ... }: { enable = lib.mkDefault false; fullName = lib.mkDefault "New User"; email = lib.mkDefault "newuser@example.com"; github = lib.mkDefault "newuser"; extraGroups = lib.mkDefault [ "wheel" "audio" "video" ]; } ``` -------------------------------- ### Enable Docker Runtime and User Group Source: https://context7.com/gdr/dot/llms.txt Enables the Docker container runtime on NixOS systems and adds users to the 'docker' group if they have enabled this module. This allows users to manage Docker containers without root privileges. ```nix { lib, pkgs, config, _modulePath, }@args: lib.my.mkModuleV2 args { description = "Docker container runtime"; systemModule = { nixosSystems = { virtualisation.docker.enable = true; # Add docker group only to users who enabled this module users.users = lib.my.mkUsersAttrs { inherit config _modulePath; } (username: { extraGroups = [ "docker" ]; }); }; }; module = { darwinSystems.home.packages = with pkgs; [ docker docker-credential-helpers ]; }; } ``` -------------------------------- ### Create Live-Editable Config Symlinks Source: https://context7.com/gdr/dot/llms.txt Creates symbolic links from ~/.config to specified dotfiles within the repository, enabling live editing of configuration files without requiring a NixOS rebuild. This is typically managed via the 'dotfiles' option in mkModuleV2. ```nix # Manual usage (typically use dotfiles option in mkModuleV2 instead) { config, lib, self, ... }: { home-manager.users = lib.my.mkDotfilesSymlink { inherit config self; path = "ghostty"; # ~/.config/ghostty source = "modules/home/terminal/ghostty/dotfiles"; # repo path # target = "~/.config/ghostty"; # optional explicit target }; } # Result: ~/.config/ghostty -> /path/to/repo/modules/home/terminal/ghostty/dotfiles # Edit files in repo, changes apply immediately without nixos-rebuild ``` -------------------------------- ### Create a New User Module (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code defines a new user module. It specifies the module's description, supported platforms, and configuration for different environments (all systems, NixOS, Darwin). ```nix # modules/home/tools/my-tool.nix { lib, pkgs, ... }@args: lib.my.mkModuleV2 args { description = "My awesome tool"; platforms = [ "linux" "darwin" ]; # optional, defaults to both module = { # Cross-platform config (goes to home-manager.users.*) allSystems.home.packages = [ pkgs.my-tool ]; # Or platform-specific nixosSystems.programs.my-tool.enable = true; darwinSystems.homebrew.casks = [ "my-tool" ]; }; } ``` -------------------------------- ### Enable User Modules Hierarchically Source: https://github.com/gdr/dot/blob/master/README.md This Nix code snippet demonstrates how to enable various user modules hierarchically. It allows for granular control over which features and applications are activated for a specific user on a host. ```nix hostUsers.myuser.modules = { home.browsers.enable = true; # enables all browsers home.core.enable = true; # enables htop, shell-utils home.shell.enable = true; # enables zsh, tmux home.editors.neovim.enable = true; # specific module }; ``` -------------------------------- ### Configure Common Nix Settings with mkSystemModuleV2 Source: https://context7.com/gdr/dot/llms.txt Creates system-level modules for common Nix settings, including experimental features and package overlays. It supports platform-specific additions for Linux and Darwin. ```nix # modules/systems/all/nix/settings.nix { lib, overlays, system, ... }@args: lib.my.mkSystemModuleV2 args { namespace = "all"; # "all" | "darwin" | "linux" description = "Common Nix settings (flakes, nix-command)"; module = _: { nix.settings.experimental-features = [ "nix-command" "flakes" ]; nixpkgs.config.allowUnfree = true; nixpkgs.overlays = [ overlays.${system}.additions ]; }; # Platform-specific additions for namespace = "all" moduleLinux = _: { system.stateVersion = "25.11"; }; moduleDarwin = _: { system.stateVersion = 5; }; } # Enable in host config: # systemAll.nix.settings.enable = true; ``` -------------------------------- ### Define Host Configuration in Nix Source: https://context7.com/gdr/dot/llms.txt Defines a complete host configuration, including user settings, system modules, and hardware specifics. Supports hierarchical module enables for user configurations and platform-specific system modules. ```nix # hosts/machines/my-host/default.nix { inputs, lib, config, pkgs, ... }: let importUser = name: import ../../users/${name}.nix { inherit lib; }; in { imports = [ ./hardware-configuration.nix ]; # User configuration with hierarchical module enables hostUsers.dgarifullin = importUser "dgarifullin" // { enable = true; keys = [{ name = "my-host"; type = "rsa"; purpose = [ "git" "ssh" ]; isDefault = true; }]; ssh = [ { host = "*"; identityFile = "~/.ssh/my-host_id_rsa"; extraOptions.AddKeysToAgent = "yes"; } { host = "github.com"; user = "git"; identityFile = "~/.ssh/my-host_id_rsa"; } ]; modules = { home.browsers.enable = true; # Enable all browsers (vivaldi, chromium) home.cli.enable = true; # Enable CLI tools (htop, shell-utils) home.shell.enable = true; # Enable zsh, tmux home.editors.neovim.enable = true; # Enable specific module home.terminal.enable = true; # Enable ghostty }; }; networking.hostName = "my-host"; # System-level modules (cross-platform) systemAll = { fonts.enable = true; nix.settings.enable = true; nix.gc.enable = true; shell.ssh.enable = true; shell.git.enable = true; }; # Linux-specific system modules systemLinux = { networking.networkmanager.enable = true; networking.openssh = { enable = true; userMap = { "*" = "github-username"; }; }; graphics.nvidia.enable = true; sound.enable = true; }; time.timeZone = "Europe/Moscow"; } ``` -------------------------------- ### Symlink Dotfiles with Nix Source: https://github.com/gdr/dot/blob/master/README.md This Nix function, `mkDotfilesSymlink`, creates symbolic links for dotfiles from a repository path to a target directory. It's used to manage configuration files that can be edited live without requiring a system rebuild. ```nix { config, pkgs, lib, self, ... }: { config = mkIf cfg.enable (mkMerge [ # Install the package (mkModule { allSystems.home.packages = [ pkgs.ghostty ]; }) # Symlink dotfiles to ~/.config/ghostty (editable without rebuild!) { home-manager.users = lib.my.mkDotfilesSymlink { inherit config self; path = "ghostty"; # ~/.config/ghostty source = "modules/home/terminal/ghostty/dotfiles"; # repo path }; } ]); } ``` -------------------------------- ### Define User Defaults in Nix Source: https://context7.com/gdr/dot/llms.txt Defines reusable default settings for a user, which can be imported and customized across different host configurations. This promotes consistency in user environments. ```nix # hosts/users/myuser.nix { lib, ... }: { fullName = "My User"; email = "user@example.com"; github = "myuser"; extraGroups = [ "wheel" "audio" "video" "docker" ]; } # Usage in host configuration: # hostUsers.myuser = importUser "myuser" // { enable = true; modules = { ... }; }; ``` -------------------------------- ### Create User Attribute Sets with mkUsersAttrs in Nix Source: https://context7.com/gdr/dot/llms.txt A helper function in Nix to generate user attribute sets, typically used for applying configurations to users who have enabled a specific module. It simplifies user management within Nix configurations. ```nix # No code provided for this snippet, only a description. ``` -------------------------------- ### NixOS Host Configuration (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code defines the configuration for a new NixOS host, including user settings, system modules, and host-specific options. It utilizes hierarchical imports for user and system configurations. ```nix # hosts/machines/my-new-host/default.nix { config, lib, pkgs, ... }: let importUser = name: import ../../users/${name}.nix { inherit lib; }; in { imports = [ ./hardware-configuration.nix ]; # User configuration hostUsers.dgarifullin = importUser "dgarifullin" // { enable = true; keys = [{ name = "my-new-host"; type = "rsa"; purpose = [ "git" "ssh" ]; isDefault = true; }]; # Hierarchical module enables modules = { home.cli.enable = true; home.shell.enable = true; home.editors.enable = true; # Or enable specific modules: # home.browsers.vivaldi.enable = true; }; }; networking.hostName = "my-new-host"; # System modules systemAll = { fonts.enable = true; nix.settings.enable = true; nix.gc.enable = true; shell.ssh.enable = true; shell.git.enable = true; }; # Linux-specific (remove for Darwin) systemLinux = { desktop.hyprland.enable = true; networking.networkmanager.enable = true; sound.enable = true; }; time.timeZone = "Europe/Moscow"; } ``` -------------------------------- ### Add Host Configuration to Flake (Nix) Source: https://github.com/gdr/dot/blob/master/README.md This Nix code snippet shows how to register a new host configuration within the project's `flake.nix` file, enabling it for either NixOS or Darwin. ```nix nixosConfigurations.my-new-host = mkNixosConfiguration ./hosts/machines/my-new-host; # or for Darwin: darwinConfigurations.my-new-host = mkDarwinConfiguration ./hosts/machines/my-new-host; ``` -------------------------------- ### Check Hierarchical Module Enable Status Source: https://context7.com/gdr/dot/llms.txt Determines if a module should be enabled based on a hierarchical path. It checks specific module enables, parent enables, grandparent enables, and per-user module enables. This function is used internally by mkModuleV2. ```nix # Internal usage in mkModuleV2 (automatic) # A module is enabled if any of these are true: # - modules.home.browsers.vivaldi.enable = true (specific) # - modules.home.browsers.enable = true (parent) # - modules.home.enable = true (grandparent) # - hostUsers..modules.home.browsers.enable = true (per-user) shouldEnable = lib.my.shouldEnableModule { inherit config; modulePath = "home.browsers.vivaldi"; }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.