aboutsummaryrefslogtreecommitdiff
path: root/home-manager/install.nix
blob: c58c0ba747874517de75ab2dba9dbe86358fbd91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ home-manager, runCommand }:

runCommand
  "home-manager-install"
  {
    propagatedBuildInputs = [ home-manager ];
    preferLocalBuild = true;
    allowSubstitutes = false;
    shellHookOnly = true;
    shellHook = ''
      confFile="''${XDG_CONFIG_HOME:-$HOME/.config}/nixpkgs/home.nix"

      if [[ ! -e $confFile ]]; then
        echo
        echo "Creating initial Home Manager configuration..."

        mkdir -p "$(dirname "$confFile")"
        cat > $confFile <<EOF
      { config, pkgs, ... }:

      {
        # Let Home Manager install and manage itself.
        programs.home-manager.enable = true;
      }
      EOF
      fi

      echo
      echo "Creating initial Home Manager generation..."
      echo

      if home-manager switch; then
        cat <<EOF

      All done! The home-manager tool should now be installed and you
      can edit

          $confFile

      to configure Home Manager. Run 'man home-configuration.nix' to
      see all available options.
      EOF
        exit 0
      else
        cat <<EOF

      Uh oh, the installation failed! Please create an issue at

          https://github.com/rycee/home-manager/issues

      if the error seems to be the fault of Home Manager.
      EOF
        exit 1
      fi
    '';
  }
  ''
    echo This derivation is not buildable, instead run it using nix-shell.
    exit 1
  ''