Compare commits

...

14 Commits

1 changed files with 44 additions and 18 deletions

View File

@ -7,10 +7,18 @@ set -e -o pipefail
makeConf() { makeConf() {
# Skip everything if main config already present # Skip everything if main config already present
[[ -e /etc/nixos/configuration.nix ]] && return 0 [[ -e /etc/nixos/configuration.nix ]] && return 0
if [[ $PASSWORD == null ]]; then if [[ -z $PASSWORD ]]; then
export PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode) export PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode)
fi fi
if [[ -z $DNS_PROVIDER_TYPE ]]; then
export DNS_PROVIDER_TYPE='CLOUDFLARE'
fi
if [[ -z $STAGING_ACME ]]; then
export STAGING_ACME='false'
fi
export ESCAPED_PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode | jq -Rs .) export ESCAPED_PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode | jq -Rs .)
export HASHED_PASSWORD=$( mkpasswd -m sha-512 "$PASSWORD" ) export HASHED_PASSWORD=$( mkpasswd -m sha-512 "$PASSWORD" )
@ -21,12 +29,9 @@ makeConf() {
# Prevent grep for sending error code 1 (and halting execution) when no lines are selected : https://www.unix.com/man-page/posix/1P/grep # Prevent grep for sending error code 1 (and halting execution) when no lines are selected : https://www.unix.com/man-page/posix/1P/grep
local IFS=$'\n' local IFS=$'\n'
for trypath in /root/.ssh/authorized_keys /home/$SUDO_USER/.ssh/authorized_keys $HOME/.ssh/authorized_keys; do
[[ -r "$trypath" ]] \
&& keys=$(sed -E 's/^.*((ssh|ecdsa)-[^[:space:]]+)[[:space:]]+([^[:space:]]+)([[:space:]]*.*)$/\1 \3\4/' "$trypath") \
&& break
done
local network_import="" local network_import=""
[[ -n "$doNetConf" ]] && network_import="./networking.nix # generated at runtime by nixos-infect"
cat > /etc/nixos/userdata/userdata.json << EOF cat > /etc/nixos/userdata/userdata.json << EOF
{ {
@ -34,17 +39,26 @@ makeConf() {
"token": "$API_TOKEN", "token": "$API_TOKEN",
"skippedMigrations": ["migrate_to_selfprivacy_channel", "mount_volume"] "skippedMigrations": ["migrate_to_selfprivacy_channel", "mount_volume"]
}, },
"backblaze": { "backup": {
"provider": "BACKBLAZE",
"accountId": "$BACKBLAZE_KEY_ID", "accountId": "$BACKBLAZE_KEY_ID",
"accountKey": "$BACKBLAZE_ACCOUNT_KEY", "accountKey": "$BACKBLAZE_ACCOUNT_KEY",
"bucket": "$BACKBLAZE_BUCKET_NAME" "bucket": "$BACKBLAZE_BUCKET_NAME"
}, },
"bitwarden": { "bitwarden": {
"enable": true, "enable": true,
"location": "sdb" "location": "sda"
}, },
"cloudflare": { "dns": {
"apiKey": "$CF_TOKEN" "provider": "$DNS_PROVIDER_TYPE",
"apiKey": "$CF_TOKEN",
"useStagingACME": $STAGING_ACME
},
"email": {
"location": "sda"
},
"server": {
"provider": "DIGITALOCEAN"
}, },
"databasePassword": "$DB_PASSWORD", "databasePassword": "$DB_PASSWORD",
"domain": "$DOMAIN", "domain": "$DOMAIN",
@ -54,11 +68,11 @@ makeConf() {
"enable": true, "enable": true,
"adminPassword": $ESCAPED_PASSWORD, "adminPassword": $ESCAPED_PASSWORD,
"databasePassword": $ESCAPED_PASSWORD, "databasePassword": $ESCAPED_PASSWORD,
"location": "sdb" "location": "sda"
}, },
"gitea": { "gitea": {
"enable": true, "enable": true,
"location": "sdb" "location": "sda"
}, },
"jitsi": { "jitsi": {
"enable": true "enable": true
@ -68,15 +82,15 @@ makeConf() {
}, },
"pleroma": { "pleroma": {
"enable": false, "enable": false,
"location": "sdb" "location": "sda"
}, },
"timezone": "Europe/Uzhgorod", "timezone": "Europe/Uzhgorod",
"resticPassword": $ESCAPED_PASSWORD, "resticPassword": $ESCAPED_PASSWORD,
"username": "$LUSER", "username": "$LUSER",
"volumes": [ "volumes": [
{ {
"device": "/dev/sdb", "device": "/dev/sda",
"mountPoint": "/volumes/sdb", "mountPoint": "/volumes/sda",
"fsType": "ext4" "fsType": "ext4"
} }
], ],
@ -102,13 +116,22 @@ EOF
) )
fi fi
availableKernelModules=('"ata_piix"' '"uhci_hcd"' '"xen_blkfront"')
if isX86_64; then
availableKernelModules+=('"vmw_pvscsi"')
fi
# If you rerun this later, be sure to prune the filesSystems attr # If you rerun this later, be sure to prune the filesSystems attr
cat > /etc/nixos/hardware-configuration.nix << EOF cat > /etc/nixos/hardware-configuration.nix << EOF
{ modulesPath, ... }: { modulesPath, ... }:
{ {
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; imports = [
(modulesPath + "/profiles/qemu-guest.nix")
$network_import
];
$bootcfg $bootcfg
boot.initrd.kernelModules = [ "nvme" ]; boot.initrd.kernelModules = [ "nvme" ];
boot.initrd.availableKernelModules = [ ${availableKernelModules[@]} ];
fileSystems."/" = { device = "$rootfsdev"; fsType = "$rootfstype"; }; fileSystems."/" = { device = "$rootfsdev"; fsType = "$rootfstype"; };
} }
EOF EOF
@ -163,7 +186,10 @@ EOF
networking = { networking = {
nameservers = [ ${nameservers[@]} ]; nameservers = [ ${nameservers[@]} ];
defaultGateway = "${gateway}"; defaultGateway = "${gateway}";
defaultGateway6 = "${gateway6}"; defaultGateway6 = {
address = "${gateway6}";
interface = "${eth0_name}";
};
dhcpcd.enable = false; dhcpcd.enable = false;
$predictable_inames $predictable_inames
interfaces = { interfaces = {
@ -312,7 +338,7 @@ infect() {
#addgroup nixbld -g 30000 || true #addgroup nixbld -g 30000 || true
#for i in {1..10}; do adduser -DH -G nixbld nixbld$i || true; done #for i in {1..10}; do adduser -DH -G nixbld nixbld$i || true; done
curl -L https://nixos.org/nix/install | $SHELL curl -L https://nixos.org/nix/install | sh -s -- --no-channel-add
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source ~/.nix-profile/etc/profile.d/nix.sh source ~/.nix-profile/etc/profile.d/nix.sh