forked from mirrors/nixpkgs
a79a294901
this should hopefully make the tests more reliable
184 lines
6 KiB
Nix
184 lines
6 KiB
Nix
{ pname
|
|
, version
|
|
, extraDesc ? ""
|
|
, src
|
|
, extraPatches ? []
|
|
, extraNativeBuildInputs ? []
|
|
, extraMeta ? {}
|
|
}:
|
|
|
|
{ lib, stdenv
|
|
# This *is* correct, though unusual. as a way of getting krb5-config from the
|
|
# package without splicing See: https://github.com/NixOS/nixpkgs/pull/107606
|
|
, pkgs
|
|
, fetchurl
|
|
, fetchpatch
|
|
, zlib
|
|
, openssl
|
|
, libedit
|
|
, pkg-config
|
|
, pam
|
|
, libredirect
|
|
, etcDir ? null
|
|
, withKerberos ? !(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)
|
|
, libkrb5
|
|
, libfido2
|
|
, hostname
|
|
, nixosTests
|
|
, withFIDO ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isMusl
|
|
, linkOpenssl ? true
|
|
}:
|
|
|
|
with lib;
|
|
stdenv.mkDerivation rec {
|
|
inherit pname version src;
|
|
|
|
patches = [
|
|
./locale_archive.patch
|
|
|
|
# See discussion in https://github.com/NixOS/nixpkgs/pull/16966
|
|
./dont_create_privsep_path.patch
|
|
] ++ extraPatches;
|
|
|
|
postPatch =
|
|
# On Hydra this makes installation fail (sometimes?),
|
|
# and nix store doesn't allow such fancy permission bits anyway.
|
|
''
|
|
substituteInPlace Makefile.in --replace '$(INSTALL) -m 4711' '$(INSTALL) -m 0711'
|
|
'';
|
|
|
|
nativeBuildInputs = [ pkg-config ]
|
|
# This is not the same as the libkrb5 from the inputs! pkgs.libkrb5 is
|
|
# needed here to access krb5-config in order to cross compile. See:
|
|
# https://github.com/NixOS/nixpkgs/pull/107606
|
|
++ optional withKerberos pkgs.libkrb5
|
|
++ extraNativeBuildInputs;
|
|
buildInputs = [ zlib openssl libedit ]
|
|
++ optional withFIDO libfido2
|
|
++ optional withKerberos libkrb5
|
|
++ optional stdenv.isLinux pam;
|
|
|
|
preConfigure = ''
|
|
# Setting LD causes `configure' and `make' to disagree about which linker
|
|
# to use: `configure' wants `gcc', but `make' wants `ld'.
|
|
unset LD
|
|
''
|
|
# Upstream build system does not support static build, so we fall back
|
|
# on fragile patching of configure script.
|
|
#
|
|
# libedit is found by pkg-config, but without --static flag, required
|
|
# to get also transitive dependencies for static linkage, hence sed
|
|
# expression.
|
|
#
|
|
# Kerberos can be found either by krb5-config or by fall-back shell
|
|
# code in openssh's configure.ac. Neither of them support static
|
|
# build, but patching code for krb5-config is simpler, so to get it
|
|
# into PATH, libkrb5.dev is added into buildInputs.
|
|
+ optionalString stdenv.hostPlatform.isStatic ''
|
|
sed -i "s,PKGCONFIG --libs,PKGCONFIG --libs --static,g" configure
|
|
sed -i 's#KRB5CONF --libs`#KRB5CONF --libs` -lkrb5support -lkeyutils#g' configure
|
|
sed -i 's#KRB5CONF --libs gssapi`#KRB5CONF --libs gssapi` -lkrb5support -lkeyutils#g' configure
|
|
'';
|
|
|
|
# I set --disable-strip because later we strip anyway. And it fails to strip
|
|
# properly when cross building.
|
|
configureFlags = [
|
|
"--sbindir=\${out}/bin"
|
|
"--localstatedir=/var"
|
|
"--with-pid-dir=/run"
|
|
"--with-mantype=man"
|
|
"--with-libedit=yes"
|
|
"--disable-strip"
|
|
(if stdenv.isLinux then "--with-pam" else "--without-pam")
|
|
] ++ optional (etcDir != null) "--sysconfdir=${etcDir}"
|
|
++ optional withFIDO "--with-security-key-builtin=yes"
|
|
++ optional withKerberos (assert libkrb5 != null; "--with-kerberos5=${libkrb5}")
|
|
++ optional stdenv.isDarwin "--disable-libutil"
|
|
++ optional (!linkOpenssl) "--without-openssl";
|
|
|
|
buildFlags = [ "SSH_KEYSIGN=ssh-keysign" ];
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
hardeningEnable = [ "pie" ];
|
|
|
|
doCheck = true;
|
|
enableParallelChecking = false;
|
|
checkInputs = optional (!stdenv.isDarwin) hostname;
|
|
preCheck = ''
|
|
# construct a dummy HOME
|
|
export HOME=$(realpath ../dummy-home)
|
|
mkdir -p ~/.ssh
|
|
|
|
# construct a dummy /etc/passwd file for the sshd under test
|
|
# to use to look up the connecting user
|
|
DUMMY_PASSWD=$(realpath ../dummy-passwd)
|
|
cat > $DUMMY_PASSWD <<EOF
|
|
$(whoami)::$(id -u):$(id -g)::$HOME:$SHELL
|
|
EOF
|
|
|
|
# we need to NIX_REDIRECTS /etc/passwd both for processes
|
|
# invoked directly and those invoked by the "remote" session
|
|
cat > ~/.ssh/environment.base <<EOF
|
|
NIX_REDIRECTS=/etc/passwd=$DUMMY_PASSWD
|
|
LD_PRELOAD=${libredirect}/lib/libredirect.so
|
|
EOF
|
|
|
|
# use an ssh environment file to ensure environment is set
|
|
# up appropriately for build environment even when no shell
|
|
# is invoked by the ssh session. otherwise the PATH will
|
|
# only contain default unix paths like /bin which we don't
|
|
# have in our build environment
|
|
cat - regress/test-exec.sh > regress/test-exec.sh.new <<EOF
|
|
cp $HOME/.ssh/environment.base $HOME/.ssh/environment
|
|
echo "PATH=\$PATH" >> $HOME/.ssh/environment
|
|
EOF
|
|
mv regress/test-exec.sh.new regress/test-exec.sh
|
|
|
|
# explicitly enable the PermitUserEnvironment feature
|
|
substituteInPlace regress/test-exec.sh \
|
|
--replace \
|
|
'cat << EOF > $OBJ/sshd_config' \
|
|
$'cat << EOF > $OBJ/sshd_config\n\tPermitUserEnvironment yes'
|
|
|
|
# some tests want to use files under /bin as example files
|
|
for f in regress/sftp-cmds.sh regress/forwarding.sh; do
|
|
substituteInPlace $f --replace '/bin' "$(dirname $(type -p ls))"
|
|
done
|
|
|
|
# set up NIX_REDIRECTS for direct invocations
|
|
set -a; source ~/.ssh/environment.base; set +a
|
|
'';
|
|
# integration tests hard to get working on darwin with its shaky
|
|
# sandbox
|
|
checkTarget = optional (!stdenv.isDarwin) "t-exec"
|
|
# other tests are less demanding of the environment
|
|
++ [ "unit" "file-tests" "interop-tests" ];
|
|
|
|
postInstall = ''
|
|
# Install ssh-copy-id, it's very useful.
|
|
cp contrib/ssh-copy-id $out/bin/
|
|
chmod +x $out/bin/ssh-copy-id
|
|
cp contrib/ssh-copy-id.1 $out/share/man/man1/
|
|
'';
|
|
|
|
installTargets = [ "install-nokeys" ];
|
|
installFlags = [
|
|
"sysconfdir=\${out}/etc/ssh"
|
|
];
|
|
|
|
passthru.tests = {
|
|
borgbackup-integration = nixosTests.borgbackup;
|
|
};
|
|
|
|
meta = {
|
|
description = "An implementation of the SSH protocol${extraDesc}";
|
|
homepage = "https://www.openssh.com/";
|
|
changelog = "https://www.openssh.com/releasenotes.html";
|
|
license = licenses.bsd2;
|
|
platforms = platforms.unix ++ platforms.windows;
|
|
maintainers = (extraMeta.maintainers or []) ++ (with maintainers; [ eelco aneeshusa ]);
|
|
mainProgram = "ssh";
|
|
} // extraMeta;
|
|
}
|