Make variable resolution more uniform
This commit is contained in:
parent
4d585096ba
commit
1dabc4442d
33
nix/lib.nix
33
nix/lib.nix
@ -21,8 +21,9 @@ in rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Generate a nix file from an opam file
|
# Generate a nix file from an opam file
|
||||||
opam2nix = { src, opamFile ? findOpamFile src, ... }@args:
|
opam2nix =
|
||||||
pkgs.runCommandNoCC (args.pname or opamFile + ".nix") args
|
{ 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";
|
"cat ${src}/${opamFile} | ${pkgs.glibc.bin}/bin/iconv -c -f utf-8 -t ascii | ${opam-parser} > $out";
|
||||||
|
|
||||||
# Traverse OPAM repository, producing an extension to
|
# Traverse OPAM repository, producing an extension to
|
||||||
@ -42,10 +43,15 @@ in rec {
|
|||||||
opam2nix {
|
opam2nix {
|
||||||
src = "${repo}/packages/${name}/${name}.${version}";
|
src = "${repo}/packages/${name}/${name}.${version}";
|
||||||
opamFile = "opam";
|
opamFile = "opam";
|
||||||
pname = name;
|
name = "${name}.nix";
|
||||||
inherit version;
|
};
|
||||||
|
package = version:
|
||||||
|
self.callPackage (file version) {
|
||||||
|
extraArgs = {
|
||||||
|
pname = name;
|
||||||
|
inherit version;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
package = version: self.callPackage (file version) { };
|
|
||||||
latest = package (latestVersion (versions name));
|
latest = package (latestVersion (versions name));
|
||||||
others = map package (versions name);
|
others = map package (versions name);
|
||||||
in latest // {
|
in latest // {
|
||||||
@ -66,14 +72,13 @@ in rec {
|
|||||||
|
|
||||||
# Extension that adds callOPAMPackage to the package set
|
# Extension that adds callOPAMPackage to the package set
|
||||||
callOPAMPackage = self: super: {
|
callOPAMPackage = self: super: {
|
||||||
callOPAMPackage = src: newAttrs: overrides:
|
callOPAMPackage = src: extraArgs: overrides:
|
||||||
(self.callPackage (opam2nix (newAttrs // { inherit src; }))
|
(self.callPackage (opam2nix (extraArgs // { inherit src; }))
|
||||||
overrides).overrideAttrs ({ buildInputs, ... }@args:
|
(overrides // { inherit extraArgs; })).overrideAttrs ({ buildInputs, ... }@args: {
|
||||||
{
|
inherit src;
|
||||||
inherit src;
|
buildInputs = buildInputs ++ extraArgs.extraBuildInputs or [ ];
|
||||||
buildInputs = buildInputs ++ newAttrs.extraBuildInputs or [ ];
|
propagatedBuildInputs = buildInputs
|
||||||
propagatedBuildInputs = buildInputs
|
++ extraArgs.extraBuildInputs or [ ];
|
||||||
++ newAttrs.extraBuildInputs or [ ];
|
});
|
||||||
} // newAttrs);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ opam2nix OPAM {..} =
|
|||||||
sepspace = mconcat . intersperse " " . normalize
|
sepspace = mconcat . intersperse " " . normalize
|
||||||
preparephase = mconcat . intersperse " " . mconcat . intersperse ["\n"]
|
preparephase = mconcat . intersperse " " . mconcat . intersperse ["\n"]
|
||||||
in
|
in
|
||||||
"{ stdenv, fetchzip, " <>deps<> " }:\n"
|
"{ stdenv, fetchzip, " <>deps<> ", extraArgs ? { } }:\n"
|
||||||
<>"with {};\n" -- Awful hack to allow this to evaluate even if some of the variables are undefined
|
<>"with extraArgs;\n" -- Awful hack to allow this to evaluate even if some of the variables are undefined
|
||||||
<>"stdenv.mkDerivation rec {\n"
|
<>"stdenv.mkDerivation (rec {\n"
|
||||||
<>foldMap (\name' -> " pname = \""<>name'<>"\";\n") name
|
<>foldMap (\name' -> " pname = \""<>name'<>"\";\n") name
|
||||||
<>foldMap (\version' -> " version = \""<>version'<>"\";\n") version
|
<>foldMap (\version' -> " version = \""<>version'<>"\";\n") version
|
||||||
<>foldMap (\url -> " src = builtins.fetchTarball { url = \""<>url<>"\"; };\n") source
|
<>foldMap (\url -> " src = builtins.fetchTarball { url = \""<>url<>"\"; };\n") source
|
||||||
@ -58,8 +58,7 @@ opam2nix OPAM {..} =
|
|||||||
<>preparephase checkPhase'
|
<>preparephase checkPhase'
|
||||||
<>"\nrunHook postCheck\n'';\n") checkPhase
|
<>"\nrunHook postCheck\n'';\n") checkPhase
|
||||||
<>" installPhase = ''\nrunHook preInstall\nopaline -prefix $out -libdir $OCAMLFIND_DESTDIR\nrunHook postInstall\n'';\n"
|
<>" installPhase = ''\nrunHook preInstall\nopaline -prefix $out -libdir $OCAMLFIND_DESTDIR\nrunHook postInstall\n'';\n"
|
||||||
|
<>"} // extraArgs)\n"
|
||||||
<>"}\n"
|
|
||||||
|
|
||||||
update :: Maybe a -> a -> Maybe a
|
update :: Maybe a -> a -> Maybe a
|
||||||
update old new = if isNothing old then Just new else old
|
update old new = if isNothing old then Just new else old
|
||||||
@ -196,18 +195,7 @@ listParser valueParser =
|
|||||||
whiteSpace = optional $ many $ oneOf " \n"
|
whiteSpace = optional $ many $ oneOf " \n"
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = getContents >>= \s -> case parse opamFile "(unknown)" s of
|
||||||
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
|
|
||||||
Left e -> print e
|
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
|
-- Right fs -> mapM_ print fs
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
opam-version: "2.0"
|
opam-version: "2.0"
|
||||||
name: "memory-proto-alpha"
|
name: "tezos-memory-proto-alpha"
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
synopsis: "Tezos Protocol Alpha in memory"
|
synopsis: "Tezos Protocol Alpha in memory"
|
||||||
maintainer: "Galfour <ligolang@gmail.com>"
|
maintainer: "Galfour <ligolang@gmail.com>"
|
||||||
|
Loading…
Reference in New Issue
Block a user