-
Notifications
You must be signed in to change notification settings - Fork 22
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
Refactor: move impl to inner config #63
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc79ecb
wip
srid 5e64443
finish
srid 70f0d19
finialize
srid 9010b35
shift devShell.enable check to outer config
srid 6b1b26a
changelog, etc.
srid d836242
move main impl to separate file
srid 6d74866
cleanups
srid a154e9e
rm unnecessary abstraction
srid 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 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 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 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,117 @@ | ||
# Definition of the `haskellProjects.${name}` submodule's `config` | ||
{ name, self, config, lib, pkgs, ... }: | ||
let | ||
# Like pkgs.runCommand but runs inside nix-shell with a mutable project directory. | ||
# | ||
# It currenty respects only the nativeBuildInputs (and no shellHook for | ||
# instance), which seems sufficient for our purposes. We also set $HOME and | ||
# make the project root mutable, because those are expected when running | ||
# something in a project shell (it is indeed the case with HLS). | ||
runCommandInSimulatedShell = devShell: projectRoot: name: attrs: command: | ||
pkgs.runCommand name (attrs // { nativeBuildInputs = devShell.nativeBuildInputs; }) | ||
'' | ||
# Set pipefail option for safer bash | ||
set -euo pipefail | ||
|
||
# Copy project root to a mutable area | ||
# We expect "command" to mutate it. | ||
export HOME=$TMP | ||
cp -R ${projectRoot} $HOME/project | ||
chmod -R a+w $HOME/project | ||
pushd $HOME/project | ||
|
||
${command} | ||
touch $out | ||
''; | ||
in | ||
{ | ||
outputs = | ||
let | ||
projectKey = name; | ||
|
||
localPackagesOverlay = self: _: | ||
let | ||
fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg)); | ||
filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; }; | ||
in | ||
lib.mapAttrs | ||
(name: value: | ||
let | ||
# callCabal2nix does not need a filtered source. It will | ||
# only pick out the cabal and/or hpack file. | ||
pkgProto = self.callCabal2nix name value.root { }; | ||
pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto { | ||
src = filterSrc name value.root; | ||
}; | ||
in | ||
fromSdist pkgFiltered) | ||
config.packages; | ||
finalOverlay = | ||
lib.composeManyExtensions | ||
[ | ||
# The order here matters. | ||
# | ||
# User's overrides (cfg.overrides) is applied **last** so | ||
# as to give them maximum control over the final package | ||
# set used. | ||
localPackagesOverlay | ||
(pkgs.haskell.lib.packageSourceOverrides config.source-overrides) | ||
config.overrides | ||
]; | ||
finalPackages = config.haskellPackages.extend finalOverlay; | ||
|
||
defaultBuildTools = hp: with hp; { | ||
inherit | ||
cabal-install | ||
haskell-language-server | ||
ghcid | ||
hlint; | ||
}; | ||
nativeBuildInputs = lib.attrValues (defaultBuildTools finalPackages // config.devShell.tools finalPackages); | ||
devShell = finalPackages.shellFor { | ||
inherit nativeBuildInputs; | ||
packages = p: | ||
map | ||
(name: p."${name}") | ||
(lib.attrNames config.packages); | ||
withHoogle = true; | ||
}; | ||
in | ||
{ | ||
packages = | ||
let | ||
mapKeys = f: attrs: lib.mapAttrs' (n: v: { name = f n; value = v; }) attrs; | ||
# Prefix package names with the project name (unless | ||
# project is named `default`) | ||
dropDefaultPrefix = packageName: | ||
if projectKey == "default" | ||
then packageName | ||
else "${projectKey}-${packageName}"; | ||
in | ||
mapKeys dropDefaultPrefix | ||
(lib.mapAttrs | ||
(name: _: finalPackages."${name}") | ||
config.packages); | ||
|
||
devShells."${projectKey}" = devShell; | ||
|
||
checks = lib.filterAttrs (_: v: v != null) { | ||
"${projectKey}-hls" = | ||
if config.devShell.hlsCheck.enable then | ||
runCommandInSimulatedShell | ||
devShell | ||
self "${projectKey}-hls-check" | ||
{ } "haskell-language-server" | ||
else null; | ||
"${projectKey}-hlint" = | ||
if config.devShell.hlintCheck.enable then | ||
runCommandInSimulatedShell | ||
devShell | ||
self "${projectKey}-hlint-check" | ||
{ } '' | ||
hlint ${lib.concatStringsSep " " config.devShell.hlintCheck.dirs} | ||
'' | ||
else null; | ||
}; | ||
}; | ||
} |
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.
@roberth Is there a better way of doing this (instead of the
//
, which seems like kind of a hack)?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.
Yeah, I think we can use module machinery for this, and we probably want that for those little modules with haskell-flake overrides anyway.
projectSubmodule = submoduleWith { specialArgs = { inherit pkgs self; }; modules = [ ..... ] }
.specialArgs
should be fine here, as we don't think we want modules to affect those parameters (not 100% sure aboutpkgs
, but that can be improved later if necessary)imports = [ ./haskell-project.nix ];
here