nixpkgs/pkgs/servers/teleport/generic.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

201 lines
5.2 KiB
Nix
Raw Normal View History

2021-11-08 21:43:52 +00:00
{ lib
, buildGoModule
2021-11-08 21:43:52 +00:00
, rustPlatform
, fetchFromGitHub
2023-02-03 22:42:58 +00:00
, fetchYarnDeps
2021-11-08 21:43:52 +00:00
, makeWrapper
2022-04-25 16:30:13 +00:00
, CoreFoundation
2022-10-11 08:55:39 +00:00
, AppKit
2024-02-03 00:14:12 +00:00
, binaryen
, cargo
, libfido2
2023-02-03 22:42:58 +00:00
, nodejs
2022-04-25 16:30:13 +00:00
, openssl
, pkg-config
2024-08-08 11:15:04 +00:00
, pnpm_9
2024-02-03 00:14:12 +00:00
, rustc
2022-04-25 16:30:13 +00:00
, Security
2021-11-08 21:43:52 +00:00
, stdenv
, xdg-utils
2023-02-03 22:42:58 +00:00
, yarn
2024-02-03 00:14:12 +00:00
, wasm-bindgen-cli
, wasm-pack
, fixup-yarn-lock
2022-01-08 08:29:19 +00:00
, nixosTests
2018-01-14 08:04:08 +00:00
2022-04-25 16:30:13 +00:00
, withRdpClient ? true
2023-02-23 18:14:50 +00:00
, version
, hash
, vendorHash
2024-07-04 17:28:15 +00:00
, extPatches ? []
2023-04-02 16:05:44 +00:00
, cargoHash ? null
, cargoLock ? null
2024-08-08 11:15:04 +00:00
, yarnHash ? null
, pnpmHash ? null
2021-11-08 21:43:52 +00:00
}:
2024-08-08 11:15:04 +00:00
assert yarnHash != null || pnpmHash != null;
2021-11-08 21:43:52 +00:00
let
# This repo has a private submodule "e" which fetchgit cannot handle without failing.
src = fetchFromGitHub {
owner = "gravitational";
repo = "teleport";
rev = "v${version}";
2023-02-23 18:14:50 +00:00
inherit hash;
2021-11-08 21:43:52 +00:00
};
2024-08-08 11:15:04 +00:00
pname = "teleport";
2023-02-23 18:14:50 +00:00
inherit version;
2021-11-08 21:43:52 +00:00
2022-04-25 16:30:13 +00:00
rdpClient = rustPlatform.buildRustPackage rec {
pname = "teleport-rdpclient";
2023-04-02 16:05:44 +00:00
inherit cargoHash cargoLock;
2022-04-25 16:30:13 +00:00
inherit version src;
buildAndTestSubdir = "lib/srv/desktop/rdp/rdpclient";
buildInputs = [ openssl ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ CoreFoundation Security ];
nativeBuildInputs = [ pkg-config ];
# https://github.com/NixOS/nixpkgs/issues/161570 ,
# buildRustPackage sets strictDeps = true;
nativeCheckInputs = buildInputs;
2022-04-25 16:30:13 +00:00
OPENSSL_NO_VENDOR = "1";
postInstall = ''
mkdir -p $out/include
cp ${buildAndTestSubdir}/librdprs.h $out/include/
2021-11-08 21:43:52 +00:00
'';
};
2023-02-03 22:42:58 +00:00
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
2023-02-23 18:14:50 +00:00
hash = yarnHash;
2023-02-03 22:42:58 +00:00
};
webassets = stdenv.mkDerivation {
pname = "teleport-webassets";
inherit src version;
2024-02-03 00:14:12 +00:00
cargoDeps = rustPlatform.importCargoLock cargoLock;
2024-08-08 11:15:04 +00:00
pnpmDeps = if pnpmHash != null then pnpm_9.fetchDeps {
inherit src pname version;
hash = pnpmHash;
} else null;
nativeBuildInputs = [ nodejs ] ++ lib.optional (lib.versionAtLeast version "15") [
binaryen
cargo
nodejs
rustc
rustc.llvmPackages.lld
rustPlatform.cargoSetupHook
wasm-bindgen-cli
wasm-pack
] ++ (if lib.versionAtLeast version "16" then [ pnpm_9.configHook ] else [ yarn fixup-yarn-lock ]);
2024-02-03 00:14:12 +00:00
2023-02-03 22:42:58 +00:00
configurePhase = ''
2024-08-08 11:15:04 +00:00
runHook preConfigure
2023-02-03 22:42:58 +00:00
export HOME=$(mktemp -d)
2024-08-08 11:15:04 +00:00
runHook postConfigure
2023-02-03 22:42:58 +00:00
'';
buildPhase = ''
2024-08-08 11:15:04 +00:00
${lib.optionalString (lib.versionOlder version "16") ''
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
fixup-yarn-lock yarn.lock
yarn install --offline \
--frozen-lockfile \
--ignore-engines --ignore-scripts
patchShebangs .
''}
2023-02-03 22:42:58 +00:00
2024-08-08 11:15:04 +00:00
PATH=$PATH:$PWD/node_modules/.bin
2023-02-03 22:42:58 +00:00
2024-02-03 00:14:12 +00:00
${if lib.versionAtLeast version "15"
then ''
pushd web/packages/teleport
# https://github.com/gravitational/teleport/blob/6b91fe5bbb9e87db4c63d19f94ed4f7d0f9eba43/web/packages/teleport/README.md?plain=1#L18-L20
RUST_MIN_STACK=16777216 wasm-pack build ./src/ironrdp --target web --mode no-install
vite build
popd
''
else "yarn build-ui-oss"}
2023-02-03 22:42:58 +00:00
'';
installPhase = ''
mkdir -p $out
cp -R webassets/. $out
'';
2021-11-08 21:43:52 +00:00
};
in
buildGoModule rec {
2024-08-08 11:15:04 +00:00
inherit pname src version;
2023-02-23 18:14:50 +00:00
inherit vendorHash;
2023-02-03 22:42:58 +00:00
proxyVendor = true;
2020-03-18 10:43:09 +00:00
2022-04-25 16:06:27 +00:00
subPackages = [ "tool/tbot" "tool/tctl" "tool/teleport" "tool/tsh" ];
tags = [ "libfido2" "webassets_embed" ]
++ lib.optional withRdpClient "desktop_access_rdp";
2020-03-18 10:43:09 +00:00
buildInputs = [ openssl libfido2 ]
2022-10-11 08:55:39 +00:00
++ lib.optionals (stdenv.hostPlatform.isDarwin && withRdpClient) [ CoreFoundation Security AppKit ];
nativeBuildInputs = [ makeWrapper pkg-config ];
2020-03-18 10:43:09 +00:00
2023-10-04 06:21:48 +00:00
patches = extPatches ++ [
./0001-fix-add-nix-path-to-exec-env.patch
2022-04-25 16:30:13 +00:00
./rdpclient.patch
2024-10-25 15:47:44 +00:00
./tsh.patch
];
2021-08-11 12:58:40 +00:00
# Reduce closure size for client machines
outputs = [ "out" "client" ];
preBuild = ''
2023-02-03 22:42:58 +00:00
cp -r ${webassets} webassets
'' + lib.optionalString withRdpClient ''
ln -s ${rdpClient}/lib/* lib/
ln -s ${rdpClient}/include/* lib/srv/desktop/rdp/rdpclient/
'';
2018-01-14 08:04:08 +00:00
2022-04-25 16:06:27 +00:00
# Multiple tests fail in the build sandbox
# due to trying to spawn nixbld's shell (/noshell), etc.
doCheck = false;
2021-04-22 15:32:55 +00:00
postInstall = ''
mkdir -p $client/bin
mv {$out,$client}/bin/tsh
# make xdg-open overrideable at runtime
wrapProgram $client/bin/tsh --suffix PATH : ${lib.makeBinPath [ xdg-utils ]}
ln -s {$client,$out}/bin/tsh
'';
2018-01-14 08:04:08 +00:00
2021-02-01 14:45:17 +00:00
doInstallCheck = true;
installCheckPhase = ''
$out/bin/tsh version | grep ${version} > /dev/null
$client/bin/tsh version | grep ${version} > /dev/null
2022-04-25 16:06:27 +00:00
$out/bin/tbot version | grep ${version} > /dev/null
2021-02-01 14:45:17 +00:00
$out/bin/tctl version | grep ${version} > /dev/null
$out/bin/teleport version | grep ${version} > /dev/null
'';
2022-01-08 08:29:19 +00:00
passthru.tests = nixosTests.teleport;
meta = with lib; {
2021-11-08 21:43:52 +00:00
description = "Certificate authority and access plane for SSH, Kubernetes, web applications, and databases";
2021-04-22 15:32:55 +00:00
homepage = "https://goteleport.com/";
2024-02-03 00:14:12 +00:00
license = if lib.versionAtLeast version "15" then licenses.agpl3Plus else licenses.asl20;
maintainers = with maintainers; [ arianvp justinas sigma tomberek freezeboy techknowlogick ];
platforms = platforms.unix;
# go-libfido2 is broken on platforms with less than 64-bit because it defines an array
# which occupies more than 31 bits of address space.
2024-08-01 17:02:44 +00:00
broken = stdenv.hostPlatform.parsed.cpu.bits < 64;
2018-01-14 08:04:08 +00:00
};
}