Skip to content

Commit 7ab708b

Browse files
Merge pull request #483 from nix-community/create-pull-request/patch
Update flakes
2 parents 1f23876 + 5abd4b3 commit 7ab708b

File tree

7 files changed

+89
-27
lines changed

7 files changed

+89
-27
lines changed

docs/howtos/INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
[Installing on a machine with no operating system](./no-os.md)
1212

13+
[Kexec on systems with limited RAM](./limited-ram.md)
14+
1315
[Copying files to the new installation](./extra-files.md)
1416

1517
[Using your own kexec image](./custom-kexec.md)

docs/howtos/limited-ram.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Kexec on Systems with Limited RAM
2+
3+
When working with nixos-anywhere on systems with limited RAM (around 1GB), you
4+
can use the `--no-disko-deps` option to reduce memory usage during installation.
5+
6+
## How it works
7+
8+
The `--no-disko-deps` option uploads only the disko partitioning script without
9+
including its dependencies. This significantly reduces memory usage because:
10+
11+
1. The installer normally stores all dependencies in memory
12+
2. Partitioning tools can be quite large when bundled with their dependencies
13+
14+
## Usage example
15+
16+
```bash
17+
nix run github:nix-community/nixos-anywhere -- --no-disko-deps --flake <path to configuration>#<configuration name> --target-host root@<ip address>
18+
```
19+
20+
## Trade-off
21+
22+
While this approach saves memory, it means the partitioning tools will be
23+
whatever versions are available on the target system, rather than the specific
24+
versions defined in your NixOS configuration. This could potentially lead to
25+
version inconsistencies between the partitioning tools and the NixOS system
26+
being installed.
27+
28+
This trade-off is usually acceptable for memory-constrained environments where
29+
installation would otherwise fail due to insufficient RAM.

docs/howtos/use-without-flakes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ step:
7878
Run `nixos-anywhere` as follows:
7979

8080
```bash
81-
nixos-anywhere --store-paths $(nix-build -A config.system.build.disko -A config.system.build.toplevel --no-out-link) root@machine
81+
nixos-anywhere --store-paths $(nix-build -A config.system.build.formatScript -A config.system.build.toplevel --no-out-link) root@machine
8282
```

docs/reference.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ TODO: Populate this guide properly
1919
<!-- `$ bash ./src/nixos-anywhere.sh --help` -->
2020

2121
```
22-
Usage: nixos-anywhere [options] <ssh-host>
22+
Usage: nixos-anywhere [options] [<ssh-host>]
2323
2424
Options:
2525
2626
* -f, --flake <flake_uri>
27-
set the flake to install the system from.
27+
set the flake to install the system from. i.e.
28+
nixos-anywhere --flake .#mymachine
29+
Also supports variants:
30+
nixos-anywhere --flake .#nixosConfigurations.mymachine.config.virtualisation.vmVariant
31+
* --target-host <ssh-host>
32+
set the SSH target host to deploy onto.
2833
* -i <identity_file>
2934
selects which SSH private key file to use.
3035
* -p, --ssh-port <ssh_port>
@@ -43,6 +48,8 @@ Options:
4348
use another kexec tarball to bootstrap NixOS
4449
* --kexec-extra-flags
4550
extra flags to add into the call to kexec, e.g. "--no-sync"
51+
* --ssh-store-setting <key> <value>
52+
ssh store settings appended to the store URI, e.g. "compress true". <value> needs to be URI encoded.
4653
* --post-kexec-ssh-port <ssh_port>
4754
after kexec is executed, use a custom ssh port to connect. Defaults to 22
4855
* --copy-host-keys
@@ -60,6 +67,8 @@ Options:
6067
disable passing --substitute-on-destination to nix-copy
6168
* --debug
6269
enable debug output
70+
* --show-trace
71+
show nix build traces
6372
* --option <key> <value>
6473
nix option to pass to every nix related command
6574
* --from <store-uri>
@@ -80,8 +89,15 @@ Options:
8089
* --disko-mode disko|mount|format
8190
set the disko mode to format, mount or destroy. Default is disko.
8291
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
83-
mount: mount the partition at the specified root-mountpoint
84-
format: create partition tables, zpools, lvms, raids and filesystems (Experimental: Can be run increntally, but use with caution and good backups)
92+
* --no-disko-deps
93+
This will only upload the disko script and not the partitioning tools dependencies.
94+
Installers usually have dependencies available.
95+
Use this option if your target machine has not enough RAM to store the dependencies in memory.
96+
* --build-on auto|remote|local
97+
sets the build on settings to auto, remote or local. Default is auto.
98+
auto: tries to figure out, if the build is possible on the local host, if not falls back gracefully to remote build
99+
local: will build on the local host
100+
remote: will build on the remote host
85101
```
86102

87103
## Explanation of known error messages

flake.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nixos-anywhere.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ kexecExtraFlags=""
99
sshStoreSettings=""
1010
enableDebug=""
1111
nixBuildFlags=()
12+
diskoAttr=""
1213
diskoScript=""
1314
diskoMode="disko"
15+
diskoDeps=y
1416
nixosSystem=""
1517
extraFiles=""
1618
vmTest="n"
@@ -137,6 +139,10 @@ Options:
137139
* --disko-mode disko|mount|format
138140
set the disko mode to format, mount or destroy. Default is disko.
139141
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
142+
* --no-disko-deps
143+
This will only upload the disko script and not the partitioning tools dependencies.
144+
Installers usually have dependencies available.
145+
Use this option if your target machine has not enough RAM to store the dependencies in memory.
140146
* --build-on auto|remote|local
141147
sets the build on settings to auto, remote or local. Default is auto.
142148
auto: tries to figure out, if the build is possible on the local host, if not falls back gracefully to remote build
@@ -255,6 +261,9 @@ parseArgs() {
255261

256262
shift
257263
;;
264+
--no-disko-deps)
265+
diskoDeps=n
266+
;;
258267
--build-on)
259268
case "$2" in
260269
auto | local | remote)
@@ -346,6 +355,12 @@ parseArgs() {
346355
shift
347356
done
348357

358+
diskoAttr="${diskoMode}Script"
359+
360+
if [[ ${diskoDeps} == "n" ]]; then
361+
diskoAttr="${diskoAttr}NoDeps"
362+
fi
363+
349364
if [[ ${printBuildLogs} == "y" ]]; then
350365
nixOptions+=("-L")
351366
fi
@@ -659,7 +674,7 @@ runDisko() {
659674
--derivation --no-check-sigs
660675
# If we don't use ssh-ng here, we get `error: operation 'getFSAccessor' is not supported by store`
661676
diskoScript=$(
662-
nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script" \
677+
nixBuild "${flake}#${flakeAttr}.system.build.${diskoAttr}" \
663678
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$sshKeyDir%2Fnixos-anywhere&$sshStoreSettings"
664679
)
665680
fi
@@ -756,7 +771,7 @@ main() {
756771
if [[ -n ${flake} ]]; then
757772
if [[ ${buildOn} == "local" ]] && [[ ${hardwareConfigBackend} == "none" ]]; then
758773
if [[ ${phases[disko]} == 1 ]]; then
759-
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script")
774+
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoAttr}")
760775
fi
761776
if [[ ${phases[install]} == 1 ]]; then
762777
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")
@@ -831,7 +846,7 @@ main() {
831846
832847
if [[ ${buildOn} != "remote" ]] && [[ -n ${flake} ]] && [[ -z ${diskoScript} ]]; then
833848
if [[ ${phases[disko]} == 1 ]]; then
834-
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script")
849+
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoAttr}")
835850
fi
836851
if [[ ${phases[install]} == 1 ]]; then
837852
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")

tests/modules/installer.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ in
1515
environment.systemPackages = [ inputs.nixos-anywhere ];
1616

1717
environment.etc = {
18-
"nixos-anywhere/disko".source = system-to-install.config.system.build.diskoScript;
18+
"nixos-anywhere/disko".source = system-to-install.config.system.build.diskoScriptNoDeps;
1919
"nixos-anywhere/system-to-install".source = system-to-install.config.system.build.toplevel;
2020
"nixos-anywhere/kexec-installer".source = kexec-installer;
2121
};

0 commit comments

Comments
 (0)