Nix shell environment to run OpenFOAM simulations reproducibly
Go to file
2025-04-22 17:02:45 +02:00
pkgs/openfoam pkgs/openfoam: set OpenFOAM version to 11.20240704 2025-04-22 17:02:45 +02:00
sims setting sail 2025-04-22 16:57:29 +02:00
.envrc setting sail 2025-04-22 16:57:29 +02:00
.gitignore setting sail 2025-04-22 16:57:29 +02:00
flake.lock setting sail 2025-04-22 16:57:29 +02:00
flake.nix setting sail 2025-04-22 16:57:29 +02:00
README.md setting sail 2025-04-22 16:57:29 +02:00
shell.nix setting sail 2025-04-22 16:57:29 +02:00

OpenFOAM nix shell environment

Usage

With direnv installed and active (eval $"(direnv hook bash)") the environment loads itself when you enter this directory or any below it. Simulations can be placed inside the sims directory. The sims directory is ignored by git. If you change branches your simulations should stay untouched. However it may lead to confusion if you have simulation results from one OpenFOAM version and then change to another. Clone this repository again for each OpenFOAM version you want to use to not confuse yourself ;-)

Requirements

nix with flakes

On nixos flakes can be enabled by adding the following to your system configuration:

nix.settings.experimental-features = [ "nix-command" "flakes" ];

On other systems add the following to your /etc/nix/nix.conf:

experimental-features = nix-command flakes

direnv

After installing direnv it has to be loaded. Maybe add the hook to your shellrc:

echo 'eval "$(direnv hook bash)"' >> ~/.bashrc

See https://direnv.net/docs/hook.html for more information. You'll need to allow the current directory:

direnv allow

Update nixpkgs

From within this directory run

nix flake update

to pin to the latest nixpkgs version.

Update OpenFOAM version

The OpenFOAM derivation is defined in pkgs/openfoam/default.nix. Edit the variables in the let block at the top of the file and replace the "sha256-..." string with an empty string. The first build will then fail and give you the correct sha hash. Replace the empty string with it.

Add different OpenFOAM release

There are branches for each OpenFOAM release. The main branch has always the latest version. If you want to add a new one:

  • create a new branch to hold the current version (e.g. openfoam-12)
  • update the repository path in pkgs/openfoam/default.nix by editing the parameters in the let block.
  • adjust the patches, postPatch, configurePhase, buildPhase and installPhase if required

Reevaluating envrc will build the new OpenFOAM (this may take a while (expect up to 1h).