mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-08-19 00:45:58 +02:00
feat: home manager vs nixos
This commit is contained in:
@@ -22,12 +22,15 @@ The following are classic Nix commands and associated concepts that are no longe
|
||||
1. In Flakes, the functionality of `nix-channel` is entirely replaced by the `inputs` section in `flake.nix`.
|
||||
2. `nix-env`: `nix-env` is a core command-line tool for classic Nix used to manage software packages in the user environment.
|
||||
1. It installs packages from the data sources added by `nix-channel`, causing the installed package's version to be influenced by the channel. Packages installed with `nix-env` are not automatically recorded in Nix's declarative configuration and are completely independent of its control, making them challenging to reproduce on other machines. Therefore, it is not recommended to use this tool.
|
||||
2. The corresponding command in Flakes is `nix profile`, which is also not recommended for use.
|
||||
2. The corresponding command in Flakes is `nix profile`. Personally, I don't recommend it either.
|
||||
3. `nix-shell`: `nix-shell` creates a temporary shell environment, which is useful for development and testing.
|
||||
1. In Flakes, this tool is divided into three sub-commands: `nix develop`, `nix shell`, and `nix run`. We will discuss these three commands in detail in the "[Development](../development/intro.md)" chapter.
|
||||
4. `nix-build`: `nix-build` builds Nix packages and places the build results in `/nix/store`, but it does not record them in Nix's declarative configuration.
|
||||
1. In Flakes, `nix-build` is replaced by `nix build`.
|
||||
5. ...
|
||||
5. `nix-collect-garbage`: Garbage collection command used to clean up unused Store Objects in `/nix/store`.
|
||||
1. In Nix Flakes, the corresponding command is `nix store gc --debug`.
|
||||
6. And other less commonly used commands are not listed here.
|
||||
1. You can refer to the detailed command comparison list in [Try to explain nix commands](https://qiita.com/Sumi-Sumi/items/6de9ee7aab10bc0dbead?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en).
|
||||
|
||||
> NOTE: `nix-env -qa` may still be useful in some cases, as it returns all packages installed in the system.
|
||||
|
||||
|
@@ -221,3 +221,19 @@ To find the options we can use in `home.nix`, referring to the following documen
|
||||
- [Home Manager - Appendix A. Configuration Options](https://nix-community.github.io/home-manager/options.html): A list of all options, it is recommended to search for keywords in it.
|
||||
- [Home Manager Option Search](https://mipmip.github.io/home-manager-option-search/) is another option search tool with better UI.
|
||||
- [home-manager](https://github.com/nix-community/home-manager): Some options are not listed in the official documentation, or the documentation is not clear enough, you can directly search and read the corresponding source code in this home-manager repo.
|
||||
|
||||
## Home Manager vs NixOS
|
||||
|
||||
When it comes to managing software packages and configurations, you often have the choice of using either NixOS modules (`configuration.nix`) or Home Manager (`home.nix`). This poses a dilemma: **What are the differences between putting packages or configuration files in NixOS modules versus Home Manager configurations, and how should you decide?**
|
||||
|
||||
First, let's understand the differences. Packages and configuration files installed through NixOS modules are global to the entire system. Global configurations are typically stored in `/etc`, and globally installed packages are linked accordingly. Regardless of the user you switch to, you can access and use these packages and configurations.
|
||||
|
||||
On the other hand, everything installed through Home Manager is specific to the corresponding user. Once you switch to another user, those configurations and packages become unavailable.
|
||||
|
||||
Based on these characteristics, here is a general recommended approach:
|
||||
|
||||
- NixOS modules: Install core system components and other software packages required by almost all users, including the root user.
|
||||
- For example, if you want a package to be accessible even when you switch to the root user, or if you want a configuration to take effect for the root user as well, you should install it through a NixOS module.
|
||||
- Home Manager: Use Home Manager to install all other configurations and software specific to individual users.
|
||||
|
||||
In summary, NixOS modules are suitable for installing system-wide components and packages that need to be accessible to multiple users, while Home Manager is ideal for managing user-specific configurations and software.
|
||||
|
Reference in New Issue
Block a user