-
-
Notifications
You must be signed in to change notification settings - Fork 401
nix: refactor with flakes #1827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0bdef8e
nix: refactor with flakes
berberman 48ce32a
Merge branch 'master' into nix-flakes
berberman a687d2a
Update github actions
berberman 421c1fd
Make pre-commit-hooks/flake-utils follows flake-utils
berberman e32f4a8
Update github actions
berberman 6bb7374
Update github actions
berberman 194046e
Support multi GHC versions
berberman b1d70ff
Update github actions
berberman b8227ba
Copy postInstall from nixpkgs
berberman ee9f5e8
Remove invalid ghc865
berberman a7febe6
Merge branch 'master' into nix-flakes
berberman 295ae9f
Merge branch 'master' into nix-flakes
berberman 450c91f
Update README
berberman bd37c8d
Use nixpkgs-unstable
berberman 47d5a94
Merge branch 'master' into nix-flakes
berberman a2b60a6
Update README
berberman 39a9f17
Merge branch 'master' into nix-flakes
berberman f94725a
Add plugins automatically
berberman b29b2c3
Merge branch 'master' into nix-flakes
berberman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,7 @@ test/testdata/**/hie.yaml | |
# ghcide-bench | ||
*.identifierPosition | ||
/bench/example | ||
|
||
# nix | ||
result | ||
result-doc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(import ( | ||
let | ||
lock = builtins.fromJSON (builtins.readFile ./flake.lock); | ||
in fetchTarball { | ||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; | ||
sha256 = lock.nodes.flake-compat.locked.narHash; } | ||
) { | ||
src = ./.; | ||
}).defaultNix |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
# 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 = "haskell language server flake"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
flake-compat = { | ||
url = "github:edolstra/flake-compat"; | ||
flake = false; | ||
}; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
pre-commit-hooks = { | ||
url = "github:cachix/pre-commit-hooks.nix"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
inputs.flake-utils.follows = "flake-utils"; | ||
}; | ||
gitignore = { | ||
url = "github:hercules-ci/gitignore.nix"; | ||
flake = false; | ||
}; | ||
}; | ||
outputs = | ||
{ self, nixpkgs, flake-compat, flake-utils, pre-commit-hooks, gitignore }: | ||
{ | ||
overlay = final: prev: | ||
with prev; | ||
let | ||
haskellOverrides = { | ||
overrides = 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; | ||
}); | ||
}; | ||
}; | ||
gitignoreSource = (import gitignore { inherit lib; }).gitignoreSource; | ||
|
||
# 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; | ||
hls-brittany-plugin = ./plugins/hls-brittany-plugin; | ||
hls-stylish-haskell-plugin = ./plugins/hls-stylish-haskell-plugin; | ||
hls-class-plugin = ./plugins/hls-class-plugin; | ||
hls-haddock-comments-plugin = ./plugins/hls-haddock-comments-plugin; | ||
hls-eval-plugin = ./plugins/hls-eval-plugin; | ||
hls-explicit-imports-plugin = ./plugins/hls-explicit-imports-plugin; | ||
hls-refine-imports-plugin = ./plugins/hls-refine-imports-plugin; | ||
hls-hlint-plugin = ./plugins/hls-hlint-plugin; | ||
hls-retrie-plugin = ./plugins/hls-retrie-plugin; | ||
hls-splice-plugin = ./plugins/hls-splice-plugin; | ||
hls-tactics-plugin = ./plugins/hls-tactics-plugin; | ||
hls-floskell-plugin = ./plugins/hls-floskell-plugin; | ||
}; | ||
|
||
# Tweak our packages | ||
tweaks = hself: hsuper: | ||
with haskell.lib; { | ||
hls-hlint-plugin = | ||
hsuper.hls-hlint-plugin.override { hlint = hself.hlint_3_2_7; }; | ||
hls-tactics-plugin = hsuper.hls-tactics-plugin.override { | ||
refinery = hself.refinery_0_3_0_0; | ||
}; | ||
}; | ||
|
||
hlsSources = | ||
builtins.mapAttrs (_: dir: gitignoreSource dir) sourceDirs; | ||
|
||
extended = hpkgs: | ||
(hpkgs.override haskellOverrides).extend (hself: hsuper: | ||
# 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 | ||
gen-hls-changelogs = | ||
let myGHC = haskellPackages.ghcWithPackages (p: with p; [ github ]); | ||
in runCommand "gen-hls-changelogs" { | ||
passAsFile = [ "text" ]; | ||
preferLocalBuild = true; | ||
allowSubstitutes = false; | ||
buildInputs = [ git myGHC ]; | ||
} '' | ||
dest=$out/bin/gen-hls-changelogs | ||
mkdir -p $out/bin | ||
echo "#!${runtimeShell}" >> $dest | ||
echo "${myGHC}/bin/runghc ${./GenChangelogs.hs}" >> $dest | ||
chmod +x $dest | ||
''; | ||
}; | ||
} // (flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ]) | ||
(system: | ||
let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
overlays = [ self.overlay ]; | ||
config = { allowBroken = true; }; | ||
}; | ||
|
||
# Pre-commit hooks to run stylish-haskell | ||
pre-commit-check = pre-commit-hooks.lib.${system}.run { | ||
src = ./.; | ||
hooks = { | ||
stylish-haskell.enable = true; | ||
stylish-haskell.excludes = [ | ||
# Ignored files | ||
"^Setup.hs$" | ||
"test/testdata/.*$" | ||
"test/data/.*$" | ||
"test/manual/lhs/.*$" | ||
"^hie-compat/.*$" | ||
"^plugins/hls-tactics-plugin/.*$" | ||
|
||
# Temporarily ignored files | ||
# Stylish-haskell (and other formatters) does not work well with some CPP usages in these files | ||
"^ghcide/src/Development/IDE/GHC/Compat.hs$" | ||
"^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$" | ||
"^ghcide/test/exe/Main.hs$" | ||
"ghcide/src/Development/IDE/Core/Rules.hs" | ||
"^hls-test-utils/src/Test/Hls/Util.hs$" | ||
]; | ||
}; | ||
}; | ||
|
||
# GHC versions | ||
ghcDefault = pkgs.hlsHpkgs ("ghc" | ||
+ pkgs.lib.replaceStrings [ "." ] [ "" ] | ||
pkgs.haskellPackages.ghc.version); | ||
ghc884 = pkgs.hlsHpkgs "ghc884"; | ||
ghc8104 = pkgs.hlsHpkgs "ghc8104"; | ||
ghc901 = pkgs.hlsHpkgs "ghc901"; | ||
|
||
# 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; | ||
map (name: p.${name}) (attrNames pkgs.hlsSources); | ||
buildInputs = [ gmp zlib ncurses capstone tracy gen-hls-changelogs ] | ||
++ (with haskellPackages; [ | ||
cabal-install | ||
hlint | ||
ormolu | ||
stylish-haskell | ||
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 | ||
${pre-commit-check.shellHook} | ||
''; | ||
}; | ||
# 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; | ||
haskell-language-server-8104-dev = mkDevShell ghc8104; | ||
haskell-language-server-901-dev = mkDevShell ghc901; | ||
|
||
# hls package | ||
haskell-language-server = mkExe ghcDefault; | ||
haskell-language-server-884 = mkExe ghc884; | ||
haskell-language-server-8104 = mkExe ghc8104; | ||
haskell-language-server-901 = mkExe ghc901; | ||
}; | ||
|
||
defaultPackage = packages.haskell-language-server; | ||
|
||
devShell = packages.haskell-language-server-dev; | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch protection rules need to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done