Skip to content

Commit

Permalink
home-manager: point <home-manager> to project root
Browse files Browse the repository at this point in the history
Before this path would point to the modules path. Using the project
root instead makes it possible to set `<home-manager>` to point to a
downloadable archive of Home Manager. This should make it
significantly easier to install and keep Home Manager up to date.

To match this change we also deprecate the Home Manager option

    programs.home-manager.modulesPath

and instead ask users to use

    programs.home-manager.path
  • Loading branch information
rycee committed Oct 23, 2017
1 parent 5605e46 commit bf3a8c6
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 21 deletions.
16 changes: 14 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# Simply defer to the home-manager script derivation.
import ./home-manager
{ pkgs ? import <nixpkgs> {} }:

rec {
home-manager = import ./home-manager {
inherit pkgs;
path = ./.;
};

install =
pkgs.runCommand
"home-manager-install"
{ propagatedBuildInputs = [ home-manager ]; }
"";
}
13 changes: 6 additions & 7 deletions home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{ pkgs

# Extra path to the Home Manager modules. If set then this path will
# be tried before `$HOME/.config/nixpkgs/home-manager/modules` and
# `$HOME/.nixpkgs/home-manager/modules`.
, modulesPath ? null
# Extra path to Home Manager. If set then this path will be tried
# before `$HOME/.config/nixpkgs/home-manager` and
# `$HOME/.nixpkgs/home-manager`.
, path ? null
}:

let

modulesPathStr = if modulesPath == null then "" else modulesPath;
pathStr = if path == null then "" else path;

in

Expand All @@ -24,8 +24,7 @@ pkgs.stdenv.mkDerivation {
--subst-var-by bash "${pkgs.bash}" \
--subst-var-by coreutils "${pkgs.coreutils}" \
--subst-var-by less "${pkgs.less}" \
--subst-var-by MODULES_PATH '${modulesPathStr}' \
--subst-var-by HOME_MANAGER_EXPR_PATH "${./home-manager.nix}"
--subst-var-by HOME_MANAGER_PATH '${pathStr}'
'';

meta = with pkgs.stdenv.lib; {
Expand Down
18 changes: 9 additions & 9 deletions home-manager/home-manager
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ function setConfigFile() {
exit 1
}

function setHomeManagerModulesPath() {
local modulesPath
for modulesPath in "@MODULES_PATH@" \
"$HOME/.config/nixpkgs/home-manager/modules" \
"$HOME/.nixpkgs/home-manager/modules" ; do
if [[ -e "$modulesPath" ]] ; then
export NIX_PATH="$NIX_PATH${NIX_PATH:+:}home-manager=$modulesPath"
function setHomeManagerNixPath() {
local path
for path in "@HOME_MANAGER_PATH@" \
"$HOME/.config/nixpkgs/home-manager" \
"$HOME/.nixpkgs/home-manager" ; do
if [[ -e "$path" || "$path" =~ ^https?:// ]] ; then
export NIX_PATH="$NIX_PATH${NIX_PATH:+:}home-manager=$path"
return
fi
done
}

function doBuildAttr() {
setConfigFile
setHomeManagerModulesPath
setHomeManagerNixPath

local extraArgs="$*"

Expand All @@ -67,7 +67,7 @@ function doBuildAttr() {
fi

nix-build \
"@HOME_MANAGER_EXPR_PATH@" \
"<home-manager/home-manager/home-manager.nix>" \
$extraArgs \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
Expand Down
2 changes: 1 addition & 1 deletion home-manager/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ with pkgs.lib;

let

env = import <home-manager> {
env = import <home-manager/modules> {
configuration =
let
conf = import confPath;
Expand Down
40 changes: 40 additions & 0 deletions modules/misc/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,46 @@ in
chosen version.
'';
}

{
time = "2017-10-23T22:54:33+00:00";
condition = config.programs.home-manager.modulesPath != null;
message = ''
The 'programs.home-manager.modulesPath' option is now
deprecated and will be removed on November 24, 2017. Please
use the option 'programs.home-manager.path' instead.
'';
}

{
time = "2017-10-23T23:10:29+00:00";
condition = !config.programs.home-manager.enable;
message = ''
Unfortunately, due to some internal restructuring it is no
longer possible to install the home-manager command when
having
home-manager = import ./home-manager { inherit pkgs; };
in the '~/.config/nixpkgs/config.nix' package override
section. Attempting to use the above override will now
result in the error "cannot coerce a set to a string".
To resolve this please delete the override from the
'config.nix' file and either link the Home Manager overlay
$ ln -s ~/.config/nixpkgs/home-manager/overlay.nix \
~/.config/nixpkgs/overlays/home-manager.nix
or add
programs.home-manager.enable = true;
to your Home Manager configuration. The latter is
recommended as the home-manager tool then is updated
automatically whenever you do a switch.
'';
}
];
};
}
28 changes: 26 additions & 2 deletions modules/programs/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ in
programs.home-manager = {
enable = mkEnableOption "Home Manager";

path = mkOption {
type = types.nullOr types.str;
default = null;
example = "$HOME/devel/home-manager";
description = ''
The default path to use for Home Manager. If this path does
not exist then
<filename>$HOME/.config/nixpkgs/home-manager</filename> and
<filename>$HOME/.nixpkgs/home-manager</filename> will be
attempted.
'';
};

modulesPath = mkOption {
type = types.nullOr types.str;
default = null;
Expand All @@ -25,17 +38,28 @@ in
path does not exist then
<filename>$HOME/.config/nixpkgs/home-manager/modules</filename>
and <filename>$HOME/.nixpkgs/home-manager/modules</filename>
will be attempted.
will be attempted. DEPRECATED: Use
<varname>programs.home-manager.path</varname> instead.
'';
};
};
};

config = mkIf cfg.enable {
assertions = [{
assertion = cfg.path == null || cfg.modulesPath == null;
message = "Cannot simultaneously use "
+ "'programs.home-manager.path' and "
+ "'programs.home-manager.modulesPath'.";
}];

home.packages = [
(import ../../home-manager {
inherit pkgs;
inherit (cfg) modulesPath;
path =
if cfg.modulesPath != null
then "$(dirname ${cfg.modulesPath})"
else cfg.path;
})
];

Expand Down

0 comments on commit bf3a8c6

Please sign in to comment.