Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/fetch-engine/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { BinaryType } from './BinaryType'
import { chmodPlusX } from './chmodPlusX'
import { cleanupCache } from './cleanupCache'
import { downloadZip } from './downloadZip'
import { allEngineEnvVarsSet, getBinaryEnvVarPath } from './env'
import { getBinaryEnvVarPath } from './env'
import { getHash } from './getHash'
import { getBar } from './log'
import { getCacheDir, getDownloadUrl, overwriteFile } from './utils'
Expand Down Expand Up @@ -73,17 +73,9 @@ export async function download(options: DownloadOptions): Promise<BinaryPaths> {
}

// get platform
const { binaryTarget, ...os } = await getPlatformInfo()
const { binaryTarget } = await getPlatformInfo()

if (os.targetDistro && ['nixos'].includes(os.targetDistro) && !allEngineEnvVarsSet(Object.keys(options.binaries))) {
console.error(
`${yellow('Warning')} Precompiled engine files are not available for ${
os.targetDistro
}, please provide the paths via environment variables, see https://pris.ly/d/custom-engines`,
)
} else if (
['freebsd11', 'freebsd12', 'freebsd13', 'freebsd14', 'freebsd15', 'openbsd', 'netbsd'].includes(binaryTarget)
) {
if (['freebsd11', 'freebsd12', 'freebsd13', 'freebsd14', 'freebsd15', 'openbsd', 'netbsd'].includes(binaryTarget)) {
console.error(
`${yellow(
'Warning',
Expand Down
34 changes: 34 additions & 0 deletions packages/get-platform/src/__tests__/getPlatform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,40 @@ describe('getBinaryTargetForCurrentPlatformInternal', () => {
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})

it('nixos (nixos), amd64 (x86_64), openssl-3.0.x', () => {
expect(
getBinaryTargetForCurrentPlatformInternal({
platform,
libssl: '3.0.x',
arch: 'x64',
archFromUname: 'x86_64',
familyDistro: 'nixos',
originalDistro: 'nixos',
targetDistro: 'debian',
}),
).toBe('debian-openssl-3.0.x')
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
expect(ctx.mocked['console.warn'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})

it('nixos (nixos), arm64 (aarch64), openssl-3.0.x', () => {
expect(
getBinaryTargetForCurrentPlatformInternal({
platform,
libssl: '3.0.x',
arch: 'arm64',
archFromUname: 'aarch64',
familyDistro: 'nixos',
originalDistro: 'nixos',
targetDistro: 'debian',
}),
).toBe('linux-arm64-openssl-3.0.x')
expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
expect(ctx.mocked['console.warn'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(`""`)
})

it('unknown (unknown), amd64 (x86_64), openssl-3.0.x', () => {
expect(
getBinaryTargetForCurrentPlatformInternal({
Expand Down
34 changes: 33 additions & 1 deletion packages/get-platform/src/__tests__/getSSLVersion.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'

import { computeLibSSLSpecificPaths, getArchFromUname, getSSLVersion } from '../getPlatform'
import { vitestContext } from '../test-utils/vitestContext'
Expand All @@ -8,11 +8,37 @@ const describeIf = (condition: boolean) => (condition ? describe : describe.skip
const ctx = vitestContext.new().assemble()

describeIf(process.platform === 'linux')('computeLibSSLSpecificPaths', () => {
afterEach(() => {
vi.unstubAllEnvs()
})

it('should not return an error', () => {
const arch = 'x64'
const archFromUname = 'x86_64'
computeLibSSLSpecificPaths({ familyDistro: 'debian', arch, archFromUname })
})

it('returns alpine paths for alpine family', () => {
expect(computeLibSSLSpecificPaths({ familyDistro: 'alpine', arch: 'x64', archFromUname: 'x86_64' })).toEqual([
'/lib',
'/usr/lib',
])
})

it('reads nix-ld library path on nixos', () => {
vi.stubEnv('NIX_LD_LIBRARY_PATH', '/run/current-system/sw/share/nix-ld/lib:/nix/store/abc-openssl-3.0.x/lib')
vi.stubEnv('LD_LIBRARY_PATH', '')
expect(computeLibSSLSpecificPaths({ familyDistro: 'nixos', arch: 'x64', archFromUname: 'x86_64' })).toEqual([
'/run/current-system/sw/share/nix-ld/lib',
'/nix/store/abc-openssl-3.0.x/lib',
])
})

it('returns no paths on nixos without nix-ld', () => {
vi.stubEnv('NIX_LD_LIBRARY_PATH', '')
vi.stubEnv('LD_LIBRARY_PATH', '')
expect(computeLibSSLSpecificPaths({ familyDistro: 'nixos', arch: 'x64', archFromUname: 'x86_64' })).toEqual([])
})
})

describeIf(process.platform === 'linux')('getSSLVersion', () => {
Expand All @@ -38,6 +64,12 @@ describeIf(process.platform === 'linux')('getSSLVersion', () => {
expect(strategy).not.toEqual(focusedStrategy)
})

it("falls back with a path that's not a dir", async () => {
ctx.fixture('libssl-specific-path/with-libssl-0')
const { strategy } = await getSSLVersion([`${ctx.tmpDir}/libssl.so.3`])
expect(strategy).not.toEqual(focusedStrategy)
})

it('selects the oldest libssl version, excluding libssl-0.x.x', async () => {
ctx.fixture('libssl-specific-path/with-libssl-0')
const { libssl, strategy } = await getSSLVersion([ctx.tmpDir])
Expand Down
17 changes: 17 additions & 0 deletions packages/get-platform/src/__tests__/parseDistro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ ID_LIKE="opensuse suse"
originalDistro: 'opensuse-tumbleweed',
},
},
{
name: 'nixos',
content: `
NAME=NixOS
VERSION="26.05 (Yarara)"
ID=nixos
ID_LIKE=""
PRETTY_NAME="NixOS 26.05 (Yarara)"
VERSION_ID="26.05"
VERSION_CODENAME=yarara
`,
expect: {
targetDistro: 'debian',
familyDistro: 'nixos',
originalDistro: 'nixos',
},
},
{
name: 'unknown',
content: `
Expand Down
30 changes: 17 additions & 13 deletions packages/get-platform/src/getPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export type DistroInfo = {
| 'debian'
| 'musl'
| 'arm'
| 'nixos'
| 'freebsd11'
| 'freebsd12'
| 'freebsd13'
Expand Down Expand Up @@ -124,6 +123,7 @@ export function parseDistro(osReleaseInput: string): DistroInfo {
*
* Alpine Linux => ID=alpine => targetDistro=musl, familyDistro=alpine
* Raspbian => ID=raspbian, ID_LIKE=debian => targetDistro=arm, familyDistro=debian
* NixOS => ID=nixos => targetDistro=debian, familyDistro=nixos
* Debian => ID=debian => targetDistro=debian, familyDistro=debian
* Distroless => ID=debian => targetDistro=debian, familyDistro=debian
* Ubuntu => ID=ubuntu, ID_LIKE=debian => targetDistro=debian, familyDistro=debian
Expand Down Expand Up @@ -157,9 +157,9 @@ export function parseDistro(osReleaseInput: string): DistroInfo {
{ id: 'nixos' },
({ id: originalDistro }) =>
({
targetDistro: 'nixos',
originalDistro,
targetDistro: 'debian',
familyDistro: 'nixos',
originalDistro,
}) as const,
)
.with(
Expand Down Expand Up @@ -298,11 +298,22 @@ type ComputeLibSSLSpecificPathsParams = {

export function computeLibSSLSpecificPaths(args: ComputeLibSSLSpecificPathsParams) {
return match(args)
.with({ familyDistro: 'musl' }, () => {
.with({ familyDistro: 'alpine' }, () => {
/* Linux Alpine */
debug('Trying platform-specific paths for "alpine"')
return ['/lib', '/usr/lib']
})
.with({ familyDistro: 'nixos' }, () => {
/* NixOS (nix-ld lists libraries for foreign binaries in NIX_LD_LIBRARY_PATH) */
debug('Trying platform-specific paths for "nixos"')
return [
...new Set(
[process.env.NIX_LD_LIBRARY_PATH, process.env.LD_LIBRARY_PATH].flatMap((value) =>
(value ?? '').split(':').filter(Boolean),
Comment thread
LewdLeah marked this conversation as resolved.
),
),
]
})
.with({ familyDistro: 'debian' }, ({ archFromUname }) => {
/* Linux Debian, Ubuntu, etc */
debug('Trying platform-specific paths for "debian" (and "ubuntu")')
Expand Down Expand Up @@ -426,11 +437,8 @@ async function findLibSSL(directory: string) {
try {
const dirContents = await fs.readdir(directory)
return dirContents.find((value) => value.startsWith('libssl.so.') && !value.startsWith('libssl.so.0'))
} catch (e) {
if (e.code === 'ENOENT') {
return undefined
}
throw e
} catch (_) {
return undefined
}
}

Expand Down Expand Up @@ -533,10 +541,6 @@ ${additionalMessage}`,
return 'netbsd'
}

if (platform === 'linux' && targetDistro === 'nixos') {
return 'linux-nixos'
}

if (platform === 'linux' && arch === 'arm64') {
// 64 bit ARM (musl or glibc)
const baseName = targetDistro === 'musl' ? 'linux-musl-arm64' : 'linux-arm64'
Expand Down