Skip to content

Commit

Permalink
Merge pull request #189 from lheckemann/flake
Browse files Browse the repository at this point in the history
Flakify the system
  • Loading branch information
delroth authored Apr 18, 2024
2 parents 2b38403 + b1686b3 commit c075aa9
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 78 deletions.
28 changes: 12 additions & 16 deletions DEV_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# How to build community builders

Building: Make a `build.cfg` file and run `./build.sh`:
# How to build community build box

```
pxeUrlPrefix https://yourdomain.com/pxe-images
pxeUrlSuffix netboot.ipxe
packetKey your-packet-api-key
packetDevice your-packet-device-id
buildHost user@an-aarch64-capable-build-box
imageName nixos-packet-aarch64-2018-01-03v1
pxeHost user@web-accessible-server
pxeDir /path/to/web/root
nix build .#hydraJobs.system
```

The build will happen on `buildHost` then copied directly from buildHost
to `pxeHost:pxeDir/imageName` (via netcat and openssl).
If the destination directory already exists, it will be overwritten.
You will need to be on an aarch64-linux machine or have an
aarch64-linux builder configured.

You can use
[nix-netboot-serve](https://github.com/DeterminateSystems/nix-netboot-serve/)
to provide netboot for the resulting configuration.

(TODO: this isn't implemented yet)
The production machine boots via the [build on hydra.nixos.org](TODO)
using netboot.nixos.org, which is also running nix-netboot-serve.

Update the PXE url and restart the server with `./restart.sh`. The PXE
URL will be calculated by `pxeUrlPrefix/imageName/pxeUrlSuffix`.
91 changes: 32 additions & 59 deletions configuration.nix
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
{ pkgs ? import ./nix { system = "aarch64-linux"; }
}:
let
makeNetboot = config:
let
config_evaled = import "${pkgs.path}/nixos/lib/eval-config.nix" config;
build = config_evaled.config.system.build;
kernelTarget = config_evaled.pkgs.stdenv.hostPlatform.linux-kernel.target;
in
pkgs.symlinkJoin {
name="netboot";
paths=[
build.netbootRamdisk
build.kernel
build.netbootIpxeScript
];
postBuild = ''
mkdir -p $out/nix-support
echo "file ${kernelTarget} $out/${kernelTarget}" >> $out/nix-support/hydra-build-products
echo "file initrd $out/initrd" >> $out/nix-support/hydra-build-products
echo "file ipxe $out/netboot.ipxe" >> $out/nix-support/hydra-build-products
'';
};

postDeviceCommands = pkgs.writeScript "post-device-commands"
''
#!/bin/sh
set -eu
set -o pipefail
PATH="${pkgs.coreutils}/bin:${pkgs.util-linux}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${pkgs.e2fsprogs}/bin:${pkgs.btrfs-progs}/bin"
exec ${./post-devices.sh}
'';

postMountCommands = pkgs.writeScript "post-mount-commands"
''
#!/bin/sh
set -eu
set -o pipefail
PATH="${pkgs.coreutils}/bin:${pkgs.util-linux}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${pkgs.e2fsprogs}/bin"
exec ${./persistence.sh}
'';

ofborg = builtins.storePath ./nix/ofborg-path;

in makeNetboot {
system = "aarch64-linux";
modules = [
"${pkgs.path}/nixos/modules/profiles/all-hardware.nix"
"${pkgs.path}/nixos/modules/profiles/minimal.nix"
{ pkgs, modulesPath, lib, ... }: {
imports = [
(modulesPath + "/profiles/all-hardware.nix")
(modulesPath + "/profiles/minimal.nix")

./modules/netboot.nix

Expand Down Expand Up @@ -155,8 +104,26 @@ in makeNetboot {
security.sudo.wheelNeedsPassword = false;

boot.supportedFilesystems = [ "zfs" ];
boot.initrd.postDeviceCommands = "${postDeviceCommands}";
boot.initrd.postMountCommands = "${postMountCommands}";
boot.initrd.postDeviceCommands = "${pkgs.writeScript "post-device-commands" ''
#!/bin/sh
set -eu
set -o pipefail
PATH="${pkgs.coreutils}/bin:${pkgs.util-linux}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${pkgs.e2fsprogs}/bin:${pkgs.btrfs-progs}/bin"
exec ${./post-devices.sh}
''}";
boot.initrd.postMountCommands = "${pkgs.writeScript "post-mount-commands" ''
#!/bin/sh
set -eu
set -o pipefail
PATH="${pkgs.coreutils}/bin:${pkgs.util-linux}/bin:${pkgs.gnugrep}/bin:${pkgs.gnused}/bin:${pkgs.e2fsprogs}/bin"
exec ${./persistence.sh}
''}";
boot.postBootCommands = ''
ls -la /
rm /etc/ssh/ssh_host_*
Expand Down Expand Up @@ -210,7 +177,13 @@ in makeNetboot {
environment.etc.host-nix-channel.source = pkgs.path;
})

({pkgs, ...}: {
{
options.ofborg.package = lib.mkOption {
description = "Ofborg package";
type = lib.types.package;
};
}
({pkgs, config, ...}: {
users.users.gc-of-borg = {
description = "GC Of Borg Workers";
home = "/var/lib/gc-of-borg";
Expand Down Expand Up @@ -255,7 +228,7 @@ in makeNetboot {
git config --global user.name "GrahamCOfBorg"
export RUST_BACKTRACE=1
${ofborg}/bin/builder /persist/ofborg/config-${id}.json
${config.ofborg.package}/bin/builder /persist/ofborg/config-${id}.json
'';
};

Expand Down
79 changes: 79 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
inputs.ofborg.url = "github:nixos/ofborg";
outputs = { nixpkgs, self, ofborg }: {
nixosConfigurations.aarch64-build-box = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
./configuration.nix
{ ofborg.package = ofborg.packages.aarch64-linux.ofborg.rs; }
];
};
hydraJobs.system = self.nixosConfigurations.aarch64-build-box.config.system.build.toplevel;
};
}
4 changes: 1 addition & 3 deletions users.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ lib, ... }:
let
pkgs = import <nixpkgs> {};
inherit (pkgs) lib;

users = {
# 1. Generate an SSH key for your root account and add the public
# key to a file matching your name in ./keys/
Expand Down

0 comments on commit c075aa9

Please sign in to comment.