diff options
| author | Nathan Henrie <n8henrie@NatePro.home.arpa> | 2022-10-18 12:50:14 -0600 |
|---|---|---|
| committer | Nathan Henrie <nate@n8henrie.com> | 2022-12-14 03:44:26 -0700 |
| commit | 5452c8c638b59b5d6b123d81d3fa6bad07d00617 (patch) | |
| tree | 85d64a692915f9994890f5182de22b77e91172dd /pkgs | |
| parent | 6349b99bc2b96ded34d068a88c7c5ced406b7f7f (diff) | |
Add support for submodules in flakes
Fixes https://github.com/LnL7/nix-darwin/issues/549
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/nix-tools/darwin-rebuild.sh | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index a57fad7..530ff82 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -121,9 +121,16 @@ if [ -z "$action" ]; then showSyntax; fi flakeFlags=(--extra-experimental-features 'nix-command flakes') if [ -n "$flake" ]; then - if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then - flake="${BASH_REMATCH[1]}" - flakeAttr="${BASH_REMATCH[2]}" + # Offical regex from https://www.rfc-editor.org/rfc/rfc3986#appendix-B + if [[ "${flake}" =~ ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? ]]; then + scheme=${BASH_REMATCH[2]} + authority=${BASH_REMATCH[4]} + path=${BASH_REMATCH[5]} + queryWithQuestion=${BASH_REMATCH[6]} + fragment=${BASH_REMATCH[9]} + + flake=${scheme}${authority}${path}${queryWithQuestion} + flakeAttr=${fragment} fi if [ -z "$flakeAttr" ]; then flakeAttr=$(hostname -s) @@ -138,7 +145,16 @@ if [ -n "$flake" ]; then cmd=info fi - flake=$(nix "${flakeFlags[@]}" flake "$cmd" --json "${extraMetadataFlags[@]}" "${extraLockFlags[@]}" -- "$flake" | jq -r .url) + metadata=$(nix "${flakeFlags[@]}" flake "$cmd" --json "${extraMetadataFlags[@]}" "${extraLockFlags[@]}" -- "$flake") + flake=$(jq -r .url <<<"${metadata}") + + if [ "$(jq -r .resolved.submodules <<<"${metadata}")" = "true" ]; then + if [[ "$flake" == *'?'* ]]; then + flake="${flake}&submodules=1" + else + flake="${flake}?submodules=1" + fi + fi fi if [ "$action" != build ] && [ -z "$flake" ]; then |
