diff --git a/home-manager/install.nix b/home-manager/install.nix index 2dfef324e894..63e63dc9aadc 100644 --- a/home-manager/install.nix +++ b/home-manager/install.nix @@ -1,4 +1,6 @@ -{ home-manager, runCommand }: +{ home-manager, runCommand +, shellHook ? "exec ${home-manager}/bin/home-manager init --switch --no-flake" +}: let @@ -12,7 +14,7 @@ in runCommand "home-manager-install" { propagatedBuildInputs = [ home-manager ]; preferLocalBuild = true; shellHookOnly = true; - shellHook = "exec ${home-manager}/bin/home-manager init --switch --no-flake"; + inherit shellHook; } '' ${hmBashLibInit} _iError 'This derivation is not buildable, please run it using nix-shell.' diff --git a/tests/integration/standalone/alice-home-dotprofile.nix b/tests/integration/standalone/alice-home-dotprofile.nix new file mode 100644 index 000000000000..8759dcccef60 --- /dev/null +++ b/tests/integration/standalone/alice-home-dotprofile.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: + +{ + home.username = "alice"; + home.homeDirectory = "/home/alice"; + home.stateVersion = "24.11"; + programs.home-manager.enable = true; + + # Write .profile + home.file = { + ".profile".text = '' + echo sourcing dotprofile + ''; + }; +} diff --git a/tests/integration/standalone/override-install.nix b/tests/integration/standalone/override-install.nix new file mode 100644 index 000000000000..5eb4ebf1caec --- /dev/null +++ b/tests/integration/standalone/override-install.nix @@ -0,0 +1,6 @@ +{ hmInstall ? (import { }).install }: +hmInstall.override { + shellHook = '' + exec home-manager init --switch --no-flake -b backup + ''; +} diff --git a/tests/integration/standalone/standard-basics.nix b/tests/integration/standalone/standard-basics.nix index a3efb04112ac..234ff0cb4d72 100644 --- a/tests/integration/standalone/standard-basics.nix +++ b/tests/integration/standalone/standard-basics.nix @@ -122,6 +122,16 @@ machine.succeed("test ! -e /home/alice/.local/state/home-manager") machine.succeed("test ! -e /home/alice/.local/state/nix/profiles/home-manager") + with subtest("Home Manager Installation with preexisting dotfile"): + succeed_as_alice("touch /home/alice/.profile") + + succeed_as_alice("cp ${ + ./alice-home-dotprofile.nix + } /home/alice/.config/home-manager/home.nix") + + succeed_as_alice("nix-shell ${./override-install.nix}") + succeed_as_alice("test -e /home/alice/.profile.backup") + logout_alice() ''; }