Skip to content

Commit 1f653b9

Browse files
authored
Merge branch 'main' into patch-1
2 parents 2295193 + 846ea21 commit 1f653b9

File tree

15 files changed

+172
-33
lines changed

15 files changed

+172
-33
lines changed

.github/workflows/auto-merge.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Auto Merge Dependency Updates
2+
on:
3+
- pull_request_target
4+
jobs:
5+
auto-merge-dependency-updates:
6+
runs-on: ubuntu-latest
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
concurrency:
11+
group: "auto-merge:${{ github.head_ref }}"
12+
cancel-in-progress: true
13+
steps:
14+
- uses: Mic92/auto-merge@main
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Update flakes"
2+
on:
3+
repository_dispatch:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "51 2 * * 0"
7+
8+
jobs:
9+
createPullRequest:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Install Nix
14+
uses: cachix/install-nix-action@v31
15+
with:
16+
extra_nix_config: |
17+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
18+
- uses: actions/create-github-app-token@v1
19+
id: app-token
20+
with:
21+
app-id: ${{ vars.CI_APP_ID }}
22+
private-key: ${{ secrets.CI_APP_PRIVATE_KEY }}
23+
- name: Update flakes
24+
run: nix flake update
25+
- name: Create Pull Request
26+
uses: peter-evans/create-pull-request@v7
27+
with:
28+
title: Update flakes
29+
token: ${{ steps.app-token.outputs.token }}
30+
labels: |
31+
auto-merge

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")

terraform/all-in-one.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module "deploy" {
2626
instance_id = local.ipv4
2727
# useful if something goes wrong
2828
# debug_logging = true
29+
# build the closure on the remote machine instead of locally
30+
# build_on_remote = true
2931
# script is below
3032
extra_files_script = "${path.module}/decrypt-ssh-secrets.sh"
3133
disk_encryption_key_scripts = [{
@@ -109,7 +111,7 @@ NixOS without relying on special_args.
109111
centralizing state in a single repository.
110112
- **Disadvantages**:
111113
- Deploying new machines requires tracking additional state. Every time
112-
Terraform updates the JSON file, youll need to commit these changes to your
114+
Terraform updates the JSON file, you'll need to commit these changes to your
113115
repository.
114116

115117
### Implementation
@@ -218,6 +220,7 @@ No resources.
218220
| <a name="input_no_reboot"></a> [no\_reboot](#input_no_reboot) | DEPRECATED: Use `phases` instead. Do not reboot after installation | `bool` | `false` | no |
219221
| <a name="input_phases"></a> [phases](#input_phases) | Phases to run. See `nixos-anywhere --help` for more information | `set(string)` | <pre>[<br> "kexec",<br> "disko",<br> "install",<br> "reboot"<br>]</pre> | no |
220222
| <a name="input_special_args"></a> [special\_args](#input_special_args) | A map exposed as NixOS's `specialArgs` thru a file. | `any` | `{}` | no |
223+
| <a name="input_build_on_remote"></a> [build\_on\_remote](#input_build_on_remote) | Build the closure on the remote machine instead of building it locally and copying it over | `bool` | `false` | no |
221224
| <a name="input_stop_after_disko"></a> [stop\_after\_disko](#input_stop_after_disko) | DEPRECATED: Use `phases` instead. Exit after disko formatting | `bool` | `false` | no |
222225
| <a name="input_target_host"></a> [target\_host](#input_target_host) | DNS host to deploy to | `string` | n/a | yes |
223226
| <a name="input_target_port"></a> [target\_port](#input_target_port) | SSH port used to connect to the target\_host after installing NixOS. If install\_port is not set than this port is also used before installing. | `number` | `22` | no |

terraform/all-in-one/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module "install" {
3636
phases = var.phases
3737
nixos_generate_config_path = var.nixos_generate_config_path
3838
nixos_facter_path = var.nixos_facter_path
39+
build_on_remote = var.build_on_remote
3940
# deprecated attributes
4041
stop_after_disko = var.stop_after_disko
4142
no_reboot = var.no_reboot
@@ -55,6 +56,7 @@ module "nixos-rebuild" {
5556
target_host = var.target_host
5657
target_user = var.target_user
5758
target_port = var.target_port
59+
install_bootloader = var.install_bootloader
5860
}
5961

6062
output "result" {

0 commit comments

Comments
 (0)