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
29 , withFIDO ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isMusl
34 stdenv.mkDerivation rec {
35 inherit pname version src;
38 ./locale_archive.patch
41 url = "https://git.alpinelinux.org/aports/plain/main/openssh/gss-serv.c.patch?id=a7509603971ce2f3282486a43bb773b1b522af83";
42 sha256 = "sha256-eFFOd4B2nccRZAQWwdBPBoKWjfEdKEVGJvKZAzLu3HU=";
45 # See discussion in https://github.com/NixOS/nixpkgs/pull/16966
46 ./dont_create_privsep_path.patch
50 # On Hydra this makes installation fail (sometimes?),
51 # and nix store doesn't allow such fancy permission bits anyway.
53 substituteInPlace Makefile.in --replace '$(INSTALL) -m 4711' '$(INSTALL) -m 0711'
56 nativeBuildInputs = [ pkg-config ]
57 # This is not the same as the libkrb5 from the inputs! pkgs.libkrb5 is
58 # needed here to access krb5-config in order to cross compile. See:
59 # https://github.com/NixOS/nixpkgs/pull/107606
60 ++ optional withKerberos pkgs.libkrb5
61 ++ extraNativeBuildInputs;
62 buildInputs = [ zlib openssl libedit ]
63 ++ optional withFIDO libfido2
64 ++ optional withKerberos libkrb5
65 ++ optional stdenv.isLinux pam;
68 # Setting LD causes `configure' and `make' to disagree about which linker
69 # to use: `configure' wants `gcc', but `make' wants `ld'.
73 # I set --disable-strip because later we strip anyway. And it fails to strip
74 # properly when cross building.
76 "--sbindir=\${out}/bin"
77 "--localstatedir=/var"
82 (if stdenv.isLinux then "--with-pam" else "--without-pam")
83 ] ++ optional (etcDir != null) "--sysconfdir=${etcDir}"
84 ++ optional withFIDO "--with-security-key-builtin=yes"
85 ++ optional withKerberos (assert libkrb5 != null; "--with-kerberos5=${libkrb5}")
86 ++ optional stdenv.isDarwin "--disable-libutil"
87 ++ optional (!linkOpenssl) "--without-openssl"
88 ++ extraConfigureFlags;
90 ${if stdenv.hostPlatform.isStatic then "NIX_LDFLAGS" else null}= [ "-laudit" ] ++ lib.optionals withKerberos [ "-lkeyutils" ];
92 buildFlags = [ "SSH_KEYSIGN=ssh-keysign" ];
94 enableParallelBuilding = true;
96 hardeningEnable = [ "pie" ];
99 enableParallelChecking = false;
100 checkInputs = optional (!stdenv.isDarwin) hostname;
101 preCheck = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
102 # construct a dummy HOME
103 export HOME=$(realpath ../dummy-home)
106 # construct a dummy /etc/passwd file for the sshd under test
107 # to use to look up the connecting user
108 DUMMY_PASSWD=$(realpath ../dummy-passwd)
109 cat > $DUMMY_PASSWD <<EOF
110 $(whoami)::$(id -u):$(id -g)::$HOME:$SHELL
113 # we need to NIX_REDIRECTS /etc/passwd both for processes
114 # invoked directly and those invoked by the "remote" session
115 cat > ~/.ssh/environment.base <<EOF
116 NIX_REDIRECTS=/etc/passwd=$DUMMY_PASSWD
117 LD_PRELOAD=${libredirect}/lib/libredirect.so
120 # use an ssh environment file to ensure environment is set
121 # up appropriately for build environment even when no shell
122 # is invoked by the ssh session. otherwise the PATH will
123 # only contain default unix paths like /bin which we don't
124 # have in our build environment
125 cat - regress/test-exec.sh > regress/test-exec.sh.new <<EOF
126 cp $HOME/.ssh/environment.base $HOME/.ssh/environment
127 echo "PATH=\$PATH" >> $HOME/.ssh/environment
129 mv regress/test-exec.sh.new regress/test-exec.sh
131 # explicitly enable the PermitUserEnvironment feature
132 substituteInPlace regress/test-exec.sh \
134 'cat << EOF > $OBJ/sshd_config' \
135 $'cat << EOF > $OBJ/sshd_config\n\tPermitUserEnvironment yes'
137 # some tests want to use files under /bin as example files
138 for f in regress/sftp-cmds.sh regress/forwarding.sh; do
139 substituteInPlace $f --replace '/bin' "$(dirname $(type -p ls))"
142 # set up NIX_REDIRECTS for direct invocations
143 set -a; source ~/.ssh/environment.base; set +a
145 # integration tests hard to get working on darwin with its shaky
147 # t-exec tests fail on musl
148 checkTarget = optional (!stdenv.isDarwin && !stdenv.hostPlatform.isMusl) "t-exec"
149 # other tests are less demanding of the environment
150 ++ [ "unit" "file-tests" "interop-tests" ];
153 # Install ssh-copy-id, it's very useful.
154 cp contrib/ssh-copy-id $out/bin/
155 chmod +x $out/bin/ssh-copy-id
156 cp contrib/ssh-copy-id.1 $out/share/man/man1/
159 installTargets = [ "install-nokeys" ];
161 "sysconfdir=\${out}/etc/ssh"
165 borgbackup-integration = nixosTests.borgbackup;
169 description = "An implementation of the SSH protocol${extraDesc}";
170 homepage = "https://www.openssh.com/";
171 changelog = "https://www.openssh.com/releasenotes.html";
172 license = licenses.bsd2;
173 platforms = platforms.unix ++ platforms.windows;
174 maintainers = (extraMeta.maintainers or []) ++ (with maintainers; [ eelco aneeshusa ]);