From 406cb56d06247487386667162131703f7d6cc68f Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 3 Nov 2024 12:01:00 +1100 Subject: [PATCH 1/3] Back out "Add support for submodules in flakes" This backs out commit 5452c8c638b59b5d6b123d81d3fa6bad07d00617. --- pkgs/nix-tools/darwin-rebuild.sh | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index e627b3ce8..ba9c2e8b1 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -157,19 +157,12 @@ 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 - scheme=${BASH_REMATCH[1]} # eg. http: - authority=${BASH_REMATCH[3]} # eg. //www.ics.uci.edu - path=${BASH_REMATCH[5]} # eg. /pub/ietf/uri/ - queryWithQuestion=${BASH_REMATCH[6]} - fragment=${BASH_REMATCH[9]} - - flake=${scheme}${authority}${path}${queryWithQuestion} - flakeAttr=${fragment} +if [[ -n "$flake" ]]; then + if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then + flake="${BASH_REMATCH[1]}" + flakeAttr="${BASH_REMATCH[2]}" fi - if [ -z "$flakeAttr" ]; then + if [[ -z "$flakeAttr" ]]; then flakeAttr=$(scutil --get LocalHostName) fi flakeAttr=darwinConfigurations.${flakeAttr} @@ -182,16 +175,7 @@ if [ -n "$flake" ]; then cmd=info fi - 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 + flake=$(nix "${flakeFlags[@]}" flake "$cmd" --json "${extraMetadataFlags[@]}" "${extraLockFlags[@]}" -- "$flake" | jq -r .url) fi if [ "$action" != build ]; then From 1d8c91b40e82853e76a0a308cfc5ddc5a72667d3 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 3 Nov 2024 12:30:47 +1100 Subject: [PATCH 2/3] darwin-rebuild: do not resolve flake path Backport of https://github.com/NixOS/nixpkgs/commit/c274d045ac254afe96b1f8139e974ada2c42059e Fixes #549 --- pkgs/nix-tools/darwin-rebuild.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index ba9c2e8b1..7824913d2 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -168,16 +168,6 @@ if [[ -n "$flake" ]]; then flakeAttr=darwinConfigurations.${flakeAttr} fi -if [ -n "$flake" ]; then - if nix "${flakeFlags[@]}" flake metadata --version &>/dev/null; then - cmd=metadata - else - cmd=info - fi - - flake=$(nix "${flakeFlags[@]}" flake "$cmd" --json "${extraMetadataFlags[@]}" "${extraLockFlags[@]}" -- "$flake" | jq -r .url) -fi - if [ "$action" != build ]; then if [ -n "$flake" ]; then extraBuildFlags+=("--no-link") From 53b9de4d6ca51c38299f265630b811fed6d4fd05 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sun, 3 Nov 2024 12:18:02 +1100 Subject: [PATCH 3/3] ci: remove tests to ensure submodules work --- .github/workflows/test.yml | 115 ------------------------------------- 1 file changed, 115 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7ad8c0a2..3dd8bcf3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -153,60 +153,6 @@ jobs: run: | . /etc/static/bashrc darwin-rebuild build --flake ./modules/examples/flake#simple --override-input nix-darwin . --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} - - name: Test git submodules - run: | - . /etc/static/bashrc - - mkdir -p /tmp/{test-nix-darwin-submodules,example-submodule} - - pushd /tmp/example-submodule - echo '"hello"' > hello.nix - git init - git add . - git commit -m "add a submodule we will import" - popd - - cp -a ./modules/examples/. /tmp/test-nix-darwin-submodules - cp -a ./modules/examples/flake/flake.nix /tmp/test-nix-darwin-submodules - - pushd /tmp/test-nix-darwin-submodules - /usr/bin/sed -i.bak \ - '\#modules = \[#s#configuration#configuration ./simple.nix#' \ - ./flake.nix - /usr/bin/sed -i.bak \ - 's#pkgs.vim#pkgs."${import ./submodule-test/hello.nix}"#' \ - ./simple.nix - git init - git add flake.nix simple.nix - git \ - -c protocol.file.allow=always \ - submodule add /tmp/example-submodule submodule-test - popd - - # Should fail - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} \ - && { - printf 'succeeded while expecting failure due to submodule\n' >/dev/stderr - exit 1 - } - # Should also fail - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules?submodules=0#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} \ - && { - printf 'succeeded while expecting failure due to submodule\n' >/dev/stderr - exit 1 - } - - # Should succeed - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules?submodules=1#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/${{ env.CURRENT_STABLE_CHANNEL }} \ install-flake-against-unstable: runs-on: macos-12 @@ -236,64 +182,3 @@ jobs: run: | . /etc/static/bashrc darwin-rebuild build --flake ./modules/examples/flake#simple --override-input nix-darwin . --override-input nixpkgs nixpkgs/nixpkgs-unstable - - name: Test git submodules - run: | - . /etc/static/bashrc - - mkdir -p /tmp/{test-nix-darwin-submodules,example-submodule} - - pushd /tmp/example-submodule - echo '"hello"' > hello.nix - git init - git add . - git commit -m "add a submodule we will import" - popd - - cp -a ./modules/examples/. /tmp/test-nix-darwin-submodules - cp -a ./modules/examples/flake/flake.nix /tmp/test-nix-darwin-submodules - - pushd /tmp/test-nix-darwin-submodules - /usr/bin/sed -i.bak \ - '\#modules = \[#s#configuration#configuration ./simple.nix#' \ - ./flake.nix - /usr/bin/sed -i.bak \ - 's#pkgs.vim#pkgs."${import ./submodule-test/hello.nix}"#' \ - ./simple.nix - git init - git add flake.nix simple.nix - git \ - -c protocol.file.allow=always \ - submodule add /tmp/example-submodule submodule-test - popd - - # Should fail - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/nixpkgs-unstable \ - && { - printf 'succeeded while expecting failure due to submodule\n' >/dev/stderr - exit 1 - } - - # Should also fail - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules?submodules=0#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/nixpkgs-unstable \ - && { - printf 'succeeded while expecting failure due to submodule\n' >/dev/stderr - exit 1 - } - - # Should succeed - darwin-rebuild build \ - --flake /tmp/test-nix-darwin-submodules?submodules=1#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/nixpkgs-unstable - - # Should also succeed - darwin-rebuild build \ - --flake git+file:///tmp/test-nix-darwin-submodules?submodules=1#simple \ - --override-input nix-darwin . \ - --override-input nixpkgs nixpkgs/nixpkgs-unstable