Skip to content

Introduce nix: use prebuilt binary packages from nixpkgs#4119

Draft
qbisi wants to merge 1 commit intoFEniCS:mainfrom
qbisi:nix
Draft

Introduce nix: use prebuilt binary packages from nixpkgs#4119
qbisi wants to merge 1 commit intoFEniCS:mainfrom
qbisi:nix

Conversation

@qbisi
Copy link
Contributor

@qbisi qbisi commented Mar 7, 2026

install nix

One can try the nix way in multiple platforms:

docker:

docker run -it nixos/nix

linux distro/macos:

# lix(another nix implemention) installer, easy to uninstall
curl -sSf -L https://install.lix.systems/lix | sh -s -- install

or

# official nix installer, hard to uninstall, see https://nix.dev/manual/nix/2.24/installation/uninstall
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon

install fenics-dolfinx

Once you have nix installed in your system, try this one-line to create python-venv with dolfinx installed

nix-shell -p "python3.withPackages (ps: with ps; [ fenics-dolfinx pyvista ])" \
  --run "python -m venv --system-site-packages .venv"

One might wonder where's the mpiexec that is compatible with the prebuilt petsc library, you can manually install mpi from nixpkgs by

#for nix flake enabled
nix profile install mpi

#for nix flake disabled
nix-env -iA mpi

or adding this shellHook to your zshrc

@qbisi qbisi changed the title introduce nix: use prebuilt binary packages from nixpkgs Introduce nix: use prebuilt binary packages from nixpkgs Mar 7, 2026
@jhale
Copy link
Member

jhale commented Mar 9, 2026

I'd be open to adding a 'community supported' list of packaging systems to point people in the right direction (with a disclaimer), but I would rather not imply official support by providing a full set of instructions.

@qbisi
Copy link
Contributor Author

qbisi commented Mar 9, 2026

The purpose is to draw dev/users's attention to nix build system. Not meant to burden the maintaince of this project.
There are three advantages using nix.

  1. multiplatform support including darwin
  2. reproducibility of nix build system
  3. customizability to override fenics-dolfinx/petsc .e.g. build petsc with mpich/complex-scalar
# shell.nix
with import <nixpkgs> {
  overlays = [
    (final: prev: {
      petsc = prev.petsc.override {
        mpi = prev.mpich;
        scalarType = "complex";
        # hypre's complex support is broken
        withHypre = false;
      };
    })
  ];
};

mkShell {
  packages = [
    (python3.withPackages (ps: [ ps.fenics-dolfinx ]))
  ];
}

@jhale
Copy link
Member

jhale commented Mar 10, 2026

I will not accept the PR as it is - I do not really want to recommend nixos, or add huge amounts of nixos recipes to the README. We have had issues in the past with community maintained packages of varying quality and levels of support and it's caused issues for our users.

I would propose the following:

#### Community-maintained packages

These packages are provided by community members and are not officially supported by the FEniCS Project developers.

- [NixOS](https://nixos.org)

or similar.

@qbisi
Copy link
Contributor Author

qbisi commented Mar 10, 2026

I will follow the recommend style and mark this draft for now.

@qbisi qbisi marked this pull request as draft March 10, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants