Skip to main content

Bootstrap NixOS depuis GitHub

Bootstrap NixOS avec une configuration hébergée sur GitHub

Cette méthode permet de déployer rapidement NixOS avec une configuration préparée à l’avance, sans avoir besoin de s’authentifier sur GitHub pendant l’installation.

Principe

  1. Préparer un repo GitHub public avec la configuration NixOS
  2. Pendant l’installation, télécharger cette configuration via HTTPS (anonyme)
  3. Lancer l’installation

Étape 1 : Créer le repo sur GitHub (depuis son PC)

Sur GitHub :

  1. New repository
  2. Nom : nixos-bootstrap-minimal
  3. Public (important pour le téléchargement anonyme)
  4. Créer

Cloner le repo sur son PC :

git clone git@github.com:MONUSER/nixos-bootstrap-minimal.git
cd nixos-bootstrap-minimal

Créer le fichier configuration.nix :

{ config, pkgs, ... }:

{
  imports = [
    ./hardware-configuration.nix
  ];

  # Nom de la machine (à adapter)
  networking.hostName = "nixos-server";

  # Fuseau horaire
  time.timeZone = "Europe/Zurich";

  # Locale
  i18n.defaultLocale = "en_US.UTF-8";
  i18n.extraLocaleSettings = {
    LC_TIME = "fr_CH.UTF-8";
    LC_MONETARY = "fr_CH.UTF-8";
  };

  # Réseau en DHCP
  networking.useDHCP = true;

  # Utilisateur admin
  users.users.admin = {
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" ];
    initialPassword = "changeme";
  };

  # Paquets de base
  environment.systemPackages = with pkgs; [
    git
    vim
    htop
    curl
  ];

  # SSH
  services.openssh.enable = true;
  services.openssh.settings.PermitRootLogin = "no";

  # Firewall
  networking.firewall.enable = true;
  networking.firewall.allowedTCPPorts = [ 22 ];

  # Version NixOS (adapter à l'ISO utilisée)
  system.stateVersion = "24.05";
}

Pousser sur GitHub :

git add configuration.nix
git commit -m "Configuration NixOS minimale"
git push

Étape 2 : Installation sur la machine cible

Booter sur l’ISO NixOS, puis :

Partitionner et monter

sudo -i

cfdisk /dev/sda
# sda1 : EFI (512M)
# sda2 : root (reste)

mkfs.fat -F 32 /dev/sda1
mkfs.ext4 /dev/sda2

mount /dev/sda2 /mnt
mkdir -p /mnt/boot
mount /dev/sda1 /mnt/boot

Générer hardware-configuration.nix

nixos-generate-config --root /mnt

Télécharger la configuration depuis GitHub

Option A - Avec curl (plus simple) :

cd /mnt/etc/nixos
rm configuration.nix

curl -L \
  https://raw.githubusercontent.com/MONUSER/nixos-bootstrap-minimal/main/configuration.nix \
  -o configuration.nix

Option B - Avec git clone :

cd /mnt/etc/nixos
rm configuration.nix

git clone https://github.com/MONUSER/nixos-bootstrap-minimal.git /tmp/bootstrap
cp /tmp/bootstrap/configuration.nix /mnt/etc/nixos/

Installer

nixos-install
reboot

Étape 3 : Après le premier boot

Se connecter :

  • Login : admin
  • Mot de passe : changeme

Changer le mot de passe immédiatement :

passwd

Adapter le hostname si nécessaire dans /etc/nixos/configuration.nix, puis :

sudo nixos-rebuild switch

Avantages de cette méthode

  • Aucune authentification GitHub requise pendant l’installation
  • Configuration préparée confortablement sur son PC
  • Reproductible : même configuration sur plusieurs machines
  • Versionné : historique des modifications dans Git