Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch submodules if supported, and warn if submodules are used but not supported #352

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions nix/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,27 @@ let
if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
submodules = if spec ? submodules then spec.submodules else false;
submoduleArg =
let
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
emptyArgWithWarning =
if submodules == true
then
builtins.trace
(
"The niv input \"${name}\" uses submodules "
+ "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
+ "does not support them"
)
{}
else {};
in
if nixSupportsSubmodules
then { inherit submodules; }
else emptyArgWithWarning;
in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }
// (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else {});
builtins.fetchGit
({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);

fetch_local = spec: spec.path;

Expand Down
4 changes: 4 additions & 0 deletions src/Niv/Sources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ data SourcesNixVersion
V25
| -- formatting fix
V26
| -- Support submodules for git repos
V27
deriving stock (Bounded, Enum, Eq)

-- | A user friendly version
Expand Down Expand Up @@ -207,6 +209,7 @@ sourcesVersionToText = \case
V24 -> "24"
V25 -> "25"
V26 -> "26"
V27 -> "27"

latestVersionMD5 :: T.Text
latestVersionMD5 = sourcesVersionToMD5 maxBound
Expand Down Expand Up @@ -245,6 +248,7 @@ sourcesVersionToMD5 = \case
V24 -> "116c2d936f1847112fef0013771dab28"
V25 -> "6612caee5814670e5e4d9dd1b71b5f70"
V26 -> "937bff93370a064c9000f13cec5867f9"
V27 -> "8031ba9d8fbbc7401c800d0b84278ec8"

-- | The MD5 sum of ./nix/sources.nix
sourcesNixMD5 :: IO T.Text
Expand Down