diff --git a/nix/lib.nix b/nix/lib.nix index 642dd510f..b3ac391f9 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -21,8 +21,9 @@ in rec { }; # Generate a nix file from an opam file - opam2nix = { src, opamFile ? findOpamFile src, ... }@args: - pkgs.runCommandNoCC (args.pname or opamFile + ".nix") args + opam2nix = + { src, opamFile ? findOpamFile src, name ? opamFile + ".nix", ... }: + pkgs.runCommandNoCC name { } "cat ${src}/${opamFile} | ${pkgs.glibc.bin}/bin/iconv -c -f utf-8 -t ascii | ${opam-parser} > $out"; # Traverse OPAM repository, producing an extension to @@ -42,10 +43,15 @@ in rec { opam2nix { src = "${repo}/packages/${name}/${name}.${version}"; opamFile = "opam"; - pname = name; - inherit version; + name = "${name}.nix"; + }; + package = version: + self.callPackage (file version) { + extraArgs = { + pname = name; + inherit version; + }; }; - package = version: self.callPackage (file version) { }; latest = package (latestVersion (versions name)); others = map package (versions name); in latest // { @@ -66,14 +72,13 @@ in rec { # Extension that adds callOPAMPackage to the package set callOPAMPackage = self: super: { - callOPAMPackage = src: newAttrs: overrides: - (self.callPackage (opam2nix (newAttrs // { inherit src; })) - overrides).overrideAttrs ({ buildInputs, ... }@args: - { - inherit src; - buildInputs = buildInputs ++ newAttrs.extraBuildInputs or [ ]; - propagatedBuildInputs = buildInputs - ++ newAttrs.extraBuildInputs or [ ]; - } // newAttrs); + callOPAMPackage = src: extraArgs: overrides: + (self.callPackage (opam2nix (extraArgs // { inherit src; })) + (overrides // { inherit extraArgs; })).overrideAttrs ({ buildInputs, ... }@args: { + inherit src; + buildInputs = buildInputs ++ extraArgs.extraBuildInputs or [ ]; + propagatedBuildInputs = buildInputs + ++ extraArgs.extraBuildInputs or [ ]; + }); }; } diff --git a/nix/opam-parser.hs b/nix/opam-parser.hs index b4a4d8cb3..236d7649f 100644 --- a/nix/opam-parser.hs +++ b/nix/opam-parser.hs @@ -38,9 +38,9 @@ opam2nix OPAM {..} = sepspace = mconcat . intersperse " " . normalize preparephase = mconcat . intersperse " " . mconcat . intersperse ["\n"] in - "{ stdenv, fetchzip, " <>deps<> " }:\n" - <>"with {};\n" -- Awful hack to allow this to evaluate even if some of the variables are undefined - <>"stdenv.mkDerivation rec {\n" + "{ stdenv, fetchzip, " <>deps<> ", extraArgs ? { } }:\n" + <>"with extraArgs;\n" -- Awful hack to allow this to evaluate even if some of the variables are undefined + <>"stdenv.mkDerivation (rec {\n" <>foldMap (\name' -> " pname = \""<>name'<>"\";\n") name <>foldMap (\version' -> " version = \""<>version'<>"\";\n") version <>foldMap (\url -> " src = builtins.fetchTarball { url = \""<>url<>"\"; };\n") source @@ -58,8 +58,7 @@ opam2nix OPAM {..} = <>preparephase checkPhase' <>"\nrunHook postCheck\n'';\n") checkPhase <>" installPhase = ''\nrunHook preInstall\nopaline -prefix $out -libdir $OCAMLFIND_DESTDIR\nrunHook postInstall\n'';\n" - - <>"}\n" + <>"} // extraArgs)\n" update :: Maybe a -> a -> Maybe a update old new = if isNothing old then Just new else old @@ -196,18 +195,7 @@ listParser valueParser = whiteSpace = optional $ many $ oneOf " \n" main :: IO () -main = do - initialOPAM <- OPAM - <$> A.optional (getEnv "pname") - <*> A.optional (getEnv "version") - <*> pure Nothing - <*> pure Nothing - <*> pure Nothing - <*> pure Nothing - <*> pure Nothing - <*> pure Nothing - - getContents >>= \s -> case parse opamFile "(unknown)" s of +main = getContents >>= \s -> case parse opamFile "(unknown)" s of Left e -> print e - Right fs -> putStrLn $ opam2nix $ evaluateFields initialOPAM fs + Right fs -> putStrLn $ opam2nix $ evaluateFields (OPAM Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing) fs -- Right fs -> mapM_ print fs diff --git a/vendors/ligo-utils/memory-proto-alpha/tezos-memory-proto-alpha.opam b/vendors/ligo-utils/memory-proto-alpha/tezos-memory-proto-alpha.opam index e6ca037cc..44ca90da2 100644 --- a/vendors/ligo-utils/memory-proto-alpha/tezos-memory-proto-alpha.opam +++ b/vendors/ligo-utils/memory-proto-alpha/tezos-memory-proto-alpha.opam @@ -1,5 +1,5 @@ opam-version: "2.0" -name: "memory-proto-alpha" +name: "tezos-memory-proto-alpha" version: "1.0" synopsis: "Tezos Protocol Alpha in memory" maintainer: "Galfour "