Merge branch 'fix/default-conf-dir'
This commit is contained in:
commit
3793dfeab5
11
README.md
11
README.md
|
@ -46,15 +46,16 @@ Currently the easiest way to install Home Manager is as follows:
|
||||||
since Home Manager uses these directories to manage your profile
|
since Home Manager uses these directories to manage your profile
|
||||||
generations. On NixOS these should already be available.
|
generations. On NixOS these should already be available.
|
||||||
|
|
||||||
2. Clone the Home Manager repository into the `~/.nixpkgs` directory:
|
2. Clone the Home Manager repository into the `~/.config/nixpkgs`
|
||||||
|
directory:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone https://github.com/rycee/home-manager ~/.nixpkgs/home-manager
|
$ git clone https://github.com/rycee/home-manager ~/.config/nixpkgs/home-manager
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Add Home Manager to your user's Nixpkgs, for example by adding it
|
3. Add Home Manager to your user's Nixpkgs, for example by adding it
|
||||||
to the `packageOverrides` section in your `~/.nixpkgs/config.nix`
|
to the `packageOverrides` section in your
|
||||||
file:
|
`~/.config/nixpkgs/config.nix` file:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
|
@ -84,7 +85,7 @@ the htop and fortune packages, installs Emacs with a few extra
|
||||||
packages enabled, installs Firefox with Adobe Flash enabled, and
|
packages enabled, installs Firefox with Adobe Flash enabled, and
|
||||||
enables the user gpg-agent service.
|
enables the user gpg-agent service.
|
||||||
|
|
||||||
First create a file `~/.nixpkgs/home.nix` containing
|
First create a file `~/.config/nixpkgs/home.nix` containing
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{ pkgs, modulesPath ? "$HOME/.nixpkgs/home-manager/modules" }:
|
{ pkgs, modulesPath ? "$HOME/.config/nixpkgs/home-manager/modules" }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
homeManagerExpr = pkgs.writeText "home-manager.nix" ''
|
homeManagerExpr = pkgs.writeText "home-manager.nix" ''
|
||||||
{ pkgs ? import <nixpkgs> {}, confPath, modulesPath }:
|
{ pkgs ? import <nixpkgs> {}, confPath }:
|
||||||
|
|
||||||
let
|
let
|
||||||
env = import modulesPath {
|
env = import <home-manager> {
|
||||||
configuration = import confPath;
|
configuration = import confPath;
|
||||||
pkgs = pkgs;
|
pkgs = pkgs;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,39 +7,67 @@ PATH=@coreutils@/bin:$PATH
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
function doBuild() {
|
# Attempts to set the HOME_MANAGER_CONFIG global variable.
|
||||||
if [[ -z "$1" ]]; then
|
#
|
||||||
echo "Need to provide path to configuration file."
|
# If no configuration file can be found then this function will print
|
||||||
|
# an error message and exit with an error code.
|
||||||
|
function setConfigFile() {
|
||||||
|
if [[ -v HOME_MANAGER_CONFIG ]] ; then
|
||||||
|
if [[ ! -e "$HOME_MANAGER_CONFIG" ]] ; then
|
||||||
|
echo "No configure file found at $HOME_MANAGER_CONFIG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$2" ]]; then
|
HOME_MANAGER_CONFIG="$(realpath "$HOME_MANAGER_CONFIG")"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local confFile
|
||||||
|
for confFile in "$HOME/.config/nixpkgs/home.nix" \
|
||||||
|
"$HOME/.nixpkgs/home.nix" ; do
|
||||||
|
if [[ -e "$confFile" ]] ; then
|
||||||
|
HOME_MANAGER_CONFIG="$confFile"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "No configuration file found. " \
|
||||||
|
"Please create one at ~/.config/nixpkgs/home.nix"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHomeManagerModulesPath() {
|
||||||
|
local modulesPath
|
||||||
|
for modulesPath in "@MODULES_PATH@" \
|
||||||
|
"$HOME/.nixpkgs/home-manager/modules" ; do
|
||||||
|
if [[ -e "$modulesPath" ]] ; then
|
||||||
|
export NIX_PATH="$NIX_PATH${NIX_PATH:+:}home-manager=$modulesPath"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function doBuild() {
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
echo "Need to provide generation output path."
|
echo "Need to provide generation output path."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -e "$2" ]]; then
|
if [[ -e "$1" ]]; then
|
||||||
echo "The output path $2 already exists."
|
echo "The output path $1 already exists."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local confFile output
|
setConfigFile
|
||||||
confFile="$(realpath "$1")"
|
setHomeManagerModulesPath
|
||||||
|
|
||||||
|
output="$(realpath "$1")"
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -r "$confFile" ]]; then
|
export NIX_PATH="$NIX_PATH${NIX_PATH:+:}home-manager=@MODULES_PATH@"
|
||||||
echo "No such configuration file: $1"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output="$(realpath "$2")"
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local extraArgs
|
local extraArgs
|
||||||
extraArgs=""
|
extraArgs=""
|
||||||
|
@ -54,8 +82,7 @@ function doBuild() {
|
||||||
|
|
||||||
nix-build $extraArgs \
|
nix-build $extraArgs \
|
||||||
"@HOME_MANAGER_EXPR_PATH@" \
|
"@HOME_MANAGER_EXPR_PATH@" \
|
||||||
--argstr modulesPath "@MODULES_PATH@" \
|
--argstr confPath "$HOME_MANAGER_CONFIG" \
|
||||||
--argstr confPath "$confFile" \
|
|
||||||
-A activation-script \
|
-A activation-script \
|
||||||
-o "$output"
|
-o "$output"
|
||||||
}
|
}
|
||||||
|
@ -64,7 +91,7 @@ function doSwitch() {
|
||||||
local wrkdir
|
local wrkdir
|
||||||
wrkdir="$(mktemp -d)"
|
wrkdir="$(mktemp -d)"
|
||||||
|
|
||||||
if doBuild "$1" "$wrkdir/generation" ; then
|
if doBuild "$wrkdir/generation" ; then
|
||||||
"$wrkdir/generation/activate"
|
"$wrkdir/generation/activate"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -93,7 +120,8 @@ function doHelp() {
|
||||||
echo
|
echo
|
||||||
echo "Options"
|
echo "Options"
|
||||||
echo
|
echo
|
||||||
echo " -f FILE The home configuration file. Default is ~/.nixpkgs/home.nix"
|
echo " -f FILE The home configuration file."
|
||||||
|
echo " Default is '~/.config/nixpkgs/home.nix'."
|
||||||
echo " -I PATH Add a path to the Nix expression search path."
|
echo " -I PATH Add a path to the Nix expression search path."
|
||||||
echo " -v Verbose output"
|
echo " -v Verbose output"
|
||||||
echo " -n Do a dry run, only prints what actions would be taken"
|
echo " -n Do a dry run, only prints what actions would be taken"
|
||||||
|
@ -107,13 +135,12 @@ function doHelp() {
|
||||||
echo " packages List all packages installed in home-manager-path"
|
echo " packages List all packages installed in home-manager-path"
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_FILE="$HOME/.nixpkgs/home.nix"
|
|
||||||
EXTRA_NIX_PATH=()
|
EXTRA_NIX_PATH=()
|
||||||
|
|
||||||
while getopts f:I:vnh opt; do
|
while getopts f:I:vnh opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
f)
|
f)
|
||||||
CONFIG_FILE=$OPTARG
|
HOME_MANAGER_CONFIG="$OPTARG"
|
||||||
;;
|
;;
|
||||||
I)
|
I)
|
||||||
EXTRA_NIX_PATH+=("$OPTARG")
|
EXTRA_NIX_PATH+=("$OPTARG")
|
||||||
|
@ -143,10 +170,10 @@ cmd="$*"
|
||||||
|
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
build)
|
build)
|
||||||
doBuild "$CONFIG_FILE" "result"
|
doBuild "result"
|
||||||
;;
|
;;
|
||||||
switch)
|
switch)
|
||||||
doSwitch "$CONFIG_FILE"
|
doSwitch
|
||||||
;;
|
;;
|
||||||
generations)
|
generations)
|
||||||
doListGens
|
doListGens
|
||||||
|
|
Loading…
Reference in a new issue