home-manager: improve command line option handling

This commit is contained in:
Robert Helgesson 2017-01-15 23:32:57 +01:00
parent e0fd58709c
commit a5c8362f7b
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86
2 changed files with 51 additions and 9 deletions

View file

@ -119,9 +119,18 @@ First create a file `~/.nixpkgs/home.nix` containing
To activate this configuration you can then run To activate this configuration you can then run
``` ```
$ home-manager switch ~/.nixpkgs/home.nix $ home-manager switch
``` ```
or if you are not feeling so lucky,
```
$ home-manager build
```
which will create a `result` link to a directory containing an
activation script and the generated home directory files.
[Nix]: https://nixos.org/nix/ [Nix]: https://nixos.org/nix/
[NixOS]: https://nixos.org/ [NixOS]: https://nixos.org/
[Nixpkgs]: https://nixos.org/nixpkgs/ [Nixpkgs]: https://nixos.org/nixpkgs/

View file

@ -66,22 +66,55 @@ function doListPackages() {
} }
function doHelp() { function doHelp() {
echo "Usage: $0 COMMAND" echo "Usage: $0 [OPTION] COMMAND"
echo
echo "Options"
echo
echo " -f FILE The home configuration file. Default is ~/.nixpkgs/home.nix"
echo " -n Do a dry run, only prints what actions would be taken"
echo " -h Print this help"
echo echo
echo "Commands" echo "Commands"
echo " help Print this help" echo " help Print this help"
echo " build CONF Build configuration into result directory" echo " build Build configuration into result directory"
echo " switch CONF Build and activate configuration" echo " switch Build and activate configuration"
echo " generations List all home environment generations" echo " generations List all home environment generations"
echo " packages List all packages installed in home-manager-path" echo " packages List all packages installed in home-manager-path"
} }
case "$1" in CONFIG_FILE="$HOME/.nixpkgs/home.nix"
while getopts f:nh opt; do
case $opt in
f)
CONFIG_FILE=$OPTARG
;;
n)
export DRY_RUN=1
;;
h)
doHelp
exit 0
;;
*)
echo "Unknown option -$OPTARG" >&2
doHelp >&2
exit 1
;;
esac
done
# Get rid of the options.
shift "$((OPTIND-1))"
cmd="$*"
case "$cmd" in
build) build)
doBuild "$2" "result" doBuild "$CONFIG_FILE" "result"
;; ;;
switch) switch)
doSwitch "$2" doSwitch "$CONFIG_FILE"
;; ;;
generations) generations)
doListGens doListGens
@ -93,8 +126,8 @@ case "$1" in
doHelp doHelp
;; ;;
*) *)
echo "Unknown command: $1" echo "Unknown command: $cmd"
doHelp doHelp >&2
exit 1 exit 1
;; ;;
esac esac