6 , extraNativeBuildInputs ? []
7 , extraConfigureFlags ? []
12 # This *is* correct, though unusual. as a way of getting krb5-config from the
13 # package without splicing See: https://github.com/NixOS/nixpkgs/pull/107606
26 , withKerberos ? false
33 , withSecurityKey ? !stdenv.hostPlatform.isStatic
34 , withFIDO ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isMusl && withSecurityKey
35 , withPAM ? stdenv.hostPlatform.isLinux
36 , dsaKeysSupport ? false
38 , isNixos ? stdenv.hostPlatform.isLinux
41 # FIDO support requires SK support
42 assert withFIDO -> withSecurityKey;
44 stdenv.mkDerivation (finalAttrs: {
45 inherit pname version src;
48 ./locale_archive.patch
51 url = "https://git.alpinelinux.org/aports/plain/main/openssh/gss-serv.c.patch?id=a7509603971ce2f3282486a43bb773b1b522af83";
52 sha256 = "sha256-eFFOd4B2nccRZAQWwdBPBoKWjfEdKEVGJvKZAzLu3HU=";
54 # See discussion in https://github.com/NixOS/nixpkgs/pull/16966
55 ./dont_create_privsep_path.patch
59 # On Hydra this makes installation fail (sometimes?),
60 # and nix store doesn't allow such fancy permission bits anyway.
62 substituteInPlace Makefile.in --replace '$(INSTALL) -m 4711' '$(INSTALL) -m 0711'
66 nativeBuildInputs = [ autoreconfHook pkg-config ]
67 # This is not the same as the krb5 from the inputs! pkgs.krb5 is
68 # needed here to access krb5-config in order to cross compile. See:
69 # https://github.com/NixOS/nixpkgs/pull/107606
70 ++ lib.optional withKerberos pkgs.krb5
71 ++ extraNativeBuildInputs;
72 buildInputs = [ zlib libedit ]
73 ++ [ (if linkOpenssl then openssl else libxcrypt) ]
74 ++ lib.optional withFIDO libfido2
75 ++ lib.optional withKerberos krb5
76 ++ lib.optional withLdns ldns
77 ++ lib.optional withPAM pam;
80 # Setting LD causes `configure' and `make' to disagree about which linker
81 # to use: `configure' wants `gcc', but `make' wants `ld'.
85 env = lib.optionalAttrs isNixos {
86 # openssh calls passwd to allow the user to reset an expired password, but nixos
87 # doesn't ship it at /usr/bin/passwd.
88 PATH_PASSWD_PROG = "/run/wrappers/bin/passwd";
91 # I set --disable-strip because later we strip anyway. And it fails to strip
92 # properly when cross building.
94 "--sbindir=\${out}/bin"
95 "--localstatedir=/var"
100 (lib.withFeature withPAM "pam")
101 (lib.enableFeature dsaKeysSupport "dsa-keys")
102 ] ++ lib.optional (etcDir != null) "--sysconfdir=${etcDir}"
103 ++ lib.optional (!withSecurityKey) "--disable-security-key"
104 ++ lib.optional withFIDO "--with-security-key-builtin=yes"
105 ++ lib.optional withKerberos (assert krb5 != null; "--with-kerberos5=${lib.getDev krb5}")
106 ++ lib.optional stdenv.hostPlatform.isDarwin "--disable-libutil"
107 ++ lib.optional (!linkOpenssl) "--without-openssl"
108 ++ lib.optional withLdns "--with-ldns"
109 ++ extraConfigureFlags;
111 ${if stdenv.hostPlatform.isStatic then "NIX_LDFLAGS" else null} = [ "-laudit" ]
112 ++ lib.optional withKerberos "-lkeyutils"
113 ++ lib.optional withLdns "-lcrypto";
115 buildFlags = [ "SSH_KEYSIGN=ssh-keysign" ];
117 enableParallelBuilding = true;
119 hardeningEnable = [ "pie" ];
122 enableParallelChecking = false;
123 nativeCheckInputs = [ openssl ] ++ lib.optional (!stdenv.hostPlatform.isDarwin) hostname;
124 preCheck = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
125 # construct a dummy HOME
126 export HOME=$(realpath ../dummy-home)
129 # construct a dummy /etc/passwd file for the sshd under test
130 # to use to look up the connecting user
131 DUMMY_PASSWD=$(realpath ../dummy-passwd)
132 cat > $DUMMY_PASSWD <<EOF
133 $(whoami)::$(id -u):$(id -g)::$HOME:$SHELL
136 # we need to NIX_REDIRECTS /etc/passwd both for processes
137 # invoked directly and those invoked by the "remote" session
138 cat > ~/.ssh/environment.base <<EOF
139 NIX_REDIRECTS=/etc/passwd=$DUMMY_PASSWD
140 LD_PRELOAD=${libredirect}/lib/libredirect.so
143 # use an ssh environment file to ensure environment is set
144 # up appropriately for build environment even when no shell
145 # is invoked by the ssh session. otherwise the PATH will
146 # only contain default unix paths like /bin which we don't
147 # have in our build environment
148 cat - regress/test-exec.sh > regress/test-exec.sh.new <<EOF
149 cp $HOME/.ssh/environment.base $HOME/.ssh/environment
150 echo "PATH=\$PATH" >> $HOME/.ssh/environment
152 mv regress/test-exec.sh.new regress/test-exec.sh
154 # explicitly enable the PermitUserEnvironment feature
155 substituteInPlace regress/test-exec.sh \
157 'cat << EOF > $OBJ/sshd_config' \
158 $'cat << EOF > $OBJ/sshd_config\n\tPermitUserEnvironment yes'
160 # some tests want to use files under /bin as example files
161 for f in regress/sftp-cmds.sh regress/forwarding.sh; do
162 substituteInPlace $f --replace '/bin' "$(dirname $(type -p ls))"
165 # set up NIX_REDIRECTS for direct invocations
166 set -a; source ~/.ssh/environment.base; set +a
168 # integration tests hard to get working on darwin with its shaky
170 # t-exec tests fail on musl
171 checkTarget = lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isMusl) "t-exec"
172 # other tests are less demanding of the environment
173 ++ [ "unit" "file-tests" "interop-tests" ];
176 # Install ssh-copy-id, it's very useful.
177 cp contrib/ssh-copy-id $out/bin/
178 chmod +x $out/bin/ssh-copy-id
179 cp contrib/ssh-copy-id.1 $out/share/man/man1/
182 installTargets = [ "install-nokeys" ];
184 "sysconfdir=\${out}/etc/ssh"
188 inherit withKerberos;
190 borgbackup-integration = nixosTests.borgbackup;
191 nixosTest = nixosTests.openssh;
192 openssh = finalAttrs.finalPackage.overrideAttrs (previousAttrs: {
193 pname = previousAttrs.pname + "-test";
200 description = "Implementation of the SSH protocol${extraDesc}";
201 homepage = "https://www.openssh.com/";
202 changelog = "https://www.openssh.com/releasenotes.html";
203 license = licenses.bsd2;
204 platforms = platforms.unix ++ platforms.windows;
205 maintainers = (extraMeta.maintainers or []) ++ (with maintainers; [ aneeshusa ]);