Skip to content

Commit 2e1975a

Browse files
committed
add some bootstrap experiement
1 parent efcd361 commit 2e1975a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

bootstrap/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Bootstrap a target via cloud-init
2+
3+
```
4+
hcloud server create --user-data-from-file $(nix-build --no-out-link) --name test --image debian-10 --type cx11
5+
```

bootstrap/boot.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let
2+
pkgs = import <nixpkgs> {};
3+
src = builtins.fetchTarball https://github.com/nix-community/nixos-generators/archive/942232e3000e80b4b4ad34cb3c07923415c27493.tar.gz;
4+
generator = import (src + "/nixos-generate.nix");
5+
6+
diskoSrc = builtins.fetchTarball https://github.com/nix-community/disko/archive/1af856886eca80ce39b61fd97816e4b3be07b236.tar.gz;
7+
8+
disko = import diskoSrc;
9+
10+
partitionDisk = disko.create cfg;
11+
12+
in generator {
13+
format-config = src + "/formats/kexec-bundle.nix";
14+
configuration = ({ config, ... }: {
15+
users.users.root.openssh.authorizedKeys.keyFiles = [ /run/root.keys ];
16+
services.openssh.enable = true;
17+
});
18+
}

bootstrap/default.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{ pkgs ? import ../nix/default.nix }:
2+
let
3+
cloud-init = (builtins.toJSON {
4+
write_files = [
5+
{
6+
path = "/run/bootstrap.nix";
7+
content = builtins.readFile ./boot.nix;
8+
}
9+
{
10+
path = "/run/root.keys";
11+
content = builtins.readFile ../config/profiles/base/andi.pub;
12+
}
13+
];
14+
bootcmd = [
15+
# install curl
16+
"apt-get update"
17+
"apt-get install -y curl"
18+
19+
# add user to drive the installer with
20+
"echo 'silly ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
21+
"useradd silly"
22+
# bootstrap nix
23+
"curl -o /run/nix.tar.xz https://nixos.org/releases/nix/nix-2.3.2/nix-2.3.2-x86_64-linux.tar.xz"
24+
# verify that we didn't download trash
25+
"echo bd4cb069d16417ba4aadc5bb005fdb263823990352f9d37c5b763a0bd145394f /run/nix.tar.xz | sha256sum -c -"
26+
# unpack and run install
27+
"cd /run && tar -xf ./nix.tar.xz && mv ./nix-* nix"
28+
"systemd-run --property=After=local-fs.target --property=User=silly /run/nix/install --daemon"
29+
30+
# build the installer environment
31+
"systemd-run --property=After=local-fs.target nix-build /run/bootstrap.nix --out-link /run/bootstrap"
32+
# exec into the installer
33+
"systemd-run --property=After=multi-user.target /run/bootstrap"
34+
];
35+
});
36+
in pkgs.writeText "cloud-init" ''
37+
#cloud-config
38+
${cloud-init}
39+
''

0 commit comments

Comments
 (0)