From a44cf5cf33b8421b2ec3ed70c4bd11761ef32bb6 Mon Sep 17 00:00:00 2001 From: user3301 <26126682+user3301@users.noreply.github.com> Date: Sat, 15 Aug 2026 07:12:56 +0000 Subject: [PATCH] Fix first-run WSL Home Manager activation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/README.nix.md | 8 +++++--- flake.nix | 19 ++++++++++++------- home/nixos-wsl.nix | 4 ++++ scripts/bootstrap-nixos-wsl.sh | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs/README.nix.md b/docs/README.nix.md index 501c903..48eccb0 100644 --- a/docs/README.nix.md +++ b/docs/README.nix.md @@ -24,9 +24,11 @@ nix --extra-experimental-features 'nix-command flakes' run github:user3301/dotfi the distribution's virtual disk; `nixos-anywhere` is intended to provision an SSH target and normally repartition its disks. -This creates the `user3301` configuration, clones the repository to -`/home/user3301/dotfiles`, and activates the local checkout. Then run -`wsl --shutdown` from PowerShell and reopen the distribution. +This first creates `user3301` without activating Home Manager, clones the +repository to `/home/user3301/dotfiles`, and then activates the full +configuration from that checkout. It is safe to rerun after an interrupted +bootstrap. When it completes, run `wsl --shutdown` from PowerShell and reopen +the distribution. ### NixOS Native ```bash diff --git a/flake.nix b/flake.nix index 788322f..a473674 100644 --- a/flake.nix +++ b/flake.nix @@ -137,20 +137,25 @@ specialArgs = { inherit inputs; }; }; + wslSystemModules = [ + nixos-wsl.nixosModules.wsl + ./systems/wsl/configuration.nix + ]; + in { # NixOS Configurations nixosConfigurations = { + # Minimal first-stage configuration used by the WSL bootstrap app. + nixos-wsl-bootstrap = mkSystem { + system = "x86_64-linux"; + modules = wslSystemModules; + }; + # NixOS WSL2 Configuration nixos-wsl = mkSystem { system = "x86_64-linux"; - modules = [ - # WSL-specific module - nixos-wsl.nixosModules.wsl - - # System configuration - ./systems/wsl/configuration.nix - + modules = wslSystemModules ++ [ # Home Manager integration home-manager.nixosModules.home-manager { diff --git a/home/nixos-wsl.nix b/home/nixos-wsl.nix index c8279b1..962f481 100644 --- a/home/nixos-wsl.nix +++ b/home/nixos-wsl.nix @@ -12,6 +12,10 @@ ./modules/languages.nix ]; + # During bootstrap there may be no active user session yet. Let the normal + # WSL login start sockets and services instead of starting them during switch. + systemd.user.startServices = "suggest"; + home = { # User information username = "user3301"; diff --git a/scripts/bootstrap-nixos-wsl.sh b/scripts/bootstrap-nixos-wsl.sh index ad19b26..d302964 100644 --- a/scripts/bootstrap-nixos-wsl.sh +++ b/scripts/bootstrap-nixos-wsl.sh @@ -32,7 +32,7 @@ fi export NIX_CONFIG="${NIX_CONFIG:-}"$'\nexperimental-features = nix-command flakes' echo "Creating the ${target_user} NixOS configuration..." -sudo nixos-rebuild switch --flake "${flake_ref}#nixos-wsl" +sudo nixos-rebuild switch --flake "${flake_ref}#nixos-wsl-bootstrap" if [[ -d "${target_repo}/.git" ]]; then echo "Updating the existing checkout at ${target_repo}..."