add some helper scripts

This commit is contained in:
2023-11-10 21:03:33 +01:00
parent d4619a2f9e
commit a9153b7c4c
7 changed files with 175 additions and 3 deletions

4
packages/default.nix Normal file
View File

@@ -0,0 +1,4 @@
final: prev: {
netali-configure-net-ruby = final.callPackage ./netali-configure-net-ruby {};
netali-default-config-ruby = final.callPackage ./netali-default-config-ruby {};
}

View File

@@ -0,0 +1,20 @@
{ writeShellScriptBin, iproute2 }:
writeShellScriptBin "netali-configure-net-ruby" ''
if [[ $# -ne 2 ]]; then
echo "Usage: netali-configure-net-ruby [interface] [last-ip-block]"
echo ""
echo "interface: name of the network interface to configure"
echo "last-ip-block: last block of the IPv6 address of this host"
exit 1
fi
INTERFACE=$1
LAST_IP_BLOCK=$2
${iproute2}/bin/ip link set up $INTERFACE
${iproute2}/bin/ip a a 2001:67c:a6c:a::$LAST_IP_BLOCK/64 dev $INTERFACE
${iproute2}/bin/ip r a default via fe80::1 dev $INTERFACE
echo "nameserver 2606:4700:4700::1111" > /etc/resolv.conf
''

View File

@@ -0,0 +1,81 @@
{ config, lib, pkgs, ... }:
{
imports =
[
./hardware-configuration.nix
];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.tmp.useTmpfs = true;
networking.nftables.enable = true;
security.sudo.wheelNeedsPassword = false;
users.users.netali = {
isNormalUser = true;
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOV4f3/OcNQIHqomvH0nGLDmXDlrO/u7JKE9Fgq2Vuqs me@netali.de" ];
};
time.timeZone = "Europe/Berlin";
i18n.defaultLocale = "en_US.UTF-8";
console = {
font = "Lat2-Terminus16";
keyMap = "de-latin1";
};
services.qemuGuest.enable = true;
system.stateVersion = "23.05";
networking.hostName = "$TARGET_HOSTNAME";
services.openssh.enable = true;
services.openssh.settings.PasswordAuthentication = false;
services.openssh.ports = [ 1022 ];
networking.useDHCP = false;
networking.dhcpcd.enable = false;
networking.nameservers = [ "2606:4700:4700::1111" "2606:4700:4700::1001" ];
nix = {
settings = {
trusted-users = [ "@wheel" ];
auto-optimise-store = true;
experimental-features = [ "nix-command" "flakes" ];
};
gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 14d";
};
extraOptions = ''
min-free = 104857600
max-free = 1073741824
''; # more readable: min-free = 100*1024*1024; max-free = 1024*1024*1024;
};
systemd.network = {
enable = true;
networks = {
"40-ens18" = {
name = "ens18";
networkConfig = {
IPv6AcceptRA = false;
};
address = [
"2001:67c:a6c:a::$LAST_IP_BLOCK/64"
];
gateway = [
"2001:67c:a6c:a::1"
];
};
};
};
}

View File

@@ -0,0 +1,18 @@
{ writeShellScriptBin, envsubst }:
writeShellScriptBin "netali-default-config-ruby" ''
if [[ $# -ne 3 ]]; then
echo "Usage: netali-default-config-ruby [out-path] [hostname] [last-ip-block]"
echo ""
echo "out-path: path to which the configuration will be written"
echo "hostname: path to which the configuration will be written"
echo "last-ip-block: last block of the IPv6 address of this host"
exit 1
fi
OUT_PATH=$1
export TARGET_HOSTNAME="$2"
export LAST_IP_BLOCK="$3"
${envsubst}/bin/envsubst -i ${./config-template.txt} -o $OUT_PATH
''