How to Install NixOS From Scratch (2026 Edition) | Flakes + Home Manager Full Guide
NixOS Installation and Configuration with Flakes and Home Manager (2026 Edition)
This guide provides a comprehensive walkthrough of installing and configuring NixOS from scratch, emphasizing the use of Nix Flakes and Home Manager from the very beginning. It is presented as a standalone tutorial, though it builds upon previous NixOS content.
---
1. Summary
This video demonstrates a modern approach to installing NixOS, integrating Nix Flakes and Home Manager during the initial setup. It covers the entire process from booting the ISO, partitioning disks, and generating configuration files, to creating a foundational flake structure and a minimal `home.nix` file. The guide then proceeds to install NixOS using these flake configurations, followed by setting up essential components like X server, fonts, and core applications. Finally, it details how to manage dotfiles and application configurations using Home Manager, culminating in a customized and functional NixOS environment.
---
2. Key Takeaways
* **Early Integration of Flakes and Home Manager:** The tutorial emphasizes starting with Flakes and Home Manager *before* the initial NixOS system build, streamlining configuration and reproducibility.
* **Reproducible NixOS Installation:** Utilizing Flakes allows for a reproducible and declarative NixOS installation process.
* **Declarative Dotfile Management:** Home Manager is used to declaratively manage user-specific configurations and dotfiles, making them easy to track and replicate.
* **System-Level vs. User-Level Configuration:** The guide clearly distinguishes between NixOS system configuration (e.g., `configuration.nix`) and user-level configuration managed by Home Manager (e.g., `home.nix`).
* **`mkOutOfStoreSymLink`:** A custom function (`mkOutOfStoreSymLink`) is introduced for managing symlinks to configuration files that reside outside the Nix store.
* **`mapAttrs` for Efficient Configuration:** The `mapAttrs` function is demonstrated as a powerful tool for cleaning up and organizing Home Manager configurations.
---
3. Detailed Notes
#### 3.1. Introduction & Setup
* **0:00 - Intro:** Overview of the tutorial's goal: a quick and painless NixOS installation with Flakes and Home Manager from the start.
* **0:40 - Download and Boot into ISO:**
* Download the latest NixOS ISO image.
* Create a bootable USB drive (e.g., using `dd` or Rufus).
* Boot from the USB drive.
* **1:25 - Partition Disks:**
* Use a tool like `fdisk` or `parted` to partition the target drive.
* Recommended partitions:
* EFI System Partition (ESP)
* Root partition (`/`)
* Swap partition (optional, but recommended)
* Home partition (optional, for separating user data)
* **2:32 - Make and Mount File Systems:**
* Format the created partitions (e.g., ext4 for root/home, FAT32 for ESP).
* Mount the root partition to `/mnt`.
* Create necessary mount points (e.g., `/mnt/boot`, `/mnt/home`) and mount other partitions.
* Ensure the ESP is mounted at `/mnt/boot`.
#### 3.2. Initial NixOS Configuration Generation
* **3:39 - Generate NixOS Config Files:**
* Run `nixos-generate-config --root /mnt` to create a basic NixOS configuration structure in `/mnt/etc/nixos/`.
* **4:11 - Create Flake and Home Files:**
* **Crucial Step:** Before rebuilding, create the `flake.nix` and `home.nix` files. This is the core of the "from scratch with Flakes" approach.
* Navigate to a working directory (e.g., `/mnt/etc/nixos`).
* Create `flake.nix` and `home.nix`.
* **5:20 - Create `flake.nix` File:**
* Define the structure of your NixOS configuration.
* `inputs`: Specifies dependencies, including `nixpkgs` (and potentially `home-manager` directly if not using a NixOS module).
* `outputs`: Defines how the flake produces outputs, such as `nixosConfigurations` for system configurations.
* Example structure:
```nix
{
description = "Tony's NixOS Configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Or a specific branch/tag
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, home-manager, ... }@inputs: {
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; # Or your architecture
specialArgs = { inherit inputs; }; # Pass inputs to modules
modules = [
./configuration.nix # Your main NixOS config
home-manager.nixosModules.home-manager # Integrate Home Manager
{
home-manager = {
extraSpecialArgs = { inherit inputs; }; # Pass inputs to HM
useGlobalPkgs = true; # Use nixpkgs from inputs
useUserPackages = true; # Enable user packages
# Ensure home.username is set here or in configuration.nix
users.users.<yourusername> = import ./home.nix;
};
}
];
};
};
}
```
* **8:30 - Clean Up `configuration.nix`:**
* Remove unnecessary default settings from `/mnt/etc/nixos/configuration.nix`.
* Ensure `imports` only includes your `flake.nix` (or references the flake configuration appropriately).
* Crucially, *ensure the `users.users.<yourusername>` section is handled by Home Manager* rather than `configuration.nix` directly.
#### 3.3. System Setup and Initial Boot
* **10:11 - Setup Xserver:**
* Configure the X server in your `configuration.nix` (or within the flake's modules).
* Include `services.xserver.enable = true;` and potentially your preferred desktop environment or window manager.
* **12:20 - Nerd Font and Experimental Features:**
* Enable experimental features if needed (e.g., for certain package features).
* Install a Nerd Font for better terminal and application display. This is often done via `fonts.packages`.
* **13:13 - Baseline Minimal `home.nix` File:**
* Create a very basic `home.nix` file. This will be expanded later.
* It should define basic user settings and potentially import other configuration files.
* Example:
```nix
{ pkgs, inputs, ... }:
{
home.username = "yourusername"; # Important!
home.stateVersion = "23.11"; # Or your desired NixOS version
# Optional: basic package installations
home.packages = with pkgs; [
git
wget
neofetch
];
# Add more configurations here as you build them
}
```
* **14:16 - Install NixOS with Flake:**
* Navigate to the directory containing `flake.nix` (usually `/mnt/etc/nixos`).
* Run the installation command:
```bash
cd /mnt/etc/nixos
# If you have a separate boot partition mounted at /mnt/boot
nixos-install --flake .#yourhostname --root /mnt
```
* This command tells NixOS to use your flake (`.`) and target a specific configuration (`#yourhostname`) for the installation under `/mnt`.
* **15:44 - First Boot Into System:**
* Reboot the system.
* If successful, you'll boot into a minimal NixOS environment, configured by your flake.
#### 3.4. Managing Dotfiles with Home Manager
* **16:49 - Create Dotfiles Folder:**
* On the newly installed system, create a directory to house your dotfiles (e.g., `~/dotfiles`).
* Clone your dotfiles repository into this directory.
* **18:05 - Add Neovim and Qtile Configs:**
* Place configuration files for your preferred applications (e.g., Neovim, Qtile) within your `~/dotfiles` directory.
* **19:23 - Install Configs with Home Manager:**
* **Refine `home.nix`:** Update your `~/etc/nixos/home.nix` (or wherever it's referenced in your flake) to import your dotfiles.
* **`mkOutOfStoreSymLink` function:**
* Define a helper function in your flake or `home.nix` to create symlinks to files that are *not* managed by Nix directly (i.e., your dotfiles).
* This function ensures that these symlinks are created relative to the user's home directory and are properly managed.
* Example (can be placed in your flake's `lib` or a separate file imported by `home.nix`):
```nix
# In a separate file like ./lib/utils.nix
{ pkgs, ... }:
{
mkOutOfStoreSymLink = { src, dest, owner, ... }:
pkgs.writeShellScript "mk-symlink-${dest}" ''
mkdir -p $(dirname "${dest}")
ln -sf ${src} ${dest}
'';
}
# In home.nix
{ pkgs, inputs, ... }:
let
cfg = import ./home.nix; # assuming home.nix is structured like this
mkOutOfStoreSymLink = inputs.self.lib.mkOutOfStoreSymLink; # or import from a separate file
in
{
# ...
home.file.".config/nvim/init.vim" = {
source = ./dotfiles/nvim/init.vim;
recursive = true; # If it's a directory
};
# OR using the helper function (more flexible for complex structures)
# home.activationScripts.symlinkDotfiles = pkgs.writeShellScript "symlink-dotfiles" ''
# ${mkOutOfStoreSymLink { src = ./dotfiles/nvim; dest = "$HOME/.config/nvim"; }}
# '';
}
```
* **Home Manager Configuration:** Add entries in `home.nix` to manage application configurations. This can involve:
* Using `home.file` to directly place configuration files.
* Using `home.packages` to install applications.
* Using `programs.<programname>` to configure specific applications.
* **Rebuild:** After updating `home.nix`, run `home-manager switch --flake .#yourusername` (if using flake) or `sudo nixos-rebuild switch --flake .#yourhostname` (if integrating HM into system config).
* **20:51 - Implement `mkOutOfStoreSymLink`:** As shown above, this function is key to symlinking your manually managed dotfiles into their correct locations within the home directory.
* **23:52 - Clean Up `home.nix` Variables:**
* Identify and consolidate common variables or repeated configurations.
* Use Nix's built-in functions to make the `home.nix` more concise.
* **26:22 - Further Cleanup with `mapAttrs`:**
* The `mapAttrs` function is demonstrated as an advanced technique for iterating over attributes (e.g., a list of configuration files) and applying a transformation or creating multiple Home Manager configurations.
* This is particularly useful for managing a large number of dotfiles efficiently.
* Example:
```nix
{ pkgs, ... }:
let
dotfiles = {
nvim = { src = ./dotfiles/nvim; dest = ".config/nvim"; };
qtile = { src = ./dotfiles/qtile; dest = ".config/qtile"; };
# ... more dotfiles
};
in
{
# ...
home.activationScripts.symlinkDotfiles = pkgs.writeShellScript "symlink-dotfiles" ''
${pkgs.lib.mapAttrs (name: val: ''
echo "Linking ${val.dest}"
mkdir -p $(dirname $HOME/${val.dest})
ln -sf ${pkgs.src/${val.src}} $HOME/${val.dest}
'') dotfiles}
'';
# Or for individual files managed by home.file:
# home.file = pkgs.lib.mapAttrs' (name: val: {
# name = val.dest;
# value = {
# source = val.src;
# target = "$HOME/${val.dest}"; # Or relative path
# };
# }) dotfiles;
}
```
* **29:13 - Obligatory Neofetch:** A quick demonstration of Neofetch to show system information and confirm the setup.
---
This comprehensive guide provides a robust foundation for a declarative and reproducible NixOS system, starting with the most modern Nix tooling.
Related Summaries
Why this video matters
This video provides valuable insights into the topic. Our AI summary attempts to capture the core message, but for the full nuance and context, we highly recommend watching the original video from the creator.
Disclaimer: This content is an AI-generated summary of a public YouTube video. The views and opinions expressed in the original video belong to the content creator. YouTube Note is not affiliated with the video creator or YouTube.

![[캡컷PC]0015-복합클립만들기분리된영상 하나로 만들기](https://img.youtube.com/vi/qtUfil0xjCs/mqdefault.jpg)
