1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 19:49:45 +01:00
This commit is contained in:
rycee 2023-03-14 22:12:30 +00:00
parent ee7b9f1637
commit 96ed3a09b2
3 changed files with 42 additions and 21 deletions

View file

@ -128,10 +128,14 @@ instead use the global <code class="literal">pkgs</code> that is configured via
<code class="literal">nixpkgs</code> options, set</p><pre class="programlisting nix">home-manager.useGlobalPkgs = true;</pre><p>This saves an extra Nixpkgs evaluation, adds consistency, and removes
the dependency on <code class="literal">NIX_PATH</code>, which is otherwise used for importing
Nixpkgs.</p></div><p>Once installed you can see <a class="xref" href="index.html#ch-usage" title="Chapter 2. Using Home Manager">Chapter 2, <em>Using Home Manager</em></a> for a more detailed
description of Home Manager and how to use it.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ch-usage"></a>Chapter 2. Using Home Manager</h1></div></div></div><p>Your use of Home Manager is centered around the configuration file, which is typically found at <code class="literal">~/.config/nixpkgs/home.nix</code>.</p><p>This configuration file can be <span class="emphasis"><em>built</em></span> and <span class="emphasis"><em>activated</em></span>.</p><p>Building a configuration produces a directory in the Nix store that contains all files and programs that should be available in your home directory and Nix user profile, respectively. The build step also checks that the configuration is valid and it will fail with an error if you, for example, assign a value to an option that does not exist or assign a value of the wrong type. Some modules also have custom assertions that perform more detailed, module specific, checks.</p><p>Concretely, if your configuration contains</p><pre class="programlisting nix">programs.emacs.enable = "yes";</pre><p>then building it, for example using <code class="literal">home-manager build</code>, will result in an error message saying something like</p><pre class="programlisting console">$ home-manager build
description of Home Manager and how to use it.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ch-usage"></a>Chapter 2. Using Home Manager</h1></div></div></div><p>Your use of Home Manager is centered around the configuration file,
which is typically found at <code class="literal">~/.config/home-manager/home.nix</code> in the standard installation
or <code class="literal">~/.config/home-manager/flake.nix</code> in a Nix flake based installation.</p><div class="note"><h3 class="title">Note</h3><p>The default configuration used to be placed in <code class="literal">~/.config/nixpkgs</code>¸
so you may see references to that elsewhere.
The old directory still works but Home Manager will print a warning message when used.</p></div><p>This configuration file can be <span class="emphasis"><em>built</em></span> and <span class="emphasis"><em>activated</em></span>.</p><p>Building a configuration produces a directory in the Nix store that contains all files and programs that should be available in your home directory and Nix user profile, respectively. The build step also checks that the configuration is valid and it will fail with an error if you, for example, assign a value to an option that does not exist or assign a value of the wrong type. Some modules also have custom assertions that perform more detailed, module specific, checks.</p><p>Concretely, if your configuration contains</p><pre class="programlisting nix">programs.emacs.enable = "yes";</pre><p>then building it, for example using <code class="literal">home-manager build</code>, will result in an error message saying something like</p><pre class="programlisting console">$ home-manager build
error: A definition for option `programs.emacs.enable' is not of type `boolean'. Definition values:
- In `/home/jdoe/.config/nixpkgs/home.nix': "yes"
(use '--show-trace' to show detailed location information)</pre><p>The message indicates that you must provide a Boolean value for this option, that is, either <code class="literal">true</code> or <code class="literal">false</code>. The documentation of each option will state the expected type, for <a class="xref" href="options.html#opt-programs.emacs.enable"><code class="option">programs.emacs.enable</code></a> you will see “Type: boolean”. You there also find information about the default value and a description of the option. You can find the complete option documentation in <a class="xref" href="options.html" title="Appendix A. Configuration Options">Appendix A, <em>Configuration Options</em></a> or directly in the terminal by running</p><pre class="programlisting console">man home-configuration.nix</pre><p>Once a configuration is successfully built, it can be activated. The activation performs the steps necessary to make the files, programs, and services available in your user environment. The <code class="literal">home-manager switch</code> command performs a combined build and activation.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec-usage-configuration"></a>2.1. Configuration Example</h2></div></div></div><p>A fresh install of Home Manager will generate a minimal <code class="literal">~/.config/nixpkgs/home.nix</code> file containing something like</p><pre class="programlisting nix">{ config, pkgs, ... }:
- In `/home/jdoe/.config/home-manager/home.nix': "yes"
(use '--show-trace' to show detailed location information)</pre><p>The message indicates that you must provide a Boolean value for this option, that is, either <code class="literal">true</code> or <code class="literal">false</code>. The documentation of each option will state the expected type, for <a class="xref" href="options.html#opt-programs.emacs.enable"><code class="option">programs.emacs.enable</code></a> you will see “Type: boolean”. You there also find information about the default value and a description of the option. You can find the complete option documentation in <a class="xref" href="options.html" title="Appendix A. Configuration Options">Appendix A, <em>Configuration Options</em></a> or directly in the terminal by running</p><pre class="programlisting console">man home-configuration.nix</pre><p>Once a configuration is successfully built, it can be activated. The activation performs the steps necessary to make the files, programs, and services available in your user environment. The <code class="literal">home-manager switch</code> command performs a combined build and activation.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec-usage-configuration"></a>2.1. Configuration Example</h2></div></div></div><p>A fresh install of Home Manager will generate a minimal <code class="literal">~/.config/home-manager/home.nix</code> file containing something like</p><pre class="programlisting nix">{ config, pkgs, ... }:
{
# Home Manager needs a bit of information about you and the
@ -327,13 +331,13 @@ and <code class="literal">nixpkgs</code> url to <code class="literal">github:Nix
The Home Manager library is exported by the flake under
<code class="literal">lib.hm</code>.
</li><li class="listitem">
You can use the above <code class="literal">flake.nix</code> as a template in <code class="literal">~/.config/nixpkgs</code> by
</li></ul></div><pre class="programlisting console">$ nix flake new ~/.config/nixpkgs -t github:nix-community/home-manager</pre></div></li><li class="listitem"><p class="simpara">
You can use the above <code class="literal">flake.nix</code> as a template in <code class="literal">~/.config/home-manager</code> by
</li></ul></div><pre class="programlisting console">$ nix flake new ~/.config/home-manager -t github:nix-community/home-manager</pre></div></li><li class="listitem"><p class="simpara">
Install Home Manager and apply the configuration by
</p><pre class="programlisting console">$ nix run &lt;flake-uri&gt;#homeConfigurations.jdoe.activationPackage</pre><p class="simpara">Substitute <code class="literal">&lt;flake-uri&gt;</code> with the flake URI of the configuration flake.
If <code class="literal">flake.nix</code> resides in <code class="literal">~/.config/nixpkgs</code>,
<code class="literal">&lt;flake-uri&gt;</code> may be <code class="literal">~/.config/nixpkgs</code>
as a Git tree or <code class="literal">path:~/.config/nixpkgs</code> if not.</p></li><li class="listitem"><p class="simpara">
If <code class="literal">flake.nix</code> resides in <code class="literal">~/.config/home-manager</code>,
<code class="literal">&lt;flake-uri&gt;</code> may be <code class="literal">~/.config/home-manager</code>
as a Git tree or <code class="literal">path:~/.config/home-manager</code> if not.</p></li><li class="listitem"><p class="simpara">
Since the release <code class="literal">21.05</code>,
building a flake-based configuration is as simple as
</p><pre class="programlisting console">$ home-manager switch --flake '&lt;flake-uri&gt;#jdoe'</pre><p class="simpara">once home-manager is installed.</p><p class="simpara">Here, <code class="literal">jdoe</code> is a configuration specified in the flake file,
@ -602,7 +606,10 @@ error: build of /nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-user-environment.
<code class="literal">rhea-jane.nix</code>, and
</li><li class="listitem">
<code class="literal">common.nix</code>
</li></ul></div><p>in your repository. On the kronos and rhea machines you can then make <code class="literal">~jane/.config/nixpkgs/home.nix</code> be a symbolic link to the corresponding file in your configuration repository.</p><p>The <code class="literal">kronos-jane.nix</code> and <code class="literal">rhea-jane.nix</code> files follow the format</p><pre class="programlisting nix">{ ... }:
</li></ul></div><p>in your repository.
On the kronos and rhea machines you can then make
<code class="literal">~jane/.config/home-manager/home.nix</code>
be a symbolic link to the corresponding file in your configuration repository.</p><p>The <code class="literal">kronos-jane.nix</code> and <code class="literal">rhea-jane.nix</code> files follow the format</p><pre class="programlisting nix">{ ... }:
{
imports = [ ./common.nix ];

File diff suppressed because one or more lines are too long

View file

@ -94,7 +94,9 @@
}
]</p></div></div><div class="refsection"><a id="id-1.13.2.4"></a><h2>Description</h2><p>
This command updates the user environment so that it corresponds to the
configuration specified in <code class="filename">~/.config/nixpkgs/home.nix</code> or <code class="filename">~/.config/nixpkgs/flake.nix</code>.
configuration specified in
<code class="filename">$XDG_CONFIG_HOME/home-manager/home.nix</code> or
<code class="filename">$XDG_CONFIG_HOME/home-manager/flake.nix</code>.
</p><p>
All operations using this tool expects a sub-command that indicates the
operation to perform. It must be one of
@ -157,8 +159,8 @@
remove packages installed through Home Manager from the user profile,
and
</p></li><li class="listitem"><p>
optionally remove all Home Manager generations and make them
available for immediate garbage collection.
remove all Home Manager generations and make them available
for immediate garbage collection.
</p></li></ul></div><p>
</p></dd></dl></div><p>
</p></div><div class="refsection"><a id="id-1.13.2.5"></a><h2>Options</h2><p>
@ -206,7 +208,7 @@
<code class="option">--file <em class="replaceable"><code>path</code></em></code>
</span></dt><dd><p>
Indicates the path to the Home Manager configuration file. If not given,
<code class="filename">$XDG_CONFIG_HOME/nixpkgs/home.nix</code> is used.
<code class="filename">$XDG_CONFIG_HOME/home-manager/home.nix</code> is used.
</p></dd><dt><span class="term">
<code class="option">-h</code>
, </span><span class="term">