Skip to content

AlexNabokikh/nix-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NixOS and nix-darwin Configurations for My Machines

This repository contains NixOS and nix-darwin configurations for my machines, managed through Nix Flakes.

It is structured to easily accommodate multiple machines and user configurations, leveraging nixpkgs, home-manager, nix-darwin, and various other community contributions for a seamless experience across NixOS and macOS.

Showcase

Hyprland

hyprland

Gnome

gnome

macOS

macos

Structure

  • flake.nix: The flake itself, defining inputs and outputs for NixOS, nix-darwin, and Home Manager configurations.
  • hosts/: NixOS and nix-darwin configurations for each machine
  • home/: Home Manager configurations for each machine
  • files/: Miscellaneous configuration files and scripts used across various applications and services
  • modules/: Reusable platform-specific modules
    • nixos/: NixOS-specific modules
    • darwin/: macOS-specific modules
    • home-manager/: User-space configuration modules
  • flake.lock: Lock file ensuring reproducible builds by pinning input versions
  • overlays/: Custom Nix overlays for package modifications or additions

Key Inputs

  • nixpkgs: Points to the nixos-unstable channel for access to the latest packages
  • nixpkgs-stable: Points to the nixos-24.11 channel, providing stable NixOS packages
  • home-manager: Manages user-specific configurations, following the nixpkgs input (release-24.11)
  • hardware: Optimizes settings for different hardware configurations
  • catppuccin: Provides global Catppuccin theme integration
  • spicetify-nix: Enhances Spotify client customization
  • darwin: Enables nix-darwin for macOS system configuration
  • nix-homebrew: Integrates Homebrew package management with nix-darwin

Usage

Adding a New Machine with a New User

To add a new machine with a new user to your NixOS or nix-darwin configuration, follow these steps:

  1. Update flake.nix:

    a. Add the new user to the users attribute set:

    users = {
      # Existing users...
      newuser = {
        avatar = ./files/avatar/face;
        email = "[email protected]";
        fullName = "New User";
        gitKey = "YOUR_GIT_KEY";
        name = "newuser";
      };
    };

    b. Add the new machine to the appropriate configuration set:

    For NixOS:

    nixosConfigurations = {
      # Existing configurations...
      newmachine = mkNixosConfiguration "newmachine" "newuser";
    };

    For nix-darwin:

    darwinConfigurations = {
      # Existing configurations...
      newmachine = mkDarwinConfiguration "newmachine" "newuser";
    };

    c. Add the new home configuration:

    homeConfigurations = {
      # Existing configurations...
      "newuser@newmachine" = mkHomeConfiguration "x86_64-linux" "newuser" "newmachine";
    };
  2. Create System Configuration:

    a. Create a new directory under hosts/ for your machine:

    mkdir -p hosts/newmachine

    b. Create default.nix in this directory:

    touch hosts/newmachine/default.nix

    c. Add the basic configuration to default.nix:

    For NixOS:

    { inputs, hostname, nixosModules, ... }:
    {
      imports = [
        inputs.hardware.nixosModules.common-cpu-amd
        ./hardware-configuration.nix
        "${nixosModules}/common"
        "${nixosModules}/programs/hyprland"
      ];
    
      networking.hostName = hostname;
    }

    For nix-darwin:

    { config, pkgs, ... }:
    {
      # Add machine-specific configurations here
    }

    d. For NixOS, generate hardware-configuration.nix:

    sudo nixos-generate-config --show-hardware-config > hosts/newmachine/hardware-configuration.nix
  3. Create Home Manager Configuration:

    a. Create a new directory for the user's host-specific configuration:

    mkdir -p home/newuser/newmachine
    touch home/newuser/newmachine/default.nix

    b. Add basic home configuration:

    { nhModules, ... }:
    {
      imports = [
        "${nhModules}/common"
        "${nhModules}/programs/neovim"
        "${nhModules}/services/waybar"
      ];
    }
  4. Building and Applying Configurations:

    a. Commit new files to git:

    git add .

    b. Build and switch to the new system configuration:

    For NixOS:

    sudo nixos-rebuild switch --flake .#newmachine

    For nix-darwin (requires Nix and nix-darwin installation first):

    darwin-rebuild switch --flake .#newmachine

    c. Build and switch to the new Home Manager configuration:

Important

On fresh systems, bootstrap Home Manager first:

nix-shell -p home-manager
home-manager switch --flake .#newuser@newmachine

After this initial setup, you can rebuild configurations separately and home-manager will be available without additional steps

Updating Flakes

To update all flake inputs to their latest versions:

nix flake update

Modules and Configurations

System Modules (in modules/nixos/)

  • common/: Common system configurations
  • programs/corectrl.nix: CoreCtrl for AMD GPU management
  • programs/hyprland.nix: Hyprland window manager
  • programs/steam.nix: Steam gaming platform
  • services/gnome.nix: GNOME desktop environment
  • services/tlp.nix: Laptop power management

Home Manager Modules (in modules/home-manager/)

  1. Core Utilities:

    • common/: Cross-platform base configuration
    • programs/git.nix: Git version control
    • programs/neovim.nix: Neovim text editor
    • programs/zsh.nix: Zsh shell configuration
  2. Desktop Environment:

    • programs/hyprland/: Hyprland window manager setup
    • services/waybar/: Custom status bar configuration
    • services/swaync/: Notification center setup
  3. Development:

    • programs/go.nix: Go development environment
    • programs/krew.nix: Kubernetes plugin manager
    • scripts/: Collection of development utilities
  4. macOS Specific:

    • programs/aerospace.nix: macOS window management

Contributing

Contributions are welcome! If you have improvements or suggestions, please open an issue or submit a pull request.

License

This repository is licensed under MIT License. Feel free to use, modify, and distribute according to the license terms.

About

NixOS, Nix-Darwin and home-manager configurations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published