From f2e0a6f78d5ebcf790046639e2edd5252b16e465 Mon Sep 17 00:00:00 2001 From: Jacek Galowicz Date: Thu, 21 Apr 2022 15:58:22 +0200 Subject: [PATCH] Fetch submodules if supported, and warn if submodules are used but not supported --- nix/sources.nix | 41 +++++++++++++++++++++++++++++++---------- src/Niv/Sources.hs | 4 ++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/nix/sources.nix b/nix/sources.nix index 41af0c6..6963775 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -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; @@ -149,14 +167,17 @@ let # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = diff --git a/src/Niv/Sources.hs b/src/Niv/Sources.hs index 01a1dee..fcb6d3c 100644 --- a/src/Niv/Sources.hs +++ b/src/Niv/Sources.hs @@ -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 @@ -207,6 +209,7 @@ sourcesVersionToText = \case V24 -> "24" V25 -> "25" V26 -> "26" + V27 -> "27" latestVersionMD5 :: T.Text latestVersionMD5 = sourcesVersionToMD5 maxBound @@ -245,6 +248,7 @@ sourcesVersionToMD5 = \case V24 -> "116c2d936f1847112fef0013771dab28" V25 -> "6612caee5814670e5e4d9dd1b71b5f70" V26 -> "937bff93370a064c9000f13cec5867f9" + V27 -> "8eb15aa505d1971b1593c3ba3a9e8646" -- | The MD5 sum of ./nix/sources.nix sourcesNixMD5 :: IO T.Text