From bf3a8c63838c998e06e6825ac80f1a9a7f735a57 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 21 Oct 2017 20:51:28 +0200 Subject: [PATCH] home-manager: point to project root Before this path would point to the modules path. Using the project root instead makes it possible to set `` 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 --- default.nix | 16 +++++++++++-- home-manager/default.nix | 13 +++++----- home-manager/home-manager | 18 +++++++------- home-manager/home-manager.nix | 2 +- modules/misc/news.nix | 40 +++++++++++++++++++++++++++++++ modules/programs/home-manager.nix | 28 ++++++++++++++++++++-- 6 files changed, 96 insertions(+), 21 deletions(-) diff --git a/default.nix b/default.nix index d9024779c..b9eedd470 100644 --- a/default.nix +++ b/default.nix @@ -1,2 +1,14 @@ -# Simply defer to the home-manager script derivation. -import ./home-manager +{ pkgs ? import {} }: + +rec { + home-manager = import ./home-manager { + inherit pkgs; + path = ./.; + }; + + install = + pkgs.runCommand + "home-manager-install" + { propagatedBuildInputs = [ home-manager ]; } + ""; +} diff --git a/home-manager/default.nix b/home-manager/default.nix index 5fed40554..943d61e81 100644 --- a/home-manager/default.nix +++ b/home-manager/default.nix @@ -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 @@ -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; { diff --git a/home-manager/home-manager b/home-manager/home-manager index 55c717eea..6bfc46e66 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -40,13 +40,13 @@ 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 @@ -54,7 +54,7 @@ function setHomeManagerModulesPath() { function doBuildAttr() { setConfigFile - setHomeManagerModulesPath + setHomeManagerNixPath local extraArgs="$*" @@ -67,7 +67,7 @@ function doBuildAttr() { fi nix-build \ - "@HOME_MANAGER_EXPR_PATH@" \ + "" \ $extraArgs \ --argstr confPath "$HOME_MANAGER_CONFIG" \ --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" diff --git a/home-manager/home-manager.nix b/home-manager/home-manager.nix index a6c9259f8..206a1bcef 100644 --- a/home-manager/home-manager.nix +++ b/home-manager/home-manager.nix @@ -9,7 +9,7 @@ with pkgs.lib; let - env = import { + env = import { configuration = let conf = import confPath; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f14248ecb..b17b04542 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -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. + ''; + } ]; }; } diff --git a/modules/programs/home-manager.nix b/modules/programs/home-manager.nix index ad7278a12..2fac0bce3 100644 --- a/modules/programs/home-manager.nix +++ b/modules/programs/home-manager.nix @@ -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 + $HOME/.config/nixpkgs/home-manager and + $HOME/.nixpkgs/home-manager will be + attempted. + ''; + }; + modulesPath = mkOption { type = types.nullOr types.str; default = null; @@ -25,17 +38,28 @@ in path does not exist then $HOME/.config/nixpkgs/home-manager/modules and $HOME/.nixpkgs/home-manager/modules - will be attempted. + will be attempted. DEPRECATED: Use + programs.home-manager.path 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; }) ];