Make variable resolution more uniform

This commit is contained in:
Alexander Bantyev 2020-03-26 20:24:04 +03:00
parent 4d585096ba
commit 1dabc4442d
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
3 changed files with 26 additions and 33 deletions

View File

@ -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";
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:
{
callOPAMPackage = src: extraArgs: overrides:
(self.callPackage (opam2nix (extraArgs // { inherit src; }))
(overrides // { inherit extraArgs; })).overrideAttrs ({ buildInputs, ... }@args: {
inherit src;
buildInputs = buildInputs ++ newAttrs.extraBuildInputs or [ ];
buildInputs = buildInputs ++ extraArgs.extraBuildInputs or [ ];
propagatedBuildInputs = buildInputs
++ newAttrs.extraBuildInputs or [ ];
} // newAttrs);
++ extraArgs.extraBuildInputs or [ ];
});
};
}

View File

@ -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

View File

@ -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 <ligolang@gmail.com>"