File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ ''
You can’t perform that action at this time.
0 commit comments