From 2692cfbfc141395483ba851ccec3227761ecba6a Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 31 Jul 2019 15:53:30 +0200 Subject: [PATCH] Avoid IFD as much as possible --- build.nix | 24 ++++++++++++++---------- builtins/default.nix | 6 +++--- default.nix | 24 ++++++++++-------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/build.nix b/build.nix index 323bf3d..949687b 100644 --- a/build.nix +++ b/build.nix @@ -17,8 +17,8 @@ src: , buildInputs ? [] , nativeBuildInputs ? [] , builtDependencies ? [] -, cargolockPath ? null -, cargotomlPath ? null +, cargolock ? null +, cargotoml ? null , release ? true , stdenv , lib @@ -43,13 +43,11 @@ with with rec { - drv = stdenv.mkDerivation + drv = stdenv.mkDerivation ( { inherit src doCheck nativeBuildInputs - cargolockPath - cargotomlPath cratePaths name version; @@ -88,24 +86,24 @@ with rec '' runHook preConfigure - if [ -n "$cargolockPath" ] + if [ -n "$cargolock" ] then echo "Setting Cargo.lock" if [ -f "Cargo.lock" ] then echo "WARNING: replacing existing Cargo.lock" fi - cp --no-preserve mode "$cargolockPath" Cargo.lock + echo "$cargolock" > Cargo.lock fi - if [ -n "$cargotomlPath" ] + if [ -n "$cargotoml" ] then echo "Setting Cargo.toml" if [ -f "Cargo.toml" ] then echo "WARNING: replacing existing Cargo.toml" fi - cp "$cargotomlPath" Cargo.toml + echo "$cargotoml" > Cargo.toml fi mkdir -p target @@ -209,7 +207,13 @@ with rec runHook postInstall ''; - }; + } // + lib.optionalAttrs (! isNull cargolock ) + { cargolock = builtinz.toTOML cargolock; } // + lib.optionalAttrs (! isNull cargotoml ) + { cargotoml = builtinz.toTOML cargotoml; } + ) + ; # XXX: the actual crate format is not documented but in practice is a # gzipped tar; we simply unpack it and introduce a ".cargo-checksum.json" diff --git a/builtins/default.nix b/builtins/default.nix index f7c61f1..11213b9 100644 --- a/builtins/default.nix +++ b/builtins/default.nix @@ -5,10 +5,10 @@ , remarshal }: +rec { - writeTOML = attrs: - let toTOML = import ./to-toml.nix { inherit lib; }; in - writeText "write-toml" (toTOML attrs); + toTOML = import ./to-toml.nix { inherit lib; }; + writeTOML = attrs: writeText "write-toml" (toTOML attrs); readTOML = usePure: f: if usePure then diff --git a/default.nix b/default.nix index 8e6209c..979bbf2 100644 --- a/default.nix +++ b/default.nix @@ -45,18 +45,16 @@ with rec { commonAttrs = src: attrs: rec { usePureFromTOML = attrs.usePureFromTOML or true; - cargolockPath = attrs.cargolockPath or null; - cargotomlPath = attrs.cargotomlPath or null; - cargolock = - if isNull cargolockPath then + cargolock = attrs.cargolock or null; + cargotoml = attrs.cargotoml or null; + cargolock' = + if isNull cargolock then builtinz.readTOML usePureFromTOML "${src}/Cargo.lock" - else - builtinz.readTOML usePureFromTOML cargolockPath; + else cargolock; rootCargotoml = - if isNull cargotomlPath then + if isNull cargotoml then builtinz.readTOML usePureFromTOML "${src}/Cargo.toml" - else - builtinz.readTOML usePureFromTOML cargotomlPath; + else cargotoml; # All the Cargo.tomls, including the top-level one cargotomls = @@ -81,7 +79,7 @@ with rec if isNull workspaceMembers then "." else lib.concatStringsSep "\n" workspaceMembers; - crateDependencies = libb.mkVersions cargolock; + crateDependencies = libb.mkVersions cargolock'; targetInstructions = if builtins.hasAttr "targets" attrs then lib.concatMapStringsSep " " (target: "-p ${target}") attrs.targets @@ -164,12 +162,10 @@ with rec { cargoBuild = "source ${buildDepsScript}"; doCheck = false; copyBuildArtifacts = true; - cargolockPath = builtinz.writeTOML cargolock; - cargotomlPath = builtinz.writeTOML - ( + cargolock = cargolock'; + cargotoml = { package = { name = "dummy"; version = "0.0.0"; }; } // { dependencies = directDependencies; } - ) ; name = if lib.length cargotomls == 0 then