Skip to content

Spacemacs activation fails on fresh NixOS install #36

@cwage

Description

@cwage

Problem

The home.activation.spacemacs script in home/default.nix fails on a fresh NixOS install in two ways:

1. Non-empty .emacs.d directory

Emacs auto-creates ~/.emacs.d/ (with eln-cache/, auto-save-list/, etc.) before the Home Manager activation runs. The activation script checks for ~/.emacs.d/.git but not for the directory itself, so git clone fails:

Activating spacemacs
fatal: destination path '/home/cwage/.emacs.d' already exists and is not an empty directory.

This causes exit code 128, which fails the entire Home Manager activation.

2. Systemd timeout on clone

Even when .emacs.d is clean, the Spacemacs repo clone can exceed the home-manager-cwage.service timeout (TimeoutStartSec=5m), causing systemd to SIGTERM the activation:

Mar 18 16:06:46 thinkpad hm-activate-cwage[8325]: Cloning into '/home/cwage/.emacs.d'...
Mar 18 16:11:46 thinkpad systemd[1]: home-manager-cwage.service: start operation timed out. Terminating.

Logs

Full journal from the session showing both failures:

# First boot — failed because .emacs.d existed (emacs auto-created it)
Mar 18 15:51:49 hm-activate-cwage[766]: Activating spacemacs
Mar 18 15:51:49 hm-activate-cwage[1066]: fatal: destination path '/home/cwage/.emacs.d' already exists and is not an empty directory.
Mar 18 15:51:49 systemd[1]: home-manager-cwage.service: Failed with result 'exit-code'.

# Second attempt after `rm -rf ~/.emacs.d` — clone started but hit 5min timeout
Mar 18 16:06:46 hm-activate-cwage[8089]: Activating spacemacs
Mar 18 16:06:46 hm-activate-cwage[8325]: Cloning into '/home/cwage/.emacs.d'...
Mar 18 16:11:46 systemd[1]: home-manager-cwage.service: start operation timed out. Terminating.
Mar 18 16:11:46 systemd[1]: home-manager-cwage.service: Failed with result 'timeout'.

Current code

home.activation.spacemacs = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
  if [ ! -d "$HOME/.emacs.d/.git" ]; then
    run ${pkgs.git}/bin/git clone --branch develop https://github.com/syl20bnr/spacemacs.git "$HOME/.emacs.d"
  fi
'';

Proposed fix

home.activation.spacemacs = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
  if [ ! -d "$HOME/.emacs.d/.git" ]; then
    run rm -rf "$HOME/.emacs.d"
    run ${pkgs.git}/bin/git clone --depth 1 --branch develop https://github.com/syl20bnr/spacemacs.git "$HOME/.emacs.d"
  fi
'';
  • rm -rf handles the non-empty directory (safe since we confirmed no .git exists)
  • --depth 1 makes the clone much faster, avoiding the timeout (full Spacemacs history isn't needed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions