Skip to content

Commit

Permalink
Set default flake directory as /etc/nix-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzime committed Jul 9, 2024
1 parent fabc653 commit da0b8b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkgs/nix-tools/darwin-rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extraProfileFlags=()
profile=@profile@
action=
flake=
noFlake=

while [ $# -gt 0 ]; do
i=$1; shift 1
Expand Down Expand Up @@ -77,6 +78,9 @@ while [ $# -gt 0 ]; do
flake=$1
shift 1
;;
--no-flake)
noFlake=1
;;
-L|-vL|--print-build-logs|--impure|--recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file|--refresh)
extraLockFlags+=("$i")
;;
Expand Down Expand Up @@ -137,6 +141,19 @@ if [ -z "$action" ]; then showSyntax; fi

flakeFlags=(--extra-experimental-features 'nix-command flakes')

# Search the default locations for the system-wide nix-darwin configuration
if [[ -z $flake && -z $noFlake ]]; then
if [[ -e /etc/nix-darwin/flake.nix ]]; then
flake="$(dirname "$(readlink -f /etc/nix-darwin/flake.nix)")"
elif [[ -e ~/.config/nix-darwin/flake.nix ]]; then
flake="$(dirname "$(readlink -f ~/.config/nix-darwin/flake.nix)")"
elif [[ -e ~/.nixpkgs/flake.nix ]]; then
flake="$(dirname "$(readlink -f ~/.nixpkgs/flake.nix)")"
fi
fi

# For convenience, use the hostname as the default configuration to
# build from the flake.
if [ -n "$flake" ]; then
# Offical regex from https://www.rfc-editor.org/rfc/rfc3986#appendix-B
if [[ "${flake}" =~ ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? ]]; then
Expand Down

0 comments on commit da0b8b1

Please sign in to comment.