You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: source/tutorials/nixos/nixos-configuration-on-vm.md
+4-58Lines changed: 4 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,59 +26,16 @@ For a thorough treatment of the module system, check the [](module-system-deep-d
26
26
## Starting from a default NixOS configuration
27
27
28
28
:::{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.
30
31
:::
31
32
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):
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`:
76
34
77
35
```nix
78
36
{ config, pkgs, ... }:
79
-
{
80
-
imports = [ ./hardware-configuration.nix ];
81
37
38
+
{
82
39
boot.loader.systemd-boot.enable = true;
83
40
boot.loader.efi.canTouchEfiVariables = true;
84
41
@@ -95,10 +52,6 @@ To be able to log in, add the following lines to the returned attribute set:
95
52
};
96
53
```
97
54
98
-
:::{note}
99
-
A configuration generated with `nixos-generate-config` contains this user configuration commented out.
100
-
:::
101
-
102
55
Additionally, you need to specify a password for this user.
103
56
For the purpose of demonstration only, you specify an insecure, plain text password by adding the `initialPassword` option to the user configuration:
104
57
@@ -119,13 +72,6 @@ We add two lightweight programs as an example:
119
72
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.
120
73
:::
121
74
122
-
This tutorial focuses on testing NixOS configurations on a virtual machine.
123
-
Therefore you will remove the reference to `hardware-configuration.nix`:
0 commit comments