summary refs log tree commit diff
path: root/pkgs/build-support/writers/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/writers/default.nix')
-rw-r--r--pkgs/build-support/writers/default.nix59
1 files changed, 37 insertions, 22 deletions
diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix
index 4673b4e6cd8..47919c251af 100644
--- a/pkgs/build-support/writers/default.nix
+++ b/pkgs/build-support/writers/default.nix
@@ -1,4 +1,4 @@
-{ pkgs, lib }:
+{ pkgs, lib, gawk, gnused, gixy }:
 
 with lib;
 rec {
@@ -63,7 +63,7 @@ rec {
   #
   # Examples:
   #   writeSimpleC = makeBinWriter { compileScript = name: "gcc -o $out $contentPath"; }
-  makeBinWriter = { compileScript }: nameOrPath: content:
+  makeBinWriter = { compileScript, strip ? true }: nameOrPath: content:
     assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null);
     assert lib.or (types.path.check content) (types.str.check content);
     let
@@ -76,6 +76,8 @@ rec {
       contentPath = content;
     }) ''
       ${compileScript}
+      ${lib.optionalString strip
+         "${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded $out"}
       ${optionalString (types.path.check nameOrPath) ''
         mv $out tmp
         mkdir -p $out/$(dirname "${nameOrPath}")
@@ -109,7 +111,10 @@ rec {
   #        return 0;
   #      }
   #    ''
-  writeC = name: { libraries ? [] }:
+  writeC = name: {
+    libraries ? [],
+    strip ? true
+  }:
     makeBinWriter {
       compileScript = ''
         PATH=${makeBinPath [
@@ -117,7 +122,7 @@ rec {
           pkgs.coreutils
           pkgs.findutils
           pkgs.gcc
-          pkgs.pkgconfig
+          pkgs.pkg-config
         ]}
         export PKG_CONFIG_PATH=${concatMapStringsSep ":" (pkg: "${pkg}/lib/pkgconfig") libraries}
         gcc \
@@ -131,8 +136,8 @@ rec {
             -Wall \
             -x c \
             "$contentPath"
-        strip --strip-unneeded "$out"
       '';
+      inherit strip;
     } name;
 
   # writeCBin takes the same arguments as writeC but outputs a directory (like writeScriptBin)
@@ -164,21 +169,39 @@ rec {
   #   '';
   writeHaskell = name: {
     libraries ? [],
-    ghc ? pkgs.ghc
+    ghc ? pkgs.ghc,
+    ghcArgs ? [],
+    strip ? true
   }:
     makeBinWriter {
       compileScript = ''
         cp $contentPath tmp.hs
-        ${ghc.withPackages (_: libraries )}/bin/ghc tmp.hs
+        ${ghc.withPackages (_: libraries )}/bin/ghc ${lib.escapeShellArgs ghcArgs} tmp.hs
         mv tmp $out
-        ${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded "$out"
       '';
+      inherit strip;
     } name;
 
   # writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin)
   writeHaskellBin = name:
     writeHaskell "/bin/${name}";
 
+  writeRust = name: {
+      rustc ? pkgs.rustc,
+      rustcArgs ? [],
+      strip ? true
+  }:
+    makeBinWriter {
+      compileScript = ''
+        cp "$contentPath" tmp.rs
+        PATH=${makeBinPath [pkgs.gcc]} ${lib.getBin rustc}/bin/rustc ${lib.escapeShellArgs rustcArgs} -o "$out" tmp.rs
+      '';
+      inherit strip;
+    } name;
+
+  writeRustBin = name:
+    writeRust "/bin/${name}";
+
   # writeJS takes a name an attributeset with libraries and some JavaScript sourcecode and
   # returns an executable
   #
@@ -218,10 +241,11 @@ rec {
   writeNginxConfig = name: text: pkgs.runCommandLocal name {
     inherit text;
     passAsFile = [ "text" ];
+    nativeBuildInputs = [ gawk gnused gixy ];
   } /* sh */ ''
     # nginx-config-formatter has an error - https://github.com/1connect/nginx-config-formatter/issues/16
-    ${pkgs.gawk}/bin/awk -f ${awkFormatNginx} "$textPath" | ${pkgs.gnused}/bin/sed '/^\s*$/d' > $out
-    ${pkgs.gixy}/bin/gixy $out
+    awk -f ${awkFormatNginx} "$textPath" | sed '/^\s*$/d' > $out
+    gixy $out
   '';
 
   # writePerl takes a name an attributeset with libraries and some perl sourcecode and
@@ -233,18 +257,9 @@ rec {
   #     print "Howdy!\n" if true;
   #   ''
   writePerl = name: { libraries ? [] }:
-  let
-    perl-env = pkgs.buildEnv {
-      name = "perl-environment";
-      paths = libraries;
-      pathsToLink = [
-        "/${pkgs.perl.libPrefix}"
-      ];
-    };
-  in
-  makeScriptWriter {
-    interpreter = "${pkgs.perl}/bin/perl -I ${perl-env}/${pkgs.perl.libPrefix}";
-  } name;
+    makeScriptWriter {
+      interpreter = "${pkgs.perl.withPackages (p: libraries)}/bin/perl";
+    } name;
 
   # writePerlBin takes the same arguments as writePerl but outputs a directory (like writeScriptBin)
   writePerlBin = name: