forked from divnix/digga
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nixos-generators devshell module
that injects our custom formats (at present, limited to `bootstrap-iso`) into the nixos-generators format search path. Additionally, introduce the `bootstrap-iso` command that wraps `nixos-generate --format bootstrap-iso`. fix: divnix#450
- Loading branch information
Showing
14 changed files
with
223 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
nixos-generators = import ./nixos-generators; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
if [ -z "${PRJ_ROOT:-}" ]; then | ||
if ! PRJ_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"; then | ||
# shellcheck disable=SC2016 | ||
printf 1>&2 -- '%s: %s. %s. %s.\n' \ | ||
"${0##*/}" 'unable to locate your project root ($PRJ_ROOT)' \ | ||
'bud relies on the project root for locating the bootstrap ISO' \ | ||
'Aborting' | ||
|
||
exit 1 | ||
fi | ||
fi | ||
|
||
boostrapIsoRequireHost() { | ||
if [ "$#" -lt 1 ]; then | ||
printf 1>&2 -- 'Error: missing required <host> argument.\n' "${0##*/}" | ||
bootstrapIsoHelp 1 | ||
fi | ||
} | ||
|
||
bootstrapIsoBuild() { | ||
boostrapIsoRequireHost "$@" || return | ||
|
||
local host="$1" | ||
shift | ||
|
||
# XXX the way nixos-generate handles flake specifications requires that we do | ||
# not quote the host as we would with, e.g.: | ||
# nix build ".#nixosConfigurations.\"my.host.name\".config.system.build.toplevel" | ||
nixos-generate "$@" --format bootstrap-iso --flake "${PRJ_ROOT}#${host}" | ||
} | ||
|
||
bootstrapIsoBurn() { | ||
boostrapIsoRequireHost "$@" || return | ||
bud="$(command -v bud)" || return | ||
bootstrapIsoBuild "$@" --out-link "${PRJ_ROOT?}/result" || return | ||
sudo -E "$bud" burn | ||
} | ||
|
||
bootstrapIsoHelp() { | ||
printf 1>&2 -- 'Usage: %s {build,burn,help} <host> [<nixos-generate-arg> ...]\n' "${0##*/}" | ||
return "${1:-0}" | ||
} | ||
|
||
cmd="${1:-}" | ||
shift 2>/dev/null || : | ||
|
||
case "$cmd" in | ||
build) | ||
bootstrapIsoBuild "$@" | ||
;; | ||
burn) | ||
bootstrapIsoBurn "$@" | ||
;; | ||
help) | ||
bootstrapIsoHelp | ||
;; | ||
*) | ||
bootstrapIsoHelp 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
cfg = config.digga.nixos-generators; | ||
|
||
searchPathVar = "NIXOS_GENERATORS_FORMAT_SEARCH_PATH"; | ||
|
||
bootstrap-iso = { | ||
category = "devos"; | ||
name = "bootstrap-iso"; | ||
help = "Create and burn a bootstrap ISO for the specified NixOS configuration"; | ||
command = builtins.readFile ./bootstrap-iso; | ||
}; | ||
in | ||
{ | ||
options.digga.nixos-generators = | ||
let | ||
inherit (lib) mkOption mkEnableOption types; | ||
in | ||
{ | ||
enable = mkEnableOption "nixos-generators extensions"; | ||
|
||
category = mkOption { | ||
type = types.str; | ||
default = "generators"; | ||
description = "category for the nixos-generate and bootstrap-iso commands"; | ||
}; | ||
|
||
package = mkOption { | ||
type = types.package; | ||
default = pkgs.nixos-generators; | ||
description = "package providing nixos-generators"; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
commands = [ | ||
{ inherit (cfg) category package; } | ||
bootstrap-iso | ||
]; | ||
|
||
env = [ | ||
{ | ||
name = searchPathVar; | ||
|
||
# prepend our formats directory to the nixos-generate search path | ||
eval = '' | ||
''${${searchPathVar}:+''${${searchPathVar}}:}${toString ./formats} | ||
''; | ||
} | ||
]; | ||
}; | ||
} |
68 changes: 68 additions & 0 deletions
68
modules/devShell/nixos-generators/formats/bootstrap-iso.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
let | ||
getFqdn = config: | ||
let | ||
net = config.networking; | ||
fqdn = | ||
if net.domain != null | ||
then "${net.hostName}.${net.domain}" | ||
else net.hostName; | ||
in | ||
fqdn; | ||
in | ||
|
||
{ config, lib, modulesPath, suites, self, inputs, ... }@args: { | ||
|
||
imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix" ]; | ||
|
||
isoImage.isoBaseName = "bootstrap-" + (getFqdn config); | ||
isoImage.contents = [{ | ||
source = self; | ||
target = "/devos/"; | ||
}]; | ||
isoImage.storeContents = [ | ||
self.devShell.${config.nixpkgs.system} | ||
# include also closures that are "switched off" by the | ||
# above profile filter on the local config attribute | ||
config.system.build.toplevel | ||
] ++ builtins.attrValues inputs; | ||
|
||
# confilcts with networking.wireless which might be slightly | ||
# more useful on a stick | ||
networking.networkmanager.enable = lib.mkForce false; | ||
# confilcts with networking.wireless | ||
networking.wireless.iwd.enable = lib.mkForce false; | ||
|
||
# Set up a link-local boostrap network | ||
# See also: https://github.com/NixOS/nixpkgs/issues/75515#issuecomment-571661659 | ||
networking.usePredictableInterfaceNames = lib.mkForce true; # so prefix matching works | ||
networking.useNetworkd = lib.mkForce true; | ||
networking.useDHCP = lib.mkForce false; | ||
networking.dhcpcd.enable = lib.mkForce false; | ||
systemd.network = { | ||
# https://www.freedesktop.org/software/systemd/man/systemd.network.html | ||
networks."boostrap-link-local" = { | ||
matchConfig = { | ||
Name = "en* wl* ww*"; | ||
}; | ||
networkConfig = { | ||
Description = "Link-local host bootstrap network"; | ||
MulticastDNS = true; | ||
LinkLocalAddressing = "ipv6"; | ||
DHCP = "yes"; | ||
}; | ||
address = [ | ||
# fall back well-known link-local for situations where MulticastDNS is not available | ||
"fe80::47" # 47: n=14 i=9 x=24; n+i+x | ||
]; | ||
extraConfig = '' | ||
# Unique, yet stable. Based off the MAC address. | ||
IPv6LinkLocalAddressGenerationMode = "eui64" | ||
''; | ||
}; | ||
}; | ||
|
||
# Required by nixos-generate | ||
formatAttr = "isoImage"; | ||
filename = "*.iso"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
nixConfig = import ./nix-config.nix; | ||
} |
File renamed without changes.