2021-05-19 10:32:23 +03:00
# Maintaining this file:
#
# - Bump the inputs version using `nix flake update`
# - Edit `sourceDirs` to update the set of local packages
#
# For more details: https://nixos.wiki/wiki/Flakes
{
description = " h a s k e l l l a n g u a g e s e r v e r f l a k e " ;
inputs = {
nixpkgs . url = " g i t h u b : N i x O S / n i x p k g s / n i x p k g s - u n s t a b l e " ;
flake-compat = {
url = " g i t h u b : e d o l s t r a / f l a k e - c o m p a t " ;
flake = false ;
} ;
flake-utils . url = " g i t h u b : n u m t i d e / f l a k e - u t i l s " ;
pre-commit-hooks = {
url = " g i t h u b : c a c h i x / p r e - c o m m i t - h o o k s . n i x " ;
inputs . nixpkgs . follows = " n i x p k g s " ;
inputs . flake-utils . follows = " f l a k e - u t i l s " ;
} ;
gitignore = {
url = " g i t h u b : h e r c u l e s - c i / g i t i g n o r e . n i x " ;
flake = false ;
} ;
} ;
outputs =
{ self , nixpkgs , flake-compat , flake-utils , pre-commit-hooks , gitignore }:
{
overlay = final : prev :
with prev ;
let
2021-07-04 08:15:04 +03:00
haskellOverrides = hself : hsuper : {
# we override mkDerivation here to apply the following
# tweak to each haskell package:
# if the package is broken, then we disable its check and relax the cabal bounds;
# otherwise, we leave it unchanged.
# hopefully, this could fix packages marked as broken by nix due to check failures
# or the build failure because of tight cabal bounds
mkDerivation = args :
let
broken = args . broken or false ;
check = args . doCheck or true ;
jailbreak = args . jailbreak or false ;
in hsuper . mkDerivation ( args // {
jailbreak = if broken then true else jailbreak ;
doCheck = if broken then false else check ;
} ) ;
2021-05-19 10:32:23 +03:00
} ;
gitignoreSource = ( import gitignore { inherit lib ; } ) . gitignoreSource ;
# List all subdirectories under `./plugins`, except `./plugins/default`
pluginsDir = ./plugins ;
pluginSourceDirs = builtins . removeAttrs ( lib . mapAttrs'
( name : _ : lib . nameValuePair name ( pluginsDir + ( " / " + name ) ) )
( builtins . readDir pluginsDir ) ) [ " d e f a u l t " ] ;
# Source directories of our packages, should be consistent with cabal.project
sourceDirs = {
haskell-language-server = ./. ;
ghcide = ./ghcide ;
hls-graph = ./hls-graph ;
shake-bench = ./shake-bench ;
hie-compat = ./hie-compat ;
hls-plugin-api = ./hls-plugin-api ;
hls-test-utils = ./hls-test-utils ;
} // pluginSourceDirs ;
# Tweak our packages
2021-05-27 07:33:28 +03:00
# Don't use `callHackage`, it requires us to override `all-cabal-hashes`
2021-05-19 10:32:23 +03:00
tweaks = hself : hsuper :
with haskell . lib ; {
2021-09-15 20:17:40 +03:00
hiedb = hself . callCabal2nix " h i e d b "
( builtins . fetchTarball {
url = " h t t p s : / / h a c k a g e . h a s k e l l . o r g / p a c k a g e / h i e d b - 0 . 4 . 1 . 0 / h i e d b - 0 . 4 . 1 . 0 . t a r . g z " ;
sha256 = " 1 1 s 7 l f k d 6 f c 3 z f 3 k g y p 3 j h i c b h x p n 6 j p 0 y j a h l 8 d 2 8 h i c w r 2 q d p i " ;
} ) { } ;
2021-05-27 07:33:28 +03:00
2021-09-10 07:31:38 +03:00
lsp = hself . lsp_1_2_0_1 ;
2021-07-23 02:55:10 +03:00
2021-09-10 07:31:38 +03:00
lsp-types = hself . lsp-types_1_3_0_1 ;
2021-07-23 02:55:10 +03:00
2021-09-10 07:31:38 +03:00
lsp-test = hself . lsp-test_0_14_0_1 ;
2021-05-19 10:32:23 +03:00
} ;
hlsSources =
builtins . mapAttrs ( _ : dir : gitignoreSource dir ) sourceDirs ;
extended = hpkgs :
2021-07-04 08:15:04 +03:00
( hpkgs . override ( old : {
overrides = lib . composeExtensions ( old . overrides or ( _ : _ : { } ) )
haskellOverrides ;
} ) ) . extend ( hself : hsuper :
2021-05-19 10:32:23 +03:00
# disable all checks for our packages
builtins . mapAttrs ( _ : drv : haskell . lib . dontCheck drv )
( lib . composeExtensions
( haskell . lib . packageSourceOverrides hlsSources ) tweaks hself
hsuper ) ) ;
in {
inherit hlsSources ;
# Haskell packages extended with our packages
hlsHpkgs = compiler : extended haskell . packages . ${ compiler } ;
# Support of GenChangelogs.hs
2021-07-01 19:57:50 +03:00
gen-hls-changelogs = hpkgs :
let myGHC = hpkgs . ghcWithPackages ( p : with p ; [ github ] ) ;
2021-05-19 10:32:23 +03:00
in runCommand " g e n - h l s - c h a n g e l o g s " {
passAsFile = [ " t e x t " ] ;
preferLocalBuild = true ;
allowSubstitutes = false ;
buildInputs = [ git myGHC ] ;
} ''
dest = $ out/bin/gen-hls-changelogs
mkdir - p $ out/bin
echo " # ! ${ runtimeShell } " > > $ dest
echo " ${ myGHC } / b i n / r u n g h c ${ ./GenChangelogs.hs } " > > $ dest
chmod + x $ dest
'' ;
} ;
} // ( flake-utils . lib . eachSystem [ " x 8 6 _ 6 4 - l i n u x " " x 8 6 _ 6 4 - d a r w i n " ] )
( system :
let
pkgs = import nixpkgs {
inherit system ;
overlays = [ self . overlay ] ;
config = { allowBroken = true ; } ;
} ;
# Pre-commit hooks to run stylish-haskell
2021-07-01 19:57:50 +03:00
pre-commit-check = hpkgs : pre-commit-hooks . lib . ${ system } . run {
2021-05-19 10:32:23 +03:00
src = ./. ;
hooks = {
stylish-haskell . enable = true ;
2021-07-01 19:57:50 +03:00
# use stylish-haskell with our target ghc
2021-07-04 08:15:04 +03:00
stylish-haskell . entry = pkgs . lib . mkForce " ${ hpkgs . stylish-haskell } / b i n / s t y l i s h - h a s k e l l - - i n p l a c e " ;
2021-05-19 10:32:23 +03:00
stylish-haskell . excludes = [
# Ignored files
" ^ S e t u p . h s $ "
" t e s t / t e s t d a t a / . * $ "
" t e s t / d a t a / . * $ "
" t e s t / m a n u a l / l h s / . * $ "
" ^ h i e - c o m p a t / . * $ "
" ^ p l u g i n s / h l s - t a c t i c s - p l u g i n / . * $ "
# Temporarily ignored files
# Stylish-haskell (and other formatters) does not work well with some CPP usages in these files
" ^ g h c i d e / s r c / D e v e l o p m e n t / I D E / G H C / C o m p a t . h s $ "
" ^ p l u g i n s / h l s - s p l i c e - p l u g i n / s r c / I d e / P l u g i n / S p l i c e . h s $ "
" ^ g h c i d e / t e s t / e x e / M a i n . h s $ "
" g h c i d e / s r c / D e v e l o p m e n t / I D E / C o r e / R u l e s . h s "
" ^ h l s - t e s t - u t i l s / s r c / T e s t / H l s / U t i l . h s $ "
] ;
} ;
} ;
2021-07-04 08:15:04 +03:00
ghc901Config = ( import ./configuration-ghc-901.nix ) { inherit pkgs ; } ;
2021-05-19 10:32:23 +03:00
# GHC versions
ghcDefault = pkgs . hlsHpkgs ( " g h c "
+ pkgs . lib . replaceStrings [ " . " ] [ " " ]
pkgs . haskellPackages . ghc . version ) ;
ghc884 = pkgs . hlsHpkgs " g h c 8 8 4 " ;
2021-09-10 07:31:38 +03:00
ghc8107 = pkgs . hlsHpkgs " g h c 8 1 0 7 " ;
2021-07-04 08:15:04 +03:00
ghc901 = ghc901Config . tweakHpkgs ( pkgs . hlsHpkgs " g h c 9 0 1 " ) ;
2021-05-19 10:32:23 +03:00
2021-08-11 11:54:51 +03:00
# For markdown support
myst-parser = pkgs . python3Packages . callPackage ./myst-parser.nix { } ;
sphinx_rtd_theme = pkgs . python3Packages . sphinx_rtd_theme . overrideAttrs ( oldAttrs : {
# For https://github.com/readthedocs/sphinx_rtd_theme/pull/1185, otherwise lists are broken locally
src = pkgs . fetchFromGitHub {
owner = " r e a d t h e d o c s " ;
repo = " s p h i n x _ r t d _ t h e m e " ;
rev = " 3 4 f 8 1 d a a f 5 2 4 6 6 3 6 6 c 8 0 0 0 3 d b 2 9 3 d 5 0 0 7 5 c 1 b 8 9 6 " ;
sha256 = " 0 r k r s v v q r 6 g 2 p 3 v 5 v q 8 8 j h f p 5 s d 0 r 1 j q j h 3 v c 5 y 2 6 j n 3 0 z 8 s 4 f k z " ;
} ;
} ) ;
pythonWithPackages = pkgs . python3 . withPackages ( ps : [ ps . sphinx myst-parser sphinx_rtd_theme ps . pip ] ) ;
docs = pkgs . stdenv . mkDerivation {
name = " h l s - d o c s " ;
src = pkgs . lib . sourceFilesBySuffices ./docs [ " . p y " " . r s t " " . m d " " . p n g " " . g i f " " . s v g " ] ;
buildInputs = [ pythonWithPackages ] ;
# -n gives warnings on missing link targets, -W makes warnings into errors
buildPhase = '' s p h i n x - b u i l d - n - W . $o u t '' ;
dontInstall = true ;
} ;
2021-05-19 10:32:23 +03:00
# Create a development shell of hls project
# See https://github.com/NixOS/nixpkgs/blob/5d4a430472cafada97888cc80672fab255231f57/pkgs/development/haskell-modules/make-package-set.nix#L319
mkDevShell = hpkgs :
with pkgs ;
hpkgs . shellFor {
doBenchmark = true ;
packages = p :
with builtins ;
2021-07-04 08:15:04 +03:00
map ( name : p . ${ name } ) ( attrNames
( if hpkgs . ghc . version == " 9 . 0 . 1 " then
removeAttrs hlsSources ghc901Config . disabledPlugins
else
hlsSources ) ) ;
2021-08-11 11:54:51 +03:00
buildInputs = [ gmp zlib ncurses capstone tracy ( gen-hls-changelogs hpkgs ) pythonWithPackages ]
2021-07-01 19:57:50 +03:00
++ ( with hpkgs ; [
2021-05-19 10:32:23 +03:00
cabal-install
hlint
2021-07-04 08:15:04 +03:00
# ormolu
# stylish-haskell
2021-05-19 10:32:23 +03:00
opentelemetry-extra
] ) ;
src = null ;
shellHook = ''
export LD_LIBRARY_PATH = $ { gmp } /lib : $ { zlib } /lib : $ { ncurses } /lib : $ { capstone } /lib
export DYLD_LIBRARY_PATH = $ { gmp } /lib : $ { zlib } /lib : $ { ncurses } /lib : $ { capstone } /lib
export PATH = $ PATH:$HOME/.local/bin
2021-07-04 08:15:04 +03:00
$ { if hpkgs . ghc . version != " 9 . 0 . 1 " then ( pre-commit-check hpkgs ) . shellHook else " " }
2021-05-19 10:32:23 +03:00
'' ;
} ;
# Create a hls executable
# Copied from https://github.com/NixOS/nixpkgs/blob/210784b7c8f3d926b7db73bdad085f4dc5d79418/pkgs/development/tools/haskell/haskell-language-server/withWrapper.nix#L16
mkExe = hpkgs :
with pkgs . haskell . lib ;
justStaticExecutables ( overrideCabal hpkgs . haskell-language-server
( _ : {
postInstall = ''
remove-references-to - t $ { hpkgs . ghc } $ out/bin/haskell-language-server
remove-references-to - t $ { hpkgs . shake . data } $ out/bin/haskell-language-server
remove-references-to - t $ { hpkgs . js-jquery . data } $ out/bin/haskell-language-server
remove-references-to - t $ { hpkgs . js-dgtable . data } $ out/bin/haskell-language-server
remove-references-to - t $ { hpkgs . js-flot . data } $ out/bin/haskell-language-server
'' ;
} ) ) ;
in with pkgs ; rec {
packages = {
# dev shell
haskell-language-server-dev = mkDevShell ghcDefault ;
haskell-language-server-884-dev = mkDevShell ghc884 ;
2021-09-10 07:31:38 +03:00
haskell-language-server-8107-dev = mkDevShell ghc8107 ;
2021-07-04 08:15:04 +03:00
haskell-language-server-901-dev = mkDevShell ghc901 ;
2021-05-19 10:32:23 +03:00
# hls package
haskell-language-server = mkExe ghcDefault ;
haskell-language-server-884 = mkExe ghc884 ;
2021-09-10 07:31:38 +03:00
haskell-language-server-8107 = mkExe ghc8107 ;
2021-07-04 08:15:04 +03:00
haskell-language-server-901 = mkExe ghc901 ;
2021-08-11 11:54:51 +03:00
# docs
docs = docs ;
2021-05-19 10:32:23 +03:00
} ;
defaultPackage = packages . haskell-language-server ;
devShell = packages . haskell-language-server-dev ;
} ) ;
}