-
Notifications
You must be signed in to change notification settings - Fork 248
Add callStackToNix function #116
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
Add callStackToNix function #116
Conversation
Excellent, thanks! |
@rvl I can do that, sure. I am also trying to think about filtering. On our monorepo this routinely generates the |
this is something you'll find with |
@angerman ok I'll try to put together a test case and then take the draft tag off. That will probably happen tomorrow though. It's late here and right now the critical path for me is getting ARM cross-compilation working. |
I have been using something similar but for plan-to-nix here. It might be a useful example. In particular it filters out only the files needed (.project, .cabal and package.yaml files). Runs { pkgs, runCommand, nix-tools, cabal-install
, hackageIndex, ghc, hpack
} :
{src} :
let
cabalFiles =
builtins.filterSource (path: type:
type == "directory" ||
pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ])
src;
plan = runCommand "plan" {
buildInputs = [ ghc hpack ];
} ''
tmp=$(mktemp -d)
cd $tmp
cp -r ${cabalFiles}/* .
chmod +w -R .
find . -name package.yaml -exec hpack "{}" \;
HOME=${hackageIndex} ${cabal-install}/bin/cabal new-configure
HOME=$out ${nix-tools}/bin/plan-to-nix --plan-json dist-newstyle/cache/plan.json -o nix-plan
cp -r nix-plan $out
'';
in
runCommand "plan-and-src" {} ''
mkdir $out
cp -r ${src}/* $out
ln -sf ${plan} $out/nix-plan
'' |
@hamishmack hpack depends on the .hs files in the source tree to infer some module lists. So it seems like your source filter would result in incorrect module lists unless one is following a convention of setting both exposed-modules and other-modules explciitly in every package.yaml file. |
As far as I know plan-to-nix does not depend on the module lists, so I think it should be ok. The |
I'm not sure if @eamsden was referring to the initial invocation of -- haskell.nix/modules/package.nix Lines 158 to 161 in 6614367
|
@eamsden any update on this? |
@eamsden If you don't have time to create an IFD test case then I can do it. Also I'm curious to know, will this work in a sandboxed build when the |
@rvl I'm busy trying to get cross-compilation to work, so if you are able to make a test case that would be great! I imagine there might be issues with fetching from git. I haven't yet tried it with that. It depends on how stack-to-nix works, that is, if it tries to fetch files from git during its run. I can think of a couple of ways to help with that, but again, I'm pushing hard on cross compilation. |
I'll try to give this a try today. |
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.
Apart from the things I don't understand, this looks good to me!
call-stack-to-nix.nix
Outdated
pkgsNix = pkgs.stdenv.mkDerivation { | ||
name = "pkgs-nix"; | ||
inherit src; | ||
nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git pkgs.rsync ]; |
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.
why do we need pkgs.rsync
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.
rsync
handles copying hidden files and directories (like .plan.nix
and .stack.nix
) better than cp
. I couldn't get cp
to do that reliably. Maybe there is a flag I am missing?
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.
Oh. I guess it is no longer used since I'm calling stack-to-nic directly into $out. I'll get rid of it.
default.nix
Outdated
@@ -52,7 +52,12 @@ let | |||
override = "stackage"; | |||
}); | |||
|
|||
packages = self: ({ |
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.
I keep wondering if we can't simplify this. Do we really need to bring in the callPackage logic for the buildPackages?
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.
I needed the callPackages stuff in buildPackages as callStackToNix needs to be built with buildPackages, otherwise if you do a cross-compile you wind up building nix-tools for the host platform rather than the build platform. This actually escaped my notice at first because I had binfmt emulation for armv7l set up on my build machine, but popped up when I tried an Aarch64 cross compile.
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.
Can't we just pull nix-tools from pkgs.buildPackages.callPackage ./nix-tools { inherit fetchExternal; };
In the end I think it all comes down to the UX/UI we expect the consumer to use, right now it's mostly like this: haskell.callPackage ./some/path where { mkStackPkgSet, callStackToNix, ... }:
let
pkgSet = mkStackPkgSet {
stack-pkgs = callStackToNix { src = ./.; };
pkg-def-extras = [];
modules = [];
}; Most of the code in However for the nix-tools = pkgs.buildPackages.callPackage ./nix-tools
{ inherit fetchExternal; inherit (self) mkCabalProjectPkgSet; }; or am I mistaken? |
dfb1f57
to
4135f9d
Compare
@eamsden thanks for noticing that nix-tools needs to be built with @angerman Sorry I got to the PR review party a bit late, but I think the corrections you have made w.r.t. |
@angerman: you broke it :( If you just call the nix tools package from pkgs.buildPackage it still tries to build it as cross-compiled, because of the way the haskell.nix packages pass around stdenv etc. That was why I added the buildPackages attribute to the haskell package set the way I did, to make sure that the whole scope was properly set up for buildPackages. Right now if I try to build a package set that uses callStackToNix as a cross-compiled build, with your changes in place, it will still try to build nix-tools as a cross-compiled build and then run them on the build machine. I know the way I had it set up was not as clean but it was the result of a lot of trying and failing to get nix-tools to build on the right platform. |
Add a
callStackToNix
function which can be pointed at a source directory with a package set and generate an input to mkStackPkgSet.This still needs better filtering so that it is only rebuild when stack.yaml or a package definition changes.