···3344Various scripts and Nushell modules that I maintain or use.
5566-# Nushell Modules
77-88-## Nebula
99-Wrapper to make setting up new hosts in a nebula network easier.
1010-1111-126# Scripts
137148## Nushell
-44
nushell/nebula/mod.nu
···11-# SPDX-License-Identifier: AGPL-3.0-only
22-# SPDX-FileCopyrightText: 2025 Shiloh Fen <shiloh@shilohfen.com>
33-44-const path_data: path = "~/.local/share/nebula" | path expand
55-const path_ca_cert: path = $path_data | path join "ca.crt"
66-const path_ca_key: path = $path_data | path join "ca.key"
77-const path_state: path = $path_data | path join "state.nuon"
88-99-export def sign [
1010- name: string
1111- groups: list<string>
1212-]: nothing -> record<path_cert: path, path_key: path> {
1313- if not ($path_ca_key | path exists) {
1414- error make {
1515- text: "No CA key found."
1616- help: "Run submodule `ca` to generate a CA before attempting to sign a device cert."
1717- }
1818- }
1919-2020- let tmp = mktemp -td "nebula-XXXXX"
2121- let path_device_cert = $tmp | path join $"($name).crt"
2222- let path_device_key = $tmp | path join $"($name).key"
2323- let ip_part = (open $path_state | get last_ip) + 1
2424-2525- nebula-cert sign -name $name -ca-crt $path_ca_cert -ca-key $path_ca_key -ip $"192.168.100.($ip_part)/24" -groups ($groups | str join ",") -out-crt $path_device_cert -out-key $path_device_key
2626-2727- {last_ip: $ip_part} | save -f $path_state
2828-2929- {
3030- path_cert: $path_device_cert
3131- path_key: $path_device_key
3232- }
3333-}
3434-3535-export def ca [
3636- name: string
3737-] {
3838- mkdir $path_data
3939- nebula-cert ca -name $name -out-crt $path_ca_cert -out-key $path_ca_key -encrypt
4040-4141- print "Certificate will be valid for one year. Be sure to set up an alert or calendar event to rotate your CA and certificates before then to ensure continued connectivity!"
4242-4343- {last_ip: 0} | save -f $path_state
4444-}