1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

home-manager: add init command to main tool

The init command is essentially the old install script but integrated
into the home-manager tool. This simplifies things slightly since we
can use the existing code infrastructure.

The init command is Nix flake aware in the sense that, if we detect
that the user's Nix setup supports flakes, then we also create an
initial `flake.nix` file.

Finally, we update the installation instructions for the Nix flakes
standalone setup to use the new init command.

Zsh completion update provided by Anund <anundm@gmail.com>.
This commit is contained in:
Robert Helgesson 2023-02-26 23:10:06 +01:00
parent 95201931f2
commit c8cb60b8a1
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
9 changed files with 460 additions and 205 deletions

View file

@ -17,6 +17,10 @@
build
</arg>
<arg choice="plain">
init <arg>--switch</arg> <arg><replaceable>dir</replaceable></arg>
</arg>
<arg choice="plain">
instantiate
</arg>
@ -218,6 +222,35 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>init</option> [<option>--switch</option>] [<replaceable>dir</replaceable>]
</term>
<listitem>
<simpara>
Generates an initial <filename>home.nix</filename> file for the
current user. If Nix flakes are enabled, then this command also
generates a <filename>flake.nix</filename> file.
</simpara>
<simpara>
If a path <replaceable>dir</replaceable> is given then the
configuration will be generated in that directory. Otherwise, the
configuration will be generated in
<filename>~/.config/home-manager</filename>. The output directory will
be created if it does not exist.
</simpara>
<simpara>
If the <option>--switch</option> option is given, then the generated
configuration is activated.
</simpara>
<simpara>
Note, this command will not overwrite any existing files. It is
therefore safe to initialize a configuration, edit it, and then re-run
the <option>init</option> command with <option>--switch</option>
enabled to activate the configuration.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>instantiate</option>

View file

@ -70,6 +70,71 @@ writing a Home Manager configuration.
[[sec-flakes-standalone]]
=== Standalone setup
The installation procedure for the standalone version of Home Manager
is currently different for the unstable and stable branch.
Therefore, if you are tracking the Nixpkgs or NixOS unstable please go to
<<sec-flakes-standalone-unstable>>,
and if you track Nixpkgs or NixOS version 22.11 please go to
<<sec-flakes-standalone-stable>>.
[[sec-flakes-standalone-unstable]]
==== Unstable Version
To prepare an initial Home Manager configuration for your logged in user,
you can run the Home Manager `init` command directly from its flake.
For example, to generate and activate a basic configuration run the command
[source,console]
$ nix run home-manager/master -- init --switch
This will generate a `flake.nix` and a `home.nix` file in
`~/.config/home-manager`, creating the directory if it does not exist.
If you omit the `--switch` option then the activation will not happen.
This is useful if you want to inspect and edit the configuration before activating it.
[source,console]
----
$ nix run home-manager/master -- init
$ # Edit files in ~/.config/home-manager
$ nix run home-manager/master -- init --switch
----
After the initial activation has completed successfully then building
and activating your flake-based configuration is as simple as
[source,console]
$ home-manager switch
It is possible to override the default configuration directory, if you want.
For example,
[source,console]
----
$ nix run home-manager/master -- init --switch ~/hmconf
$ # And after the initial activation.
$ home-manager switch --flake ~/hmconf
----
[NOTE]
====
The flake inputs are not automatically updated by Home Manager.
You need to use the standard `nix flake update` command for that.
If you only want to update a single flake input,
then the command `nix flake lock --update-input <input>` can be used.
You can also pass flake-related options
such as `--recreate-lock-file` or `--update-input <input>`
to `home-manager` when building or switching,
and these options will be forwarded to `nix build`.
See the {nixos-wiki-flakes}[NixOS Wiki page] for details.
====
[[sec-flakes-standalone-stable]]
==== Version 22.11
1. Set up a flake with a `flake.nix` as follows:
+
[source,nix]
@ -79,9 +144,9 @@ writing a Home Manager configuration.
inputs = {
# Specify the source of Home Manager and Nixpkgs.
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
home-manager = {
url = "github:nix-community/home-manager";
url = "github:nix-community/home-manager/release-22.11";
inputs.nixpkgs.follows = "nixpkgs";
};
};
@ -109,16 +174,10 @@ writing a Home Manager configuration.
+
[NOTE]
====
* The above example tracks the master branch of Home Manager
and nixos-unstable branch of Nixpkgs.
If you would like to use the `release-22.11` branch,
change the `home-manager` input url to `github:nix-community/home-manager/release-22.11`
and `nixpkgs` url to `github:NixOS/nixpkgs/nixos-22.11`.
* The Home Manager library is exported by the flake under
`lib.hm`.
* The Home Manager library is exported by the flake under `lib.hm`.
* You can use the above `flake.nix` as a template in `~/.config/home-manager` by
+
[source,console]
$ nix flake new ~/.config/home-manager -t github:nix-community/home-manager
====

View file

@ -30,6 +30,14 @@ The old location will continue to work but using it will trigger a warning messa
We changed the default configuration location to avoid confusion about
which files belong to Home Manager and which belong to Nixpkgs.
* The `home-manager` tool now offers an `init` command.
This command can be used to generate an initial Home Manager configuration,
and optionally also activate it.
The recommended installation method for a standalone Home Manager setup
with Nix flakes uses this new command.
The standard installation method remains the same but uses the new command internally.
See <<sec-flakes-standalone-unstable>> for more.
[[sec-release-23.05-state-version-changes]]
=== State Version Changes
@ -45,5 +53,5 @@ These changes are only active if the `home.stateVersion` option is set to "23.05
- <<opt-wayland.windowManager.sway.config.floating.titlebar>>
--
+
now default to `true` which is consistent with the default values
for those options used by `i3` and `sway`.
now default to `true` which is consistent with the default values for
those options used by `i3` and `sway`.