From cb49b9265913deda398cde5c439517360ba93d93 Mon Sep 17 00:00:00 2001 From: zseri Date: Sat, 28 Aug 2021 06:04:54 +0200 Subject: [PATCH] dropbear: expose optional scp support (fixes #135849) --- pkgs/tools/networking/dropbear/default.nix | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pkgs/tools/networking/dropbear/default.nix b/pkgs/tools/networking/dropbear/default.nix index 1fd686735b7e..30efbcc508d0 100644 --- a/pkgs/tools/networking/dropbear/default.nix +++ b/pkgs/tools/networking/dropbear/default.nix @@ -1,8 +1,19 @@ -{ stdenv, lib, fetchurl, glibc, zlib +{ lib, stdenv, fetchurl, glibc, zlib , enableStatic ? stdenv.hostPlatform.isStatic +, enableSCP ? false , sftpPath ? "/run/current-system/sw/libexec/sftp-server" }: +let + # NOTE: DROPBEAR_PATH_SSH_PROGRAM is only necessary when enableSCP is true, + # but it is enabled here always anyways for consistency + dflags = { + SFTPSERVER_PATH = sftpPath; + DROPBEAR_PATH_SSH_PROGRAM = "${placeholder "out"}/bin/dbclient"; + }; + +in + stdenv.mkDerivation rec { pname = "dropbear"; version = "2020.81"; @@ -13,14 +24,23 @@ stdenv.mkDerivation rec { }; dontDisableStatic = enableStatic; - configureFlags = lib.optional enableStatic "LDFLAGS=-static"; - CFLAGS = "-DSFTPSERVER_PATH=\\\"${sftpPath}\\\""; + CFLAGS = lib.pipe (lib.attrNames dflags) [ + (builtins.map (name: "-D${name}=\\\"${dflags.${name}}\\\"")) + (lib.concatStringsSep " ") + ]; # https://www.gnu.org/software/make/manual/html_node/Libraries_002fSearch.html preConfigure = '' - makeFlags=VPATH=`cat $NIX_CC/nix-support/orig-libc`/lib + makeFlagsArray=( + VPATH=$(cat $NIX_CC/nix-support/orig-libc)/lib + PROGRAMS="${lib.concatStringsSep " " ([ "dropbear" "dbclient" "dropbearkey" "dropbearconvert" ] ++ lib.optionals enableSCP ["scp"])}" + ) + ''; + + postInstall = lib.optionalString enableSCP '' + ln -rs $out/bin/scp $out/bin/dbscp ''; patches = [