2020-11-05 22:52:20 +01:00
|
|
|
|
[[ch-installation]]
|
|
|
|
|
== Installing Home Manager
|
|
|
|
|
|
|
|
|
|
:nix-darwin: https://github.com/LnL7/nix-darwin/
|
|
|
|
|
|
|
|
|
|
Home Manager can be used in three primary ways:
|
|
|
|
|
|
|
|
|
|
1. Using the standalone `home-manager` 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
|
2021-11-14 23:55:18 +01:00
|
|
|
|
home directory independently of the system as a whole. See
|
2020-11-05 22:52:20 +01:00
|
|
|
|
<<sec-install-standalone>> for instructions on how to perform this
|
|
|
|
|
installation.
|
|
|
|
|
|
|
|
|
|
2. As a module within a NixOS system configuration. This allows the
|
|
|
|
|
user profiles to be built together with the system when running
|
|
|
|
|
`nixos-rebuild`. See <<sec-install-nixos-module>> for a description of
|
|
|
|
|
this setup.
|
|
|
|
|
|
|
|
|
|
3. As a module within a {nix-darwin}[nix-darwin] system configuration.
|
|
|
|
|
This allows the user profiles to be built together with the system
|
|
|
|
|
when running `darwin-rebuild`. See <<sec-install-nix-darwin-module>>
|
|
|
|
|
for a description of this setup.
|
|
|
|
|
|
|
|
|
|
[[sec-install-standalone]]
|
|
|
|
|
=== Standalone installation
|
|
|
|
|
|
|
|
|
|
:nix-allowed-users: https://nixos.org/nix/manual/#conf-allowed-users
|
|
|
|
|
:nixos-allowed-users: https://nixos.org/nixos/manual/options.html#opt-nix.allowedUsers
|
2021-11-14 23:55:18 +01:00
|
|
|
|
:bash: https://www.gnu.org/software/bash/
|
|
|
|
|
:zsh: http://zsh.sourceforge.net/
|
|
|
|
|
:fish: https://fishshell.com
|
|
|
|
|
:plugin-foreign-env: https://github.com/oh-my-fish/plugin-foreign-env
|
|
|
|
|
:babelfish: https://github.com/bouk/babelfish
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
1. Make sure you have a working Nix installation. Specifically, make
|
|
|
|
|
sure that your user is able to build and install Nix packages. For
|
|
|
|
|
example, you should be able to successfully run a command like
|
|
|
|
|
`nix-instantiate '<nixpkgs>' -A hello` without having to switch to the
|
|
|
|
|
root user. For a multi-user install of Nix this means that your user
|
|
|
|
|
must be covered by the {nix-allowed-users}[`allowed-users`] Nix
|
|
|
|
|
option. On NixOS you can control this option using the
|
|
|
|
|
{nixos-allowed-users}[`nix.allowedUsers`] system option.
|
|
|
|
|
|
2021-11-14 23:55:18 +01:00
|
|
|
|
2. Add the appropriate Home Manager channel. If you are following
|
|
|
|
|
Nixpkgs master or an unstable channel you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
+
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
|
|
|
|
$ nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
|
|
|
$ nix-channel --update
|
|
|
|
|
----
|
|
|
|
|
+
|
2022-06-01 21:28:33 +02:00
|
|
|
|
and if you follow a Nixpkgs version 22.05 channel you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
+
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-01 21:28:33 +02:00
|
|
|
|
$ nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.05.tar.gz home-manager
|
2020-11-05 22:52:20 +01:00
|
|
|
|
$ nix-channel --update
|
|
|
|
|
----
|
|
|
|
|
+
|
2022-01-10 15:57:17 +01:00
|
|
|
|
On non-NixOS, you may have to add
|
2020-11-05 22:52:20 +01:00
|
|
|
|
+
|
|
|
|
|
[source,bash]
|
2022-01-10 15:57:17 +01:00
|
|
|
|
export NIX_PATH=$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels${NIX_PATH:+:$NIX_PATH}
|
2020-11-05 22:52:20 +01:00
|
|
|
|
+
|
2022-01-10 15:57:17 +01:00
|
|
|
|
to your shell (see https://github.com/NixOS/nix/issues/2033[nix#2033]
|
|
|
|
|
and
|
|
|
|
|
https://discourse.nixos.org/t/where-is-nix-path-supposed-to-be-set/16434/8[this
|
|
|
|
|
reply on the Nix Discourse]).
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
3. Run the Home Manager installation command and create the first Home
|
|
|
|
|
Manager generation:
|
|
|
|
|
+
|
|
|
|
|
[source,console]
|
|
|
|
|
$ nix-shell '<home-manager>' -A install
|
|
|
|
|
+
|
|
|
|
|
Once finished, Home Manager should be active and available in your
|
|
|
|
|
user environment.
|
|
|
|
|
|
|
|
|
|
4. If you do not plan on having Home Manager manage your shell
|
|
|
|
|
configuration then you must source the
|
|
|
|
|
+
|
|
|
|
|
[source,bash]
|
|
|
|
|
$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
|
|
|
|
|
+
|
2020-12-13 17:25:45 +01:00
|
|
|
|
file in your shell configuration. Alternatively source
|
|
|
|
|
+
|
|
|
|
|
[source,bash]
|
|
|
|
|
/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh
|
|
|
|
|
+
|
|
|
|
|
when managing home configuration together with system configuration.
|
|
|
|
|
+
|
2021-09-04 10:22:58 +02:00
|
|
|
|
This file can be sourced directly by POSIX.2-like shells such as
|
2021-11-14 23:55:18 +01:00
|
|
|
|
{bash}[Bash] or {zsh}[Z shell]. {fish}[Fish] users can use utilities
|
|
|
|
|
such as {plugin-foreign-env}[foreign-env] or {babelfish}[babelfish].
|
2020-11-05 22:52:20 +01:00
|
|
|
|
+
|
|
|
|
|
For example, if you use Bash then add
|
|
|
|
|
+
|
|
|
|
|
[source,bash]
|
|
|
|
|
----
|
|
|
|
|
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
----
|
|
|
|
|
+
|
2021-07-29 18:05:48 +02:00
|
|
|
|
to your `~/.profile` file.
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
If instead of using channels you want to run Home Manager from a Git
|
|
|
|
|
checkout of the repository then you can use the
|
|
|
|
|
<<opt-programs.home-manager.path>> option to specify the absolute path
|
|
|
|
|
to the repository.
|
|
|
|
|
|
2021-11-14 23:55:18 +01:00
|
|
|
|
Once installed you can see <<ch-usage>> for a more detailed
|
|
|
|
|
description of Home Manager and how to use it.
|
|
|
|
|
|
2020-11-05 22:52:20 +01:00
|
|
|
|
[[sec-install-nixos-module]]
|
|
|
|
|
=== NixOS module
|
|
|
|
|
|
|
|
|
|
Home Manager provides a NixOS module that allows you to prepare user
|
|
|
|
|
environments directly from the system configuration file, which often
|
|
|
|
|
is more convenient than using the `home-manager` tool. It also opens
|
|
|
|
|
up additional possibilities, for example, to automatically configure
|
|
|
|
|
user environments in NixOS declarative containers or on systems
|
|
|
|
|
deployed through NixOps.
|
|
|
|
|
|
|
|
|
|
To make the NixOS module available for use you must `import` it into
|
|
|
|
|
your system configuration. This is most conveniently done by adding a
|
2020-12-19 01:29:32 +01:00
|
|
|
|
Home Manager channel. For example, if you are following Nixpkgs master
|
|
|
|
|
or an unstable channel, you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-18 23:29:35 +02:00
|
|
|
|
# nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
|
|
|
# nix-channel --update
|
2020-11-05 22:52:20 +01:00
|
|
|
|
----
|
|
|
|
|
|
2022-06-01 21:28:33 +02:00
|
|
|
|
and if you follow a Nixpkgs version 22.05 channel, you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-18 23:29:35 +02:00
|
|
|
|
# nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.05.tar.gz home-manager
|
|
|
|
|
# nix-channel --update
|
2020-11-05 22:52:20 +01:00
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
It is then possible to add
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
imports = [ <home-manager/nixos> ];
|
|
|
|
|
|
|
|
|
|
to your system `configuration.nix` file, which will introduce a new
|
|
|
|
|
NixOS option called `home-manager.users` whose type is an attribute
|
|
|
|
|
set that maps user names to Home Manager configurations.
|
|
|
|
|
|
|
|
|
|
For example, a NixOS configuration may include the lines
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
----
|
|
|
|
|
users.users.eve.isNormalUser = true;
|
|
|
|
|
home-manager.users.eve = { pkgs, ... }: {
|
|
|
|
|
home.packages = [ pkgs.atool pkgs.httpie ];
|
|
|
|
|
programs.bash.enable = true;
|
|
|
|
|
};
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
and after a `nixos-rebuild switch` the user eve's environment should
|
|
|
|
|
include a basic Bash configuration and the packages atool and httpie.
|
|
|
|
|
|
2021-12-22 20:19:29 +01:00
|
|
|
|
[NOTE]
|
|
|
|
|
====
|
|
|
|
|
If `nixos-rebuild switch` does not result in the environment you expect,
|
|
|
|
|
you can take a look at the output of the Home Manager activation script output using
|
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
$ systemctl status "home-manager-$USER.service"
|
|
|
|
|
====
|
|
|
|
|
|
2021-11-14 23:55:18 +01:00
|
|
|
|
If you do not plan on having Home Manager manage your shell
|
|
|
|
|
configuration then you must add either
|
|
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
|
----
|
|
|
|
|
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
|
----
|
|
|
|
|
. "/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
to your shell configuration, depending on whether
|
|
|
|
|
<<nixos-opt-home-manager.useUserPackages>> is enabled. This file can
|
|
|
|
|
be sourced directly by POSIX.2-like shells such as {bash}[Bash] or
|
|
|
|
|
{zsh}[Z shell]. {fish}[Fish] users can use utilities such as
|
|
|
|
|
{plugin-foreign-env}[foreign-env] or {babelfish}[babelfish].
|
|
|
|
|
|
2020-11-05 22:52:20 +01:00
|
|
|
|
[NOTE]
|
|
|
|
|
====
|
|
|
|
|
By default packages will be installed to `$HOME/.nix-profile` but they
|
|
|
|
|
can be installed to `/etc/profiles` if
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
home-manager.useUserPackages = true;
|
|
|
|
|
|
|
|
|
|
is added to the system configuration. This is necessary if, for
|
|
|
|
|
example, you wish to use `nixos-rebuild build-vm`. This option may
|
|
|
|
|
become the default value in the future.
|
|
|
|
|
====
|
|
|
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
|
====
|
|
|
|
|
By default, Home Manager uses a private `pkgs` instance that is
|
|
|
|
|
configured via the `home-manager.users.<name>.nixpkgs` options. To
|
|
|
|
|
instead use the global `pkgs` that is configured via the system level
|
|
|
|
|
`nixpkgs` options, set
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
home-manager.useGlobalPkgs = true;
|
|
|
|
|
|
|
|
|
|
This saves an extra Nixpkgs evaluation, adds consistency, and removes
|
|
|
|
|
the dependency on `NIX_PATH`, which is otherwise used for importing
|
|
|
|
|
Nixpkgs.
|
|
|
|
|
====
|
|
|
|
|
|
2021-11-14 23:55:18 +01:00
|
|
|
|
Once installed you can see <<ch-usage>> for a more detailed
|
|
|
|
|
description of Home Manager and how to use it.
|
|
|
|
|
|
2020-11-05 22:52:20 +01:00
|
|
|
|
[[sec-install-nix-darwin-module]]
|
|
|
|
|
=== nix-darwin module
|
|
|
|
|
|
|
|
|
|
Home Manager provides a module that allows you to prepare user
|
|
|
|
|
environments directly from the {nix-darwin}[nix-darwin] configuration
|
|
|
|
|
file, which often is more convenient than using the `home-manager`
|
|
|
|
|
tool.
|
|
|
|
|
|
|
|
|
|
To make the NixOS module available for use you must `import` it into
|
|
|
|
|
your system configuration. This is most conveniently done by adding a
|
2020-12-19 01:29:32 +01:00
|
|
|
|
Home Manager channel. For example, if you are following Nixpkgs master
|
|
|
|
|
or an unstable channel, you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-15 11:14:19 +02:00
|
|
|
|
$ nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
|
|
|
$ nix-channel --update
|
2020-11-05 22:52:20 +01:00
|
|
|
|
----
|
|
|
|
|
|
2022-06-01 21:28:33 +02:00
|
|
|
|
and if you follow a Nixpkgs version 22.05 channel, you can run
|
2020-11-05 22:52:20 +01:00
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
|
----
|
2022-06-15 11:14:19 +02:00
|
|
|
|
$ nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.05.tar.gz home-manager
|
|
|
|
|
$ nix-channel --update
|
2020-11-05 22:52:20 +01:00
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
It is then possible to add
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
imports = [ <home-manager/nix-darwin> ];
|
|
|
|
|
|
|
|
|
|
to your nix-darwin `configuration.nix` file, which will introduce a
|
|
|
|
|
new NixOS option called `home-manager` whose type is an attribute set
|
|
|
|
|
that maps user names to Home Manager configurations.
|
|
|
|
|
|
|
|
|
|
For example, a nix-darwin configuration may include the lines
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
----
|
2021-08-10 20:41:00 +02:00
|
|
|
|
users.users.eve = {
|
2021-07-28 21:52:22 +02:00
|
|
|
|
name = "eve";
|
|
|
|
|
home = "/Users/eve";
|
|
|
|
|
}
|
2020-11-05 22:52:20 +01:00
|
|
|
|
home-manager.users.eve = { pkgs, ... }: {
|
|
|
|
|
home.packages = [ pkgs.atool pkgs.httpie ];
|
|
|
|
|
programs.bash.enable = true;
|
|
|
|
|
};
|
|
|
|
|
----
|
|
|
|
|
|
2021-03-18 23:15:30 +01:00
|
|
|
|
and after a `darwin-rebuild switch` the user eve's environment
|
2020-11-05 22:52:20 +01:00
|
|
|
|
should include a basic Bash configuration and the packages atool and
|
|
|
|
|
httpie.
|
|
|
|
|
|
2021-11-14 23:55:18 +01:00
|
|
|
|
If you do not plan on having Home Manager manage your shell
|
|
|
|
|
configuration then you must add either
|
|
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
|
----
|
|
|
|
|
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
|
----
|
|
|
|
|
. "/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh"
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
to your shell configuration, depending on whether
|
|
|
|
|
<<nix-darwin-opt-home-manager.useUserPackages>> is enabled. This file
|
|
|
|
|
can be sourced directly by POSIX.2-like shells such as {bash}[Bash] or
|
|
|
|
|
{zsh}[Z shell]. {fish}[Fish] users can use utilities such as
|
|
|
|
|
{plugin-foreign-env}[foreign-env] or {babelfish}[babelfish].
|
|
|
|
|
|
2020-11-05 22:52:20 +01:00
|
|
|
|
[NOTE]
|
|
|
|
|
====
|
|
|
|
|
By default user packages will not be ignored in favor of
|
|
|
|
|
`environment.systemPackages`, but they will be intalled to
|
|
|
|
|
`/etc/profiles/per-user/$USERNAME` if
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
home-manager.useUserPackages = true;
|
|
|
|
|
|
|
|
|
|
is added to the nix-darwin configuration. This option may become the
|
|
|
|
|
default value in the future.
|
|
|
|
|
====
|
|
|
|
|
|
|
|
|
|
[NOTE]
|
|
|
|
|
====
|
|
|
|
|
By default, Home Manager uses a private `pkgs` instance that is
|
|
|
|
|
configured via the `home-manager.users.<name>.nixpkgs` options. To
|
|
|
|
|
instead use the global `pkgs` that is configured via the system level
|
|
|
|
|
`nixpkgs` options, set
|
|
|
|
|
|
|
|
|
|
[source,nix]
|
|
|
|
|
home-manager.useGlobalPkgs = true;
|
|
|
|
|
|
|
|
|
|
This saves an extra Nixpkgs evaluation, adds consistency, and removes
|
|
|
|
|
the dependency on `NIX_PATH`, which is otherwise used for importing
|
|
|
|
|
Nixpkgs.
|
|
|
|
|
====
|
2021-11-14 23:55:18 +01:00
|
|
|
|
|
|
|
|
|
Once installed you can see <<ch-usage>> for a more detailed
|
|
|
|
|
description of Home Manager and how to use it.
|