some changes to simplify the script for my usage

This commit is contained in:
CherryKitten 2024-04-07 12:12:30 +02:00
parent ed6a87bc3a
commit 9f826561fd
Signed by: sammy
GPG key ID: 98D8F75FB0658276

View file

@ -4,22 +4,10 @@
set -e -o pipefail
autodetectProvider() {
if [ -e /etc/hetzner-build ]; then
PROVIDER="hetznercloud"
fi
}
makeConf() {
# Skip everything if main config already present
[[ -e /etc/nixos/configuration.nix ]] && return 0
# Lightsail config is not like the others
if [ "$PROVIDER" = "lightsail" ]; then
makeLightsailConf
return 0
fi
# NB <<"EOF" quotes / $ ` in heredocs, <<EOF does not
mkdir -p /etc/nixos
# Prevent grep for sending error code 1 (and halting execution) when no lines are selected : https://www.unix.com/man-page/posix/1P/grep
@ -32,7 +20,7 @@ makeConf() {
done
local network_import=""
[[ -n "$doNetConf" ]] && network_import="./networking.nix # generated at runtime by nixos-infect"
network_import="./networking.nix # generated at runtime by nixos-infect"
cat > /etc/nixos/configuration.nix << EOF
{ ... }:
let
@ -101,19 +89,9 @@ $bootcfg
}
EOF
[[ -n "$doNetConf" ]] && makeNetworkingConf || true
makeNetworkingConf || true
}
makeLightsailConf() {
mkdir -p /etc/nixos
cat > /etc/nixos/configuration.nix << EOF
{ config, pkgs, modulesPath, lib, ... }:
{
imports = [ "\${modulesPath}/virtualisation/amazon-image.nix" ];
boot.loader.grub.device = lib.mkForce "/dev/nvme0n1";
}
EOF
}
makeNetworkingConf() {
# XXX It'd be better if we used procfs for all this...
@ -393,15 +371,6 @@ infect() {
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
}
if [ ! -v PROVIDER ]; then
autodetectProvider
fi
[ "$PROVIDER" = "digitalocean" ] && doNetConf=y # digitalocean requires detailed network config to be generated
[ "$PROVIDER" = "lightsail" ] && newrootfslabel="nixos"
if [[ "$PROVIDER" = "digitalocean" ]] || [[ "$PROVIDER" = "servarica" ]] || [[ "$PROVIDER" = "hetznercloud" ]]; then
doNetConf=y # some providers require detailed network config to be generated
fi
checkEnv
prepareEnv