-
Notifications
You must be signed in to change notification settings - Fork 95
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
BUILD: Add Nix flake with package and devShell #1572
base: master
Are you sure you want to change the base?
Conversation
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 probably should learn more about nix, but ...
I guess there's 3 options:
- you maintain it (a good reason to stay around?)
- it's cut down as much as possible and you supply minimal instructions and we say it is unmaintained
- we don't merge
Does this need to be in the home directory? If not, it'd make option 2 more attractive (dir can have its own README etc)
|
||
# This is a hackaround because STIR requires source available at runtime. | ||
setSourceRoot = '' | ||
actualSourceRoot=; |
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.
strange indentation?
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.
''
blah
blah
''
Is a multi-line string. It is customary in Nix to indent multiline scripts to 2 spaces more than the outer scope for readability. The variable setSourceRoot contains a bash snippet to be run, that should set the sourceRoot variable, pointing to the root of the source. This is usually provided, I can't recall what problem I was solving here but happy to play around with it if we're keeping it.
propagatedBuildInputs = [ swig ] | ||
++ lib.optional buildPython [ python numpy ]; | ||
|
||
# This is a hackaround because STIR requires source available at runtime. |
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.
really? Which ones? (only registries, which in CMake are now being handled by object libraries, so no longer source)
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.
Yes, registries. That's great, I'll test it out without
] ++ lib.optionals (buildPython) [ | ||
"-DBUILD_SWIG_PYTHON=ON" | ||
] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ | ||
"-DOPENGL_INCLUDE_DIR=${lib.getInclude libGL}/include" # Borrowed from vtk |
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.
used by what?
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 believe this is side-stepping a bug or something that should be covered by nixpkgs' vtk, it shouldn't be needed.
STIR build failed in including vtk libs which were trying to include OpenGL. I didn't spend too long digging in, I should run again without this an post the error at a minimum.
''; | ||
postInstall = '' | ||
# add scripts to bin | ||
find $src/scripts -type f ! -path "*maintenance*" -name "*.sh" -exec cp -fn {} $out/bin \; |
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.
Not all are called *.sh but this should have been done by CMake anyway.
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.
This, again, is likely either outdated or a kludge for a missing script I needed that was missed. I'll run with/without and check the output/bin diff
meta = with lib; { | ||
description = "STIR - Software for Tomographic Image Reconstruction"; | ||
homepage = http://stir.sourceforge.net; | ||
license = with licenses; [ lgpl21 gpl2 free ]; # free = custom PARAPET license |
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.
apache 2 these days. Hopefully no gpl stuff around anymore
{ stdenv | ||
, lib | ||
, fetchFromGitHub | ||
, cmake , boost , itk , swig, libGL |
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.
who needs libGL?
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.
Used in the line
"-DOPENGL_INCLUDE_DIR=${lib.getInclude libGL}/include" # Borrowed from vtk
See comment there: probably compensating for an issue with the vtk in nixpkgs (used by itk)
''; | ||
cmakeFlags = [ | ||
"-DBUILD_TESTING=ON" | ||
"-DGRAPHICS=PGM" |
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.
any reason not to use None
? Not sure if anyone is use the pgm support and how long it will survive
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.
No reason, thanks
"-DSTIR_MPI=OFF" | ||
"-DSTIR_OPENMP=${if stdenv.isDarwin then "OFF" else "ON"}" | ||
] ++ lib.optionals (buildLibs) [ | ||
"-DBUILD_SHARED_LIBS=ON" |
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 doubt this works.
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? I'll have to check. I believe I needed it to build SIRF against STIR, but made it optional here in the hopes it builds faster and with a smaller closure.
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.
There's #6 (our almost oldest issue!) . It's possible that it works on Linux, but definitely not on other systems.
You surely don't need it for SIRF (VM, docker, GHA and all builds that I know of don't use it).
It should be a lot faster to build though, so if it works, you could keep it (but change the name of the variable!)
packages = forAllSystems (system: | ||
let pkgs = nixpkgsFor.${system}; in with pkgs; rec { | ||
stir = callPackage ./default.nix { inherit (python3Packages) python numpy; }; | ||
stir-nolibs = callPackage ./default.nix { buildLibs = false; buildPython = false; }; |
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.
confusing name for something which actually uses shared libs and no python.
let | ||
pkgs = nixpkgsFor.${system}; | ||
# Which STIR package to use | ||
package = self.packages.${system}.stir-nolibs; |
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 this one?
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.
Would you typically want BUILD_SHARED_DEPS=ON in your development env? I turn it off to build faster, though I can't say I acutally compared the build time for STIR recently.
If you're happy with 1, now I think about it, I'd be quite happy to maintain the nix components in perpetuity. Once set up changes are simple.
You mean the project root? Good question. Looks like it: NixOS/nix#4414 I think a user would then have to use something like |
^Except I can't guarantee I check my GitHub notification all the time, there's a good chance I'd need an email :p |
some version stuff at least... unless that can be automated (but I don't see how)
if that'd work, I'd be happier with that. Not standard of course, but fine. |
Nix is a package manager. I've been using it for a long-while, including for STIR/SIRF development. You can declaratively (i.e., using a .nix file) set up the dependencies of a file, and then drop into an environment with it (so a bit like docker to the end user) or install it to your system (like a normal package manager).
So with Nix, a user could run
nix shell github:UCL/STIR
and have STIR available (after waiting for the build, locally).Or you can load up the development env, to just load all the dependencies into the environments without having nix run the build. I run
nix develop
in the directory, then cancd build && make BUILD_TESTS && ctest
without having explicitly installed dependencies, like boost, onto the system.I don't necessarily advocate adoption - it would be tricky to maintain if no-one is using it and I've been AWOL for a long time. This PR is (1) for visibility; so that some new user could copy the .nix files locally (say they want to try STIR and are familiar with Nix), and (2) to let you know I do have it running if it is of interest.