@@ -122,7 +122,7 @@ let
122122 # This works because `cabal configure` does not include any of the `/nix/sore/`
123123 # paths in the `plan.json` (so materialized plan-nix will still work as expeced).
124124 # See tests/unit.nix for examples of input and output.
125− parseRepositoryBlock = cabalProjectFileName: sha256map: cabal-install: nix-tools: block:
125+ parseRepositoryBlock = cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: block:
126126 let
127127 lines = pkgs.lib.splitString "\n" block;
128128 # The first line will contain the repository name.
@@ -135,9 +135,27 @@ let
135135 in rec {
136136 # This is `some-name` from the `repository some-name` line in the `cabal.project` file.
137137 name = __head lines;
138− # The $HOME dir with `.cabal` sub directory after running `cabal new-update` to download the repository
139− home =
140− pkgs.evalPackages.runCommand name ({
138+ # The $HOME/.cabal/packages/${name} after running `cabal v2-update` to download the repository
139+ repoContents = if inputMap ? ${attrs.url}
140+ # If there is an input use it to make `file:` url and create a suitable `.cabal/packages/${name}` directory
141+ then pkgs.evalPackages.runCommand name ({
142+ nativeBuildInputs = [ cabal-install ];
143+ preferLocalBuild = true;
144+ }) ''
145+ HOME=$(mktemp -d)
146+ mkdir -p $HOME/.cabal/packages/${name}
147+ cat <<EOF > $HOME/.cabal/config
148+ repository ${name}
149+ url: file:${inputMap.${attrs.url}}
150+ ${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
151+ ${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"}
152+ ${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"}
153+ EOF
154+
155+ cabal v2-update ${name}
156+ cp -r $HOME/.cabal/packages/${name} $out
157+ ''
158+ else pkgs.evalPackages.runCommand name ({
141159 nativeBuildInputs = [ cabal-install pkgs.evalPackages.curl nix-tools ];
142160 LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.evalPackages.stdenv.buildPlatform.libc == "glibc") "${pkgs.evalPackages.glibcLocales}/lib/locale/locale-archive";
143161 LANG = "en_US.UTF-8";
@@ -147,8 +165,9 @@ let
147165 outputHashAlgo = "sha256";
148166 outputHash = sha256;
149167 }) ''
150− mkdir -p $out/.cabal
151− cat <<EOF > $out/.cabal/config
168+ HOME=$(mktemp -d)
169+ mkdir -p $HOME/.cabal/packages/${name}
170+ cat <<EOF > $HOME/.cabal/config
152171 repository ${name}
153172 url: ${attrs.url}
154173 ${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
@@ -157,8 +176,8 @@ let
157176 EOF
158177
159178 export SSL_CERT_FILE=${pkgs.evalPackages.cacert}/etc/ssl/certs/ca-bundle.crt
160− mkdir -p $out/.cabal/packages/${name}
161− HOME=$out cabal new-update ${name}
179+ cabal v2-update ${name}
180+ cp -r $HOME/.cabal/packages/${name} $out
162181 '';
163182 # Output of hackage-to-nix
164183 hackage = import (
@@ -169,34 +188,22 @@ let
169188 preferLocalBuild = true;
170189 } ''
171190 mkdir -p $out
172− hackage-to-nix $out ${home}/.cabal/packages/${name}/01-index.tar ${attrs.url}
191+ hackage-to-nix $out ${repoContents}/01-index.tar ${attrs.url}
173192 '');
174− # Tarball info in the same format as `extra-hackage-tarballs` passed in to cabalProject
175− tarball = {
176− ${name} = home + "/.cabal/packages/${name}/01-index.tar.gz";
193+ # Directory to `lndir` when constructing a suitable $HOME/.cabal dir
194+ repo = {
195+ ${name} = repoContents;
177196 };
178− # Replacement `repository` block using `file:` uri and the remaining text (text that was not part of the attribute block).
179− updatedText = ''
180− repository ${name}
181− url: file:${home + "/.cabal/packages/${name}"}
182− secure: True
183− root-keys:
184− key-threshold: 0
185− '' + pkgs.lib.strings.concatStringsSep "\n" x.snd;
186197 };
187198
188− parseRepositories = cabalProjectFileName: sha256map: cabal-install: nix-tools: projectFile:
199+ parseRepositories = cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: projectFile:
189200 let
190201 # This will leave the name of repository in the first line of each block
191202 blocks = pkgs.lib.splitString "\nrepository " ("\n" + projectFile);
192− initialText = pkgs.lib.lists.take 1 blocks;
193− repoBlocks = builtins.map (parseRepositoryBlock cabalProjectFileName sha256map cabal-install nix-tools) (pkgs.lib.lists.drop 1 blocks);
203+ repoBlocks = builtins.map (parseRepositoryBlock cabalProjectFileName sha256map inputMap cabal-install nix-tools) (pkgs.lib.lists.drop 1 blocks);
194204 in {
195205 extra-hackages = pkgs.lib.lists.map (block: block.hackage) repoBlocks;
196− tarballs = pkgs.lib.lists.foldl' (x: block: x // block.tarball) {} repoBlocks;
197− updatedText = pkgs.lib.strings.concatStringsSep "\n" (
198− initialText
199− ++ (builtins.map (x: x.updatedText) repoBlocks));
206+ repos = pkgs.lib.lists.foldl' (x: block: x // block.repo) {} repoBlocks;
200207 };
201208
202209in {