Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ spack install additivefoam

See the [installation instructions](https://ornl.github.io/AdditiveFOAM/docs/installation/#installation) in the [documentation](https://ornl.github.io/AdditiveFOAM/) for other options for building `AdditiveFOAM`.

An alternative installation mechanism is using Nix. See
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanjs would you prefer this be in the docs instead?

[Nix.md](./envs/nix/NIX.md) for more details.

## Citing
[![DOI](https://joss.theoj.org/papers/10.21105/joss.07770/status.svg)](https://doi.org/10.21105/joss.07770)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8034097.svg)](https://doi.org/10.5281/zenodo.8034097)
Expand Down
25 changes: 25 additions & 0 deletions envs/nix/NIX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Nix

First install the [Nix package manager][NIX] and then enable
[Flakes][Flakes]. Alternatively, check out the [Determinate Systems
Installer][Determinate] for an out of the box experience. See
[nix.dev][nix.dev] for more help with Nix.

To get an environment with both AdditiveFOAM and ExaCA use

$ nix develop github:ORNL/AdditiveFOAM?dir=envs/nix
# AdditiveFOAM and ExaCA now available
$ additiveFoam --help
$ ExaCA --help

To get a specific release, use:

$ nix develop github:ORNL/AdditiveFOAM/<tag>?dir=envs/nix

See the main [README](../../README.md) for more details on building
AdditiveFOAM.

[NIX]: https://nixos.org/download.html
[Flakes]: https://nixos.wiki/wiki/Flakes
[nix.dev]: https://nix.dev
[Determinate]: https://github.com/DeterminateSystems/nix-installer
106 changes: 106 additions & 0 deletions envs/nix/additivefoam.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
stdenv,
makeWrapper,
openfoam,
openmpi,
exaca,
src,
version,
glibc,
zlib
}:
stdenv.mkDerivation rec {
pname = "additivefoam";
inherit version;
inherit src;

nativeBuildInputs = [
makeWrapper
];

buildInputs = [
openfoam
openmpi
zlib
];

propagatedBuildInputs = [
exaca
openmpi
];

buildPhase = ''
runHook preBuild

mkdir -p builduser/.OpenFOAM
mkdir -p builduser/OpenFOAM
export HOME=$(pwd)/builduser
export USER=builduser

source ${openfoam.BASHRC} || true

APPS_DIR=$(pwd)/applications/solvers/additiveFoam

cd $APPS_DIR/movingHeatSource
wmake libso

cd $APPS_DIR/functionObjects/ExaCA
wmake libso

cd $APPS_DIR
wmake

runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir -p $out

cp -r $FOAM_USER_APPBIN $out
cp -r $FOAM_USER_LIBBIN $out

cp -r ${src}/applications $out/
cp -r ${src}/tutorials $out/

runHook postInstall
'';

postInstall = ''
wrapProgram $out/bin/additiveFoam \
--suffix LD_LIBRARY_PATH : "$out/lib:${openmpi}/lib:${stdenv.cc.cc.lib}/lib:${zlib}/lib"

LINKER=${glibc}/lib/ld-linux-x86-64.so.2;
patchelf --set-interpreter $LINKER $out/bin/.additiveFoam-wrapped
'';

doCheck = false;
doInstallCheck = true;

installCheckPhase = ''

cd $HOME
mkdir -p app
cp -r ${src}/tutorials/AMB2018-02-B/* app/
chmod u+w -R app
cd app

# Ensure ExaCA is found
substituteInPlace $HOME/app/Allrun --replace-fail "~/install/exaca/bin/ExaCA" "ExaCA"

./Allrun -withExaCA

if [ -f "ExaCA/Output.vtk" ]; then
echo "Check PASSED: Output.vtk generated."
else
echo "Check FAILED: Output.vtk not found."
exit 1
fi

cd ..
rm -rf app

'';

}
41 changes: 41 additions & 0 deletions envs/nix/dev.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ self', pkgs, lib, ...}:

{
devShells = with self'.packages; rec {
default = pkgs.mkShell {
name = "additivefoam-env";

packages = [
openfoam
exaca
self'.packages.default
];

shellHook = ''
source ${openfoam.BASHRC}
'';

};

devel = pkgs.mkShell {
name = "additivefoam-dev";

packages = [
openfoam
exaca
];

inputsFrom = [
self'.packages.default
];

shellHook = ''
source ${openfoam.BASHRC}
'';

LOCALE_ARCHIVE = pkgs.lib.optional (pkgs.stdenv.hostPlatform.isLinux) (
"${pkgs.glibcLocales}/lib/locale/locale-archive"
);
};
};
}
132 changes: 132 additions & 0 deletions envs/nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions envs/nix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## See NIX.md for help getting started with Nix

{
description = "An open-source CFD code for additive manufacturing built on OpenFOAM.";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
exaca.url = "github:LLNL/ExaCA?dir=envs/nix";
parts.url = "github:hercules-ci/flake-parts";
};

outputs = inputs @ { self, parts, ... }: (
parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];

perSystem = { pkgs, inputs', ... }: {
packages = rec {
default = additivefoam;

openfoam = pkgs.callPackage ./openfoam.nix { scotch = scotch; };
scotch = pkgs.callPackage ./scotch.nix { };
exaca = inputs'.exaca.packages.default;

additivefoam = pkgs.callPackage ./additivefoam.nix {
src = ../..;
version = "master";
exaca = exaca;
openfoam = openfoam;
};
};

imports = [
./dev.nix
];
};
}
);
}
Loading