<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>Home Manager Manual</title><linkrel="stylesheet"type="text/css"href="style.css"/><linkrel="stylesheet"type="text/css"href="overrides.css"/><linkrel="stylesheet"type="text/css"href="mono-blue.css"/><scriptsrc="highlight.pack.js"type="text/javascript"></script><scriptsrc="highlight.load.js"type="text/javascript"></script><metaname="generator"content="DocBook XSL Stylesheets V1.79.2"/><linkrel="home"href="index.html"title="Home Manager Manual"/><linkrel="next"href="options.html"title="AppendixA.Configuration Options"/></head><body><divclass="navheader"><tablewidth="100%"summary="Navigation header"><tr><thcolspan="3"align="center">Home Manager Manual</th></tr><tr><tdwidth="20%"align="left"></td><thwidth="60%"align="center"></th><tdwidth="20%"align="right"><aaccesskey="n"href="options.html">Next</a></td></tr></table><hr/></div><divclass="book"><divclass="titlepage"><div><div><h1class="title"><aid="book-home-manager-manual"></a>Home Manager Manual</h1></div></div><hr/></div><divclass="toc"><dlclass="toc"><dt><spanclass="preface"><ahref="index.html#idm140737328863152">Preface</a></span></dt><dt><spanclass="chapter"><ahref="index.html#ch-installation">1. Installing Home Manager</a></span></dt><dd><dl><dt><spanclass="section"><ahref="index.html#sec-install-standalone">1.1. Standalone installation</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-install-nixos-module">1.2. NixOS module</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-install-nix-darwin-module">1.3. nix-darwin module</a></span></dt></dl></dd><dt><spanclass="chapter"><ahref="index.html#ch-writing-modules">2. Writing Home Manager Modules</a></span></dt><dd><dl><dt><spanclass="section"><ahref="index.html#sec-option-types">2.1. Option Types</a></span></dt></dl></dd><dt><spanclass="chapter"><ahref="index.html#ch-contributing">3. Contributing</a></span></dt><dd><dl><dt><spanclass="section"><ahref="index.html#sec-contrib-getting-started">3.1. Getting started</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines">3.2. Guidelines</a></span></dt><dd><dl><dt><spanclass="section"><ahref="index.html#sec-guidelines-back-compat">3.2.1. Maintain backward compatibility</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-forward-compat">3.2.2. Keep forward compatibility in mind</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-valuable-options">3.2.3. Add only valuable options</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-add-tests">3.2.4. Add relevant tests</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-module-maintainer">3.2.5. Add relevant documentation</a></span></dt><dt><spanclass="section"><ahref="index.html#_add_yourself_as_a_module_maintainer">3.2.6. Add yourself as a module maintainer</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-code-style">3.2.7. Format your code</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-commit-message-style">3.2.8. Format your commit messages</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-news-style">3.2.9. Format your news entries</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-conditional-modules">3.2.10. Use conditional modules and news</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-guidelines-licensing">3.2.11. Mind the license</a></span></dt></dl></dd><dt><spanclass="section"><ahref="index.html#sec-commit-style">3.3. Commits</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-code-style">3.4. Code Style</a></span></dt><dt><spanclass="section"><ahref="index.html#sec-news">3.5. News</a></span></dt><dt><spanclass="section"
</a></span><spanclass="refpurpose"> — reconfigure a user environment</span></dt></dl></dd><dt><spanclass="appendix"><ahref="release-notes.html">C. Release Notes</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-21.03">C.1. Release 21.03</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-21.03-highlights">C.1.1. Highlights</a></span></dt><dt><spanclass="section"><ahref="release-notes.html#sec-release-21.03-state-version-changes">C.1.2. State Version Changes</a></span></dt></dl></dd><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.09">C.2. Release 20.09</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.09-highlights">C.2.1. Highlights</a></span></dt><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.09-state-version-changes">C.2.2. State Version Changes</a></span></dt></dl></dd><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.03">C.3. Release 20.03</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.03-highlights">C.3.1. Highlights</a></span></dt><dt><spanclass="section"><ahref="release-notes.html#sec-release-20.03-state-version-changes">C.3.2. State Version Changes</a></span></dt></dl></dd><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.09">C.4. Release 19.09</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.09-highlights">C.4.1. Highlights</a></span></dt><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.09-state-version-changes">C.4.2. State Version Changes</a></span></dt></dl></dd><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.03">C.5. Release 19.03</a></span></dt><dd><dl><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.03-highlights">C.5.1. Highlights</a></span></dt><dt><spanclass="section"><ahref="release-notes.html#sec-release-19.03-state-version-changes">C.5.2. State Version Changes</a></span></dt></dl></dd><dt><spanclass="section"><ahref="release-notes.html#sec-release-18.09">C.6. Release 18.09</a></span></dt></dl></dd></dl></div><divclass="preface"><divclass="titlepage"><div><div><h1class="title"><aid="idm140737328863152"></a>Preface</h1></div></div></div><p>
Commands prefixed with <codeclass="literal">#</code> have to be run as root, either
requiring to login as root user or temporarily switching to it using
<codeclass="literal">sudo</code> for example.
</p></div></div><divclass="chapter"><divclass="titlepage"><div><div><h1class="title"><aid="ch-installation"></a>Chapter1.Installing Home Manager</h1></div></div></div><p>
Using the standalone <spanclass="command"><strong>home-manager</strong></span> tool. For platforms
other than NixOS and Darwin, this is the only available choice. It is also
recommended for people on NixOS or Darwin that want to manage their home
directory independent of the system as a whole. See
<aclass="xref"href="index.html#sec-install-standalone"title="1.1.Standalone installation">Section1.1, “Standalone installation”</a> for instructions on how to
perform this installation.
</p></li><liclass="listitem"><p>
As a module within a NixOS system configuration. This allows the user
profiles to be built together with the system when running
<spanclass="command"><strong>nixos-rebuild</strong></span>. See
<aclass="xref"href="index.html#sec-install-nixos-module"title="1.2.NixOS module">Section1.2, “NixOS module”</a> for a description of this
system configuration. This allows the user profiles to be built together
with the system when running <spanclass="command"><strong>darwin-rebuild</strong></span>. See
<aclass="xref"href="index.html#sec-install-nix-darwin-module"title="1.3.nix-darwin module">Section1.3, “nix-darwin module”</a> for a description of this
By default, Home Manager uses a private <codeclass="literal">pkgs</code> instance
that is configured via the <codeclass="option">home-manager.users.<name>.nixpkgs</code> options.
To instead use the global <codeclass="literal">pkgs</code> that is configured via
the system level <codeclass="option">nixpkgs</code> options, set
</p><preclass="programlisting nix">
home-manager.useGlobalPkgs = true;
</pre><p>
This saves an extra Nixpkgs evaluation, adds consistency, and removes the
dependency on <codeclass="envar">NIX_PATH</code>, which is otherwise used for
importing Nixpkgs.
</p></div></div></div><divclass="chapter"><divclass="titlepage"><div><div><h1class="title"><aid="ch-writing-modules"></a>Chapter2.Writing Home Manager Modules</h1></div></div></div><p>The module system in Home Manager is based entirely on the NixOS module system so we will here only highlight aspects that are specific for Home Manager. For information about the module system as such please refer to the <aclass="link"href="https://nixos.org/nixos/manual/index.html#sec-writing-modules"target="_top">Writing NixOS Modules</a> chapter of the NixOS manual.</p><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-option-types"></a>2.1.Option Types</h2></div></div></div><p>Overall the basic option types are the same in Home Manager as NixOS. A few Home Manager options, however, make use of custom types that are worth describing in more detail. These are the option types <codeclass="literal">dagOf</code> and <codeclass="literal">gvariant</code> that are used, for example, by <aclass="xref"href="options.html#opt-programs.ssh.matchBlocks"><codeclass="option">programs.ssh.matchBlocks</code></a> and <aclass="xref"href="options.html#opt-dconf.settings"><codeclass="option">dconf.settings</code></a>.</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term">
<codeclass="literal">hm.types.dagOf</code>
</span></dt><dd><pclass="simpara">
Options of this type have attribute sets as values where each member is a node in a <aclass="link"href="https://en.wikipedia.org/w/index.php?title=Directed_acyclic_graph&oldid=939656095"target="_top">directed acyclic graph</a> (DAG). This allows the attribute set entries to express dependency relations among themselves. This can, for example, be used to control the order of match blocks in a OpenSSH client configuration or the order of activation script blocks in <aclass="xref"href="options.html#opt-home.activation"><codeclass="option">home.activation</code></a>.
</p><pclass="simpara">A number of functions are provided to create DAG nodes. The functions are shown below with examples using an option <codeclass="literal">foo.bar</code> of type <codeclass="literal">hm.types.dagOf types.int</code>.</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term">
Indicates that <codeclass="literal">value</code> can be placed anywhere within the DAG. This is also the default for plain attribute set entries, that is
<codeclass="literal">hm.dag.entryAfter (afters: list string) (value: T)</code>
</span></dt><dd><pclass="simpara">
Indicates that <codeclass="literal">value</code> must be placed <spanclass="emphasis"><em>after</em></span> each of the attribute names in the given list. For example
</p><preclass="programlisting nix">foo.bar = {
a = 0;
b = hm.dag.entryAfter [ "a" ] 1;
}</pre><pclass="simpara">would place <codeclass="literal">b</code> after <codeclass="literal">a</code> in the graph.</p></dd><dt><spanclass="term">
<codeclass="literal">hm.dag.entryBefore (befores: list string) (value: T)</code>
</span></dt><dd><pclass="simpara">
Indicates that <codeclass="literal">value</code> must be placed <spanclass="emphasis"><em>before</em></span> each of the attribute names in the given list. For example
</p><preclass="programlisting nix">foo.bar = {
b = hm.dag.entryBefore [ "a" ] 1;
a = 0;
}</pre><pclass="simpara">would place <codeclass="literal">b</code> before <codeclass="literal">a</code> in the graph.</p></dd><dt><spanclass="term">
<codeclass="literal">hm.dag.entryBetween (befores: list string) (afters: list string) (value: T)</code>
</span></dt><dd><pclass="simpara">
Indicates that <codeclass="literal">value</code> must be placed <spanclass="emphasis"><em>before</em></span> the attribute names in the first list and <spanclass="emphasis"><em>after</em></span> the attribute names in the second list. For example
</p><preclass="programlisting nix">foo.bar = {
a = 0;
c = hm.dag.entryBetween [ "b" ] [ "a" ] 2;
b = 1;
}</pre><pclass="simpara">would place <codeclass="literal">c</code> before <codeclass="literal">b</code> and after <codeclass="literal">a</code> in the graph.</p></dd></dl></div></dd><dt><spanclass="term">
<codeclass="literal">hm.types.gvariant</code>
</span></dt><dd><pclass="simpara">
This type is useful for options representing <aclass="link"href="https://developer.gnome.org/glib/stable/glib-GVariant.html#glib-GVariant.description"target="_top">GVariant</a> values. The type accepts all primitive GVariant types as well as arrays and tuples. Dictionaries are not currently supported.
</p><pclass="simpara">To create a GVariant value you can use a number of provided functions. Examples assume an option <codeclass="literal">foo.bar</code> of type <codeclass="literal">hm.types.gvariant</code>.</p><divclass="variablelist"><dlclass="variablelist"><dt><spanclass="term">
Takes a Nix value <codeclass="literal">v</code> to a GVariant <codeclass="literal">boolean</code> value. Note, Nix booleans are automatically coerced using this function. That is,
Takes a Nix value <codeclass="literal">v</code> to a GVariant <codeclass="literal">string</code> value. Note, Nix strings are automatically coerced using this function. That is,
</p><preclass="programlisting nix">foo.bar = hm.gvariant.mkString "a string";</pre><pclass="simpara">is equivalent to</p><preclass="programlisting nix">foo.bar = "a string";</pre></dd><dt><spanclass="term">
Takes a Nix value <codeclass="literal">v</code> to a GVariant <codeclass="literal">int32</code> value. Note, Nix integers are automatically coerced using this function. That is,
Takes a Nix value <codeclass="literal">v</code> to a GVariant <codeclass="literal">double</code> value. Note, Nix floats are automatically coerced using this function. That is,
<codeclass="literal">hm.gvariant.mkArray type elements</code>
</span></dt><dd><pclass="simpara">
Builds a GVariant array containing the given list of elements, where each element is a GVariant value of the given type. The <codeclass="literal">type</code> value can be constructed using
</li></ul></div><pclass="simpara">where <codeclass="literal">type</code> and <codeclass="literal">types</code> are themselves a type and list of types, respectively.</p></dd><dt><spanclass="term">
Builds a GVariant maybe value whose (non-existent) element is of the given type. The <codeclass="literal">type</code> value is constructed as described for the <codeclass="literal">mkArray</code> function above.
</dd></dl></div></dd></dl></div></div></div><divclass="chapter"><divclass="titlepage"><div><div><h1class="title"><aid="ch-contributing"></a>Chapter3.Contributing</h1></div></div></div><p>Contributions to Home Manager are very welcome. To make the process as smooth as possible for both you and the Home Manager maintainers we provide some guidelines that we ask you to follow. See <aclass="xref"href="index.html#sec-contrib-getting-started"title="3.1.Getting started">Section3.1, “Getting started”</a> for information on how to set up a suitable development environment and <aclass="xref"href="index.html#sec-guidelines"title="3.2.Guidelines">Section3.2, “Guidelines”</a> for the actual guidelines.</p><p>This text is mainly directed at those who would like to make code contributions to Home Manager. If you just want to report a bug then first look among the already <aclass="link"href="https://github.com/nix-community/home-manager/issues"target="_top">open issues</a>, if you find one matching yours then feel free to comment on it to add any additional information you may have. If no matching issue exists then go to the <aclass="link"href="https://github.com/nix-community/home-manager/issues/new"target="_top">new issue</a> page and write a description of your problem. Include as much information as you can, ideally also include relevant excerpts from your Home Manager configuration.</p><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-contrib-getting-started"></a>3.1.Getting started</h2></div></div></div><p>If you have not previously forked Home Manager then you need to do that first. Have a look at GitHub’s <aclass="link"href="https://help.github.com/articles/fork-a-repo/"target="_top">Fork a repo</a> for instructions on how to do this.</p><p>Once you have a fork of Home Manager you should create a branch starting at the most recent <codeclass="literal">master</code> branch. Give your branch a reasonably descriptive name. Commit your changes to this branch and when you are happy with the result and it fulfills <aclass="xref"href="index.html#sec-guidelines"title="3.2.Guidelines">Section3.2, “Guidelines”</a> then push the branch to GitHub and <aclass="link"href="https://help.github.com/articles/creating-a-pull-request/"target="_top">create a pull request</a>.</p><p>Assuming your clone is at <codeclass="literal">$HOME/devel/home-manager</code> then you can make the <codeclass="literal">home-manager</code> command use it by either</p><divclass="orderedlist"><olclass="orderedlist"type="1"><liclass="listitem"><pclass="simpara">
programs.home-manager.path = "$HOME/devel/home-manager";</pre><pclass="simpara">and running <codeclass="literal">home-manager switch</code> to activate the change. Afterwards, <codeclass="literal">home-manager build</code> and <codeclass="literal">home-manager switch</code> will use your cloned repository.</p></li></ol></div><p>The first option is good if you only temporarily want to use your clone.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-guidelines"></a>3.2.Guidelines</h2></div></div></div><p>If your contribution satisfy the following rules then there is a good chance it will be merged without too much trouble. The rules are enforced by the Home Manager maintainers and to a lesser extent the Home Manager CI system.</p><p>If you are uncertain how these rules affect the change you would like to make then feel free to start a discussion in the <aclass="link"href="https://webchat.freenode.net/?url=irc%3A%2F%2Firc.freenode.net%2Fhome-manager"target="_top">#home-manager</a> IRC channel, ideally before you start developing.</p><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-back-compat"></a>3.2.1.Maintain backward compatibility</h3></div></div></div><p>Your contribution should never cause another user’s existing configuration to break. Home Manager is used in many different environments and you should consider how you change may effect others. For example,</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem">
Does your change work for people that do not use NixOS? Consider other GNU/Linux distributions and macOS.
</li><liclass="listitem">
Does your change work for people whose configuration is built on one system and deployed on another system?
</li></ul></div></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-forward-compat"></a>3.2.2.Keep forward compatibility in mind</h3></div></div></div><p>The master branch of Home Manager tracks the unstable channel of Nixpkgs, which may update package versions at any time. It is therefore important to consider how a package update may affect your code and try to reduce the risk of breakage.</p><p>The most effective way to reduce this risk is to follow the advice in <aclass="xref"href="index.html#sec-guidelines-valuable-options"title="3.2.3.Add only valuable options">Section3.2.3, “Add only valuable options”</a>.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-valuable-options"></a>3.2.3.Add only valuable options</h3></div></div></div><p>When creating a new module it is tempting to include every option supported by the software. This is <spanclass="emphasis"><em>strongly</em></span> discouraged. Providing many options increases maintenance burden and risk of breakage considerably. This is why only the most <aclass="link"href="https://github.com/Infinisil/rfcs/blob/config-option/rfcs/0042-config-option.md#valuable-options"target="_top">important software options</a> should be modeled explicitly. Less important options should be expressible through an <codeclass="literal">extraConfig</code> escape hatch.</p><p>A good rule of thumb for the first implementation of a module is to only add explicit options for those settings that absolutely must be set for the software to function correctly. It follows that a module for software that provides sensible default values for all settings would require no explicit options at all.</p><p>If the software uses a structured configuration format like a JSON, YAML, INI, TOML, or even a plain list of key/value pairs then consider using a <codeclass="literal">settings</code> option as described in <aclass="link"href="https://github.com/Infinisil/rfcs/blob/config-option/rfcs/0042-config-option.md"target="_top">Nix RFC 42</a>.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-add-tests"></a>3.2.4.Add relevant tests</h3></div></div></div><p>If at all possible, make sure to add new tests and expand existing tests so that your change will keep working in the future. See <aclass="xref"href="index.html#sec-tests"title="3.6.Tests">Section3.6, “Tests”</a> for more information about the Home Manager test suite.</p><p>All contributed code <spanclass="emphasis"><em>must</em></span> pass the test suite.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-module-maintainer"></a>3.2.5.Add relevant documentation</h3></div></div></div><p>Many code changes require changing the documentation as well. Module options should be documented with DocBook. See <aclass="link"href="https://docbook.rocks/"target="_top">DocBook rocks!</a> for a quick introduction and <aclass="link"href="https://tdg.docbook.org/"target="_top">DocBook 5: The Definitive Guide</a> for in-depth information of DocBook. Home Manager is itself documented using a combination of DocBook and <aclass="link"href="https://asciidoc.org/"target="_top">AsciiDoc</a>. All text is hosted in Home Manager’s Git repository.</p><p>The HTML version of the manual containing both the module option descriptions and the documentation of Home Manager can be generated and opened by typing the following in a shell within a clone of the Home Manager Git repository:</p><preclass="programlisting console">$ nix-build -A docs.html
$ xdg-open ./result/share/doc/home-manager/index.html</pre><p>When you have made changes to a module, it is a good idea to check that the man page version of the module options looks good:</p><preclass="programlisting console">$ nix-build -A docs.manPages
$ man ./result/share/man/man5/home-configuration.nix.5</pre></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="_add_yourself_as_a_module_maintainer"></a>3.2.6.Add yourself as a module maintainer</h3></div></div></div><p>Every new module <spanclass="emphasis"><em>must</em></span> include a named maintainer using the <codeclass="literal">meta.maintainers</code> attribute. If you are a user of a module that currently lacks a maintainer then please consider adopting it.</p><p>If you are present in the NixOS maintainer list then you can use that entry. If you are not then you can add yourself to <codeclass="literal">modules/lib/maintainers.nix</code> in the Home Manager project.</p><p>Also add yourself to <codeclass="literal">.github/CODEOWNERS</code> as owner of the associated module files, including the test files. You will then be automatically added as a reviewer on any new pull request that touches your files.</p><p>Maintainers are encouraged to join the IRC channel and participate when they have opportunity.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-code-style"></a>3.2.7.Format your code</h3></div></div></div><p>Make sure your code is formatted as described in <aclass="xref"href="index.html#sec-code-style"title="3.4.Code Style">Section3.4, “Code Style”</a>. To maintain consistency throughout the project you are encouraged to browse through existing code and adopt its style also in new code.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-commit-message-style"></a>3.2.8.Format your commit messages</h3></div></div></div><p>Similar to <aclass="xref"href="index.html#sec-guidelines-code-style"title="3.2.7.Format your code">Section3.2.7, “Format your code”</a> we encourage a consistent commit message format as described in <aclass="xref"href="index.html#sec-commit-style"title="3.3.Commits">Section3.3, “Commits”</a>.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-news-style"></a>3.2.9.Format your news entries</h3></div></div></div><p>If your contribution includes a change that should be communicated to users of Home Manager then you can add a news entry. The entry must be formatted as described in <aclass="xref"href="index.html#sec-news"title="3.5.News">Section3.5, “News”</a>.</p><p>When new modules are added a news entry should be included but you do not need to create this entry manually. The merging maintainer will create the entry for you. This is to reduce the risk of merge conflicts.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-conditional-modules"></a>3.2.10.Use conditional modules and news</h3></div></div></div><p>Home Manager includes a number of modules that are only usable on some of the supported platforms. The most common example of platform specific modules are those that define systemd user services, which only works on Linux systems.</p><p>If you add a module that is platform specific then make sure to include a condition in the <codeclass="literal">loadModule</code> function call. This will make the module accessible only on systems where the condition evaluates to <codeclass="literal">true</code>.</p><p>Similarly, if you are adding a news entry then it should be shown only to users that may find it relevant, see <aclass="xref"href="index.html#sec-news"title="3.5.News">Section3.5, “News”</a> for a description of conditional news.</p></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aid="sec-guidelines-licensing"></a>3.2.11.Mind the license</h3></div></div></div><p>The Home Manager project is covered by the MIT license and we can only accept contributions that fall under this license, or are licensed in a compatible way. When you contribute self written code and documentation it is assumed that you are doing so under the MIT license.</p><p>A potentia
{long description}</pre><p>where <codeclass="literal">{component}</code> refers to the code component (or module) your change affects, <codeclass="literal">{description}</code> is a very brief description of your change, and <codeclass="literal">{long description}</code> is an optional clarifying description. Note, <codeclass="literal">{description}</code> should start with a lower case letter. As a rare exception, if there is no clear component, or your change affects many components, then the <codeclass="literal">{component}</code> part is optional. See <aclass="xref"href="index.html#ex-commit-message"title="Example3.1.Compliant commit message">Example3.1, “Compliant commit message”</a> for a commit message that fulfills these requirements.</p><divclass="example"><aid="ex-commit-message"></a><pclass="title"><strong>Example3.1.Compliant commit message</strong></p><divclass="example-contents"><p>The commit <aclass="link"href="https://github.com/nix-community/home-manager/commit/69f8e47e9e74c8d3d060ca22e18246b7f7d988ef"target="_top">69f8e47e9e74c8d3d060ca22e18246b7f7d988ef</a> contains the commit message</p><preclass="screen">starship: allow running in Emacs if vterm is used
without issues.</pre><p>which ticks all the boxes necessary to be accepted in Home Manager.</p></div></div><brclass="example-break"/><p>Finally, when adding a new module, say <codeclass="literal">programs/foo.nix</code>, we use the fixed commit format <codeclass="literal">foo: add module</code>. You can, of course, still include a long description if you wish.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-code-style"></a>3.4.Code Style</h2></div></div></div><p>The code in Home Manager is formatted by the <aclass="link"href="https://github.com/serokell/nixfmt/"target="_top">nixfmt</a> tool and the formatting is checked in the pull request tests. Run the <codeclass="literal">format</code> tool inside the project repository before submitting your pull request.</p><p>Keep lines at a reasonable width, ideally 80 characters or less. This also applies to string literals.</p><p>We prefer <codeclass="literal">lowerCamelCase</code> for variable and attribute names with the accepted exception of variables directly referencing packages in Nixpkgs which use a hyphenated style. For example, the Home Manager option <codeclass="literal">services.gpg-agent.enableSshSupport</code> references the <codeclass="literal">gpg-agent</code> package in Nixpkgs.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-news"></a>3.5.News</h2></div></div></div><p>Home Manager includes a system for presenting news to the user. When making a change you, therefore, have the option to also include an associated news entry. In general, a news entry should only be added for truly noteworthy news. For example, a bug fix or new option does generally not need a news entry.</p><p>If you do have a change worthy of a news entry then please add one in <aclass="link"href="https://github.com/nix-community/home-manager/blob/master/modules/misc/news.nix"target="_top"><codeclass="literal">news.nix</code></a> but you should follow some basic guidelines:</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem"><pclass="simpara">
The entry timestamp should be in ISO-8601 format having "+00:00" as time zone. For example, "2017-09-13T17:10:14+00:00". A suitable timestamp can be produced by the command
</p><preclass="programlisting console">$ date --iso-8601=second --universal</pre></li><liclass="listitem">
The entry condition should be as specific as possible. For example, if you are changing or deprecating a specific option then you could restrict the news to those users who actually use this option.
</li><liclass="listitem">
Wrap the news message so that it will fit in the typical terminal, that is, at most 80 characters wide. Ideally a bit less.
</li><liclass="listitem">
Unlike commit messages, news will be read without any connection to the Home Manager source code. It is therefore important to make the message understandable in isolation and to those who do not have knowledge of the Home Manager internals. To this end it should be written in more descriptive, prose like way.
</li><liclass="listitem"><pclass="simpara">
If you refer to an option then write its full attribute path. That is, instead of writing
</p><preclass="screen">The option 'foo' has been deprecated, please use 'bar' instead.</pre><pclass="simpara">it should read</p><preclass="screen">The option 'services.myservice.foo' has been deprecated, please
use 'services.myservice.bar' instead.</pre></li><liclass="listitem"><pclass="simpara">
A new module, say <codeclass="literal">foo.nix</code>, should always include a news entry that has a message along the lines of
</p><preclass="screen">A new module is available: 'services.foo'.</pre><pclass="simpara">If the module is platform specific, e.g., a service module using systemd, then a condition like</p><preclass="programlisting nix">condition = hostPlatform.isLinux;</pre><pclass="simpara">should be added. If you contribute a module then you don’t need to add this entry, the merger will create an entry for you.</p></li></ul></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="sec-tests"></a>3.6.Tests</h2></div></div></div><p>Home Manager includes a basic test suite and it is highly recommended to include at least one test when adding a module. Tests are typically in the form of "golden tests" where, for example, a generated configuration file is compared to a known correct file.</p><p>It is relatively easy to create tests by modeling the existing tests, found in the <codeclass="literal">tests</code> project directory.</p><p>The full Home Manager test suite can be run by executing</p><preclass="programlisting console">$ nix-shell --pure tests -A run.all</pre><p>in the project root. List all test cases through</p><preclass="programlisting console">$ nix-shell --pure tests -A list</pre><p>and run an individual test, for example <codeclass="literal">alacritty-empty-settings</code>, through</p><preclass="programlisting console">$ nix-shell --pure tests -A run.alacritty-empty-settings</pre></div></div><divclass="chapter"><divclass="titlepage"><div><div><h1class="title"><aid="ch-faq"></a>Chapter4.Frequently Asked Questions (FAQ)</h1></div></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_why_is_there_a_collision_error_when_switching_generation"></a>4.1.Why is there a collision error when switching generation?</h2></div></div></div><p>Home Manager currently installs packages into the user environment, precisely as if the packages were installed through <codeclass="literal">nix-env--install</code>. This means that you will get a collision error if your Home Manager configuration attempts to install a package that you already have installed manually, that is, packages that shows up when you run <codeclass="literal">nix-env--query</code>.</p><p>For example, imagine you have the <codeclass="literal">hello</code> package installed in your environment</p><preclass="programlisting console">$ nix-env --query
hello-2.10</pre><p>and your Home Manager configuration contains</p><preclass="programlisting nix">home.packages = [ pkgs.hello ];</pre><p>Then attempting to switch to this configuration will result in an error similar to</p><preclass="programlisting console">$ home-manager switch
building path(s) ‘/nix/store/b5c0asjz9f06l52l9812w6k39ifr49jj-user-environment’
Wide character in die at /nix/store/64jc9gd2rkbgdb4yjx3nrgc91bpjj5ky-buildenv.pl line 79.
collision between ‘/nix/store/fmwa4axzghz11cnln5absh31nbhs9lq1-home-manager-path/bin/hello’ and ‘/nix/store/c2wyl8b9p4afivpcz8jplc9kis8rj36d-hello-2.10/bin/hello’; use ‘nix-env --set-flag priority NUMBER PKGNAME’ to change the priority of one of the conflicting packages
builder for ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-user-environment.drv’ failed with exit code 2
error: build of ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-user-environment.drv’ failed</pre><p>The solution is typically to uninstall the package from the environment using <codeclass="literal">nix-env--uninstall</code> and reattempt the Home Manager generation switch.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_why_are_the_session_variables_not_set"></a>4.2.Why are the session variables not set?</h2></div></div></div><p>Home Manager is only able to set session variables automatically if it manages your Bash or Z shell configuration. If you don’t want to let Home Manager manage your shell then you will have to manually source the <codeclass="literal">~/.nix-profile/etc/profile.d/hm-session-vars.sh</code> file in an appropriate way. In Bash and Z shell this can be done by adding</p><preclass="programlisting bash">. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"</pre><p>to your <codeclass="literal">.profile</code> and <codeclass="literal">.zshrc</code> files, respectively. The <codeclass="literal">hm-session-vars.sh</code> file should work in most Bourne-like shells.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_how_do_set_up_a_configuration_for_multiple_users_machines"></a>4.3.How do set up a configuration for multiple users/machines?</h2></div></div></div><p>A typical way to prepare a repository of configurations for multiple logins and machines is to prepare one "top-level" file for each unique combination.</p><p>For example, if you have two machines, called "kronos" and "rhea" on which you want to configure your user "jane" then you could create the files</p><divclass="itemizedlist"><ulclass="itemizedlist"style="list-style-type: disc; "><liclass="listitem">
<codeclass="literal">kronos-jane.nix</code>,
</li><liclass="listitem">
<codeclass="literal">rhea-jane.nix</code>, and
</li><liclass="listitem">
<codeclass="literal">common.nix</code>
</li></ul></div><p>in your repository. On the kronos and rhea machines you can then make <codeclass="literal">~jane/.config/nixpkgs/home.nix</code> be a symbolic link to the corresponding file in your configuration repository.</p><p>The <codeclass="literal">kronos-jane.nix</code> and <codeclass="literal">rhea-jane.nix</code> files follow the format</p><preclass="programlisting nix">{ ... }:
{
imports = [ ./common.nix ];
# Various options that are specific for this machine/user.
}</pre><p>while the <codeclass="literal">common.nix</code> file contains configuration shared across the two logins. Of course, instead of just a single <codeclass="literal">common.nix</code> file you can have multiple ones, even one per program or service.</p><p>You can get some inspiration from the <aclass="link"href="https://www.reddit.com/r/NixOS/comments/9bb9h9/post_your_homemanager_homenix_file/"target="_top">Post your home-manager home.nix file!</a> Reddit thread.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_why_do_i_get_an_error_message_about_literal_ca_desrt_dconf_literal"></a>4.4.Why do I get an error message about <codeclass="literal">ca.desrt.dconf</code>?</h2></div></div></div><p>You are most likely trying to configure the GTK or Gnome Terminal but the DBus session is not aware of the dconf service. The full error you might get is</p><preclass="screen">error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name ca.desrt.dconf was not provided by any .service files</pre><p>The solution on NixOS is to add</p><preclass="programlisting nix">services.dbus.packages = with pkgs; [ gnome3.dconf ];</pre><p>to your system configuration.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_how_do_i_install_packages_from_nixpkgs_unstable"></a>4.5.How do I install packages from Nixpkgs unstable?</h2></div></div></div><p>If you are using a stable version of Nixpkgs but would like to install some particular packages from Nixpkgs unstable – or some other channel – then you can import the unstable Nixpkgs and refer to its packages within your configuration. Something like</p><preclass="programlisting nix">{ pkgs, config, ... }:
}</pre><p>should work provided you have a Nix channel called <codeclass="literal">nixpkgs-unstable</code>.</p><p>You can add the <codeclass="literal">nixpkgs-unstable</code> channel by running</p><preclass="programlisting console"># nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
# nix-channel --update</pre><p>Note, the package will not be affected by any package overrides, overlays, etc.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aid="_how_do_i_override_the_package_used_by_a_module"></a>4.6.How do I override the package used by a module?</h2></div></div></div><p>By default Home Manager will install the package provided by your chosen <codeclass="literal">nixpkgs</code> channel but occasionally you might end up needing to change this package. This can typically be done in two ways.</p><divclass="orderedlist"><olclass="orderedlist"type="1"><liclass="listitem"><pclass="simpara">
If the module provides a <codeclass="literal">package</code> option, such as <codeclass="literal">programs.beets.package</code>, then this is the recommended way to perform the override. For example,
If no <codeclass="literal">package</code> option is available then you can typically override the relevant package using an <aclass="link"href="https://nixos.org/nixpkgs/manual/#chap-overlays"target="_top">overlay</a>.
</p><pclass="simpara">For example, if you want to use the <codeclass="literal">programs.skim</code> module but use the <codeclass="literal">skim</code> package from Nixpkgs unstable, then a configuration like</p><preclass="programlisting nix">{ pkgs, config, ... }:
}</pre><pclass="simpara">should work OK.</p></li></ol></div></div></div></div><divclass="navfooter"><hr/><tablewidth="100%"summary="Navigation footer"><tr><tdwidth="40%"align="left"></td><tdwidth="20%"align="center"></td><tdwidth="40%"align="right"><aaccesskey="n"href="options.html">Next</a></td></tr><tr><tdwidth="40%"align="left"valign="top"></td><tdwidth="20%"align="center"></td><tdwidth="40%"align="right"valign="top">AppendixA.Configuration Options</td></tr></table></div></body></html>