cabal2nix-2.19.0: Convert Cabal files into Nix build instructions.
Safe HaskellNone
LanguageHaskell2010

Distribution.Nixpkgs.Haskell.Platform

Description

This module defines conversions from the (autoconf-derived) platform strings nixpkgs uses into Cabal's Platform type. This is intended to facilitate later evaluation of .cabal files. For this conversion Cabal's Permissive heuristics are used as well as a logic equivalent to the GHC_CONVERT_* macros from GHC's configure script.

Since the process is inherently lossy because Cabal ignores certain factors like endianness, conversion from Platform to nixpkgs' platform strings. For this usecase, try Distribution.Nixpkgs.Meta from distribution-nixpkgs.

Synopsis

Documentation

parsePlatformLenient :: String -> Maybe Platform Source #

Convert a platform string of two or three(-ish) components to Platform.

For this, the following logic is utilized:

  • If the string has one dash, the form cpu-os is assumed where os may only have a single component. The vendor part is ignored.
  • Otherwise cpu-vendor-os is assumed where os may have any number of components separated by dashes to accomodate its two component kernel-system form.

Note: This behavior is different from nixpkgs' lib.systems.elaborate: Because we have no knowledge of the legal contents of the different parts, we only decide how to parse it based on what form the string has. This can give different results compared to autoconf or nixpkgs. It will also never reject an invalid platform string that has a valid form.

>>> parsePlatformLenient "x86_64-unknown-linux"
Just (Platform X86_64 Linux)
>>> parsePlatformLenient "x86_64-pc-linux-gnu"
Just (Platform X86_64 Linux)
>>> parsePlatformLenient "x86_64-linux"
Just (Platform X86_64 Linux)

Note also that this conversion sometimes looses information nixpkgs would retain:

>>> parsePlatformLenient "powerpc64-unknown-linux"
Just (Platform PPC64 Linux)
>>> parsePlatformLenient "powerpc64le-unknown-linux"
Just (Platform PPC64 Linux)

parsePlatformFromSystemLenient :: String -> Maybe Platform Source #

Convert a Nix style system tuple into a Cabal Platform. The tuple is assumed to be of the form cpu-os, any extra components are assumed to be part of os to accomodate its kernel-system form.

The same caveats about validation and lossiness apply as for parsePlatformLenient.

>>> parsePlatformFromSystemLenient "x86_64-linux"
Just (Platform X86_64 Linux)
>>> parsePlatformFromSystemLenient "x86_64-linux-musl"
Just (Platform X86_64 Linux)
>>> parsePlatformFromSystemLenient "i686-netbsd"
Just (Platform I386 NetBSD)