Skip to content

Commit 8061765

Browse files
authored
nixos-configuration-on-vm: de-emphasize nixos-generate-config (#1158)
The main point of `nixos-generate-config` is that it generates the `hardware-configuration.nix` matching the characteristics of the machine you're running on, but that configuration is not used in the VM scenario anyway.
1 parent 3d80db6 commit 8061765

File tree

1 file changed

+4
-58
lines changed

1 file changed

+4
-58
lines changed

source/tutorials/nixos/nixos-configuration-on-vm.md

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,16 @@ For a thorough treatment of the module system, check the [](module-system-deep-d
2626
## Starting from a default NixOS configuration
2727

2828
:::{note}
29-
You can also skip this section and copy the [sample configuration](sample-nixos-config) for this tutorial into a file `configuration.nix` in the current directory.
29+
This tutorial starts with building up your `configuration.nix` from first principles, explaining each step.
30+
If you prefer, you can skip ahead to the [sample configuration](sample-nixos-config) section.
3031
:::
3132

32-
Use the `nixos-generate-config` command to create a configuration file that contains some useful defaults and configuration suggestions.
33-
The configuration produced from the following setup also is used for the [NixOS minimal ISO image](https://nixos.org/download#nixos-iso):
34-
35-
```shell-session
36-
nix-shell -I nixpkgs=channel:nixos-24.05 -p "$(cat <<EOF
37-
let
38-
pkgs = import <nixpkgs> { config = {}; overlays = []; };
39-
iso-config = pkgs.path + /nixos/modules/installer/cd-dvd/installation-cd-minimal.nix;
40-
nixos = pkgs.nixos iso-config;
41-
in nixos.config.system.build.nixos-generate-config
42-
EOF
43-
)"
44-
```
45-
46-
:::{dropdown} Detailed explanation
47-
48-
This `nix-shell` invocation creates an environment based on Nixpkgs obtained from a [channel](ref-pinning-nixpkgs) and adds to it a derivation that is described by the Nix expression passed as a string to the `-p` option.
49-
50-
That Nix expression:
51-
- Takes the configuration file for the minimal ISO image from the obtained version of Nixpkgs found in the lookup path `<nixpkgs>`
52-
- Evaluates that NixOS configuration with `pkgs.nixos`
53-
- Returns the derivation which produces the `nixos-generate-config` executable from the evaluated configuration
54-
55-
:::
56-
57-
Create a NixOS configuration in your working directory:
58-
59-
```shell-session
60-
[nix-shell:~]$ nixos-generate-config --dir ./
61-
```
62-
63-
:::{note}
64-
By default, when no `--dir` is specified, the generated configuration file is written to `/etc/nixos/configuration.nix`, which typically requires `sudo` permissions.
65-
:::
66-
67-
In the working directory you will then find two files:
68-
69-
1. `hardware-configuration.nix` is specific to the hardware `nix-generate-config` is being run on.
70-
71-
You can ignore that file for this tutorial because it has no effect inside a virtual machine.
72-
73-
2. `configuration.nix` contains various suggestions and comments for the initial setup of a desktop computer.
74-
75-
The default NixOS configuration without comments is:
33+
We start with a minimal `configuration.nix`:
7634

7735
```nix
7836
{ config, pkgs, ... }:
79-
{
80-
imports = [ ./hardware-configuration.nix ];
8137
38+
{
8239
boot.loader.systemd-boot.enable = true;
8340
boot.loader.efi.canTouchEfiVariables = true;
8441
@@ -95,10 +52,6 @@ To be able to log in, add the following lines to the returned attribute set:
9552
};
9653
```
9754

98-
:::{note}
99-
A configuration generated with `nixos-generate-config` contains this user configuration commented out.
100-
:::
101-
10255
Additionally, you need to specify a password for this user.
10356
For the purpose of demonstration only, you specify an insecure, plain text password by adding the `initialPassword` option to the user configuration:
10457

@@ -119,13 +72,6 @@ We add two lightweight programs as an example:
11972
Do not use plain text passwords outside of this example unless you know what you are doing. See [`initialHashedPassword`](https://nixos.org/manual/nixos/stable/options.html#opt-users.extraUsers._name_.initialHashedPassword) or [`ssh.authorizedKeys`](https://nixos.org/manual/nixos/stable/options.html#opt-users.extraUsers._name_.openssh.authorizedKeys.keys) for more secure alternatives.
12073
:::
12174

122-
This tutorial focuses on testing NixOS configurations on a virtual machine.
123-
Therefore you will remove the reference to `hardware-configuration.nix`:
124-
125-
```diff
126-
- imports = [ ./hardware-configuration.nix ];
127-
```
128-
12975
(sample-nixos-config)=
13076
### Sample configuration
13177

0 commit comments

Comments
 (0)