⚡ Skrip nixos-mirror.sh

Atur substituter tercepat untuk NixOS

Penjelasan

NixOS menggunakan nix.conf untuk mengatur substituter (mirror repository). Dengan menambahkan mirror tercepat, kita bisa mempercepat proses nix-env dan nixos-rebuild. Skrip ini otomatis backup konfigurasi lama dan menambahkan substituter baru.

⚠️ Jalankan dengan sudo karena butuh akses tulis ke /etc/nix/nix.conf.

Kode Skrip

      
#!/bin/bash
# nixos-mirror.sh — atur substituter mirror tercepat NixOS

set -e

CONF_FILE="/etc/nix/nix.conf"
BACKUP="/etc/nix/nix.conf.backup"

echo "[INFO] Membackup konfigurasi lama ke $BACKUP ..."
sudo cp "$CONF_FILE" "$BACKUP"

echo "[INFO] Menambahkan substituter mirror..."
sudo bash -c 'cat >> /etc/nix/nix.conf <<EOF

# Tambahan substituter mirror cepat
substituters = https://cache.nixos.org https://mirror.sjtu.edu.cn/nix-channels/store
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= mirror.sjtu.edu.cn-1:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
EOF'

echo "[INFO] Update channel..."
nix-channel --update

echo "[DONE] Substituter NixOS berhasil ditambahkan."
    
⬇️ Download nixos-mirror.sh
times;