Skip to content

Commit 533d3f8

Browse files
committed
Add Nix recipes
1 parent e8f2502 commit 533d3f8

File tree

6 files changed

+260
-0
lines changed

6 files changed

+260
-0
lines changed

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
description = "OpenPFC built with Nix";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
6+
7+
outputs = { self, nixpkgs, flake-utils }:
8+
flake-utils.lib.eachDefaultSystem (system:
9+
let
10+
pkgs = import nixpkgs { inherit system; };
11+
12+
# HeFFTe for development (master branch)
13+
heffteDev = pkgs.stdenv.mkDerivation {
14+
pname = "heffte";
15+
version = "dev";
16+
src = pkgs.fetchFromGitHub {
17+
owner = "icl-utk-edu";
18+
repo = "heffte";
19+
rev = "master";
20+
sha256 = null; # Allow Nix to compute the hash dynamically
21+
};
22+
nativeBuildInputs = [ pkgs.cmake pkgs.openmpi pkgs.fftw pkgs.fftwFloat ];
23+
};
24+
25+
# HeFFTe for releases (specific versions)
26+
heffteRelease = pkgs.callPackage ./nix/heffte.nix {
27+
fftw = pkgs.fftw;
28+
fftwFloat = pkgs.fftwFloat;
29+
openmpi = pkgs.openmpi;
30+
fetchFromGitHub = pkgs.fetchFromGitHub;
31+
cmake = pkgs.cmake;
32+
};
33+
34+
in {
35+
# Development environment
36+
devShells.default = pkgs.mkShell {
37+
nativeBuildInputs = [
38+
pkgs.cmake
39+
pkgs.openmpi
40+
pkgs.gcc
41+
pkgs.fftw
42+
pkgs.fftwFloat
43+
pkgs.nlohmann_json
44+
heffteDev
45+
];
46+
src = ./; # Use the local source for OpenPFC during development
47+
};
48+
49+
# Release builds
50+
packages.default = pkgs.callPackage ./nix/default.nix {
51+
heffte = heffteRelease;
52+
enableDocs = true;
53+
enableTests = true;
54+
catch2_3 = pkgs.catch2_3;
55+
};
56+
});
57+
}

nix/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Building with NiX
2+
3+
## What is Nix?
4+
5+
Nix is a powerful package manager and build system that provides reproducible
6+
builds, declarative configurations, and isolated development environments. It
7+
solves common problems in software development, such as dependency conflicts,
8+
non-reproducible builds, and difficulty in managing multiple versions of
9+
dependencies.
10+
11+
### Key Features of Nix:
12+
13+
- **Reproducibility**: Ensures that builds are consistent across different
14+
systems.
15+
- **Isolation**: Dependencies are isolated, preventing conflicts between
16+
projects.
17+
- **Versioning**: Allows managing multiple versions of dependencies and tools.
18+
- **Declarative Configuration**: Environments and builds are defined in a single
19+
configuration file.
20+
21+
## How We Use Nix in This Project
22+
23+
In this project, Nix is used to manage dependencies and build environments for
24+
both development and specific versions of the project. This ensures that all
25+
contributors and users can work with the same setup, regardless of their
26+
operating system or local configurations.
27+
28+
### Developing OpenPFC
29+
30+
To set up the development environment, where `HeFFTe` is built from its
31+
respective `master` branch and OpenPFC is built from the local source, run:
32+
33+
```bash
34+
nix develop
35+
```
36+
37+
This will create a shell environment with the latest source code for both projects.
38+
39+
### Building Specific Releases
40+
41+
To build a specific release of `OpenPFC` with a specific version of `HeFFTe`, use the `nix build` command with arguments. For example:
42+
43+
```bash
44+
nix build .#default --arg version "0.1.1" --arg heffteVersion "0.2.1"
45+
```
46+
47+
This command will build `OpenPFC` version `0.1.1` with `HeFFTe` version `0.2.1`.
48+
49+
### Why Use Nix?
50+
51+
By using Nix, we ensure that:
52+
53+
- All contributors have a consistent development environment.
54+
- Builds are reproducible and reliable.
55+
- Managing dependencies and versions is straightforward and conflict-free.
56+
57+
For more information about Nix, visit the [official
58+
documentation](https://nixos.org/manual/nix/stable/).

nix/default.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{ lib
2+
, stdenv
3+
, cmake
4+
, git
5+
, mpi
6+
, heffte
7+
, nlohmann_json
8+
, catch2_3 ? null
9+
, doxygen ? null
10+
, enableDocs ? false
11+
, enableTests ? true
12+
, enableExamples ? true
13+
, enableApps ? true
14+
, fetchFromGitHub
15+
, version ? "dev"
16+
, src ? ./
17+
}:
18+
19+
stdenv.mkDerivation rec {
20+
pname = "openpfc";
21+
inherit version;
22+
23+
inherit src;
24+
25+
nativeBuildInputs = [ cmake git ];
26+
buildInputs = [ mpi heffte nlohmann_json ]
27+
++ lib.optional enableDocs doxygen
28+
++ lib.optional enableTests catch2_3;
29+
30+
cmakeFlags = [
31+
"-DCMAKE_BUILD_TYPE=Release"
32+
"-DOpenPFC_BUILD_TESTS=${if enableTests then "ON" else "OFF"}"
33+
"-DOpenPFC_BUILD_EXAMPLES=${if enableExamples then "ON" else "OFF"}"
34+
"-DOpenPFC_BUILD_APPS=${if enableApps then "ON" else "OFF"}"
35+
"-DOpenPFC_BUILD_DOCUMENTATION=${if enableDocs then "ON" else "OFF"}"
36+
"-DHeffte_DIR=${heffte}/lib/cmake/Heffte"
37+
];
38+
39+
doCheck = enableTests;
40+
41+
meta = {
42+
description = "Phase Field Crystal simulation framework";
43+
homepage = "https://github.com/VTT-ProperTune/OpenPFC";
44+
license = lib.licenses.agpl3;
45+
platforms = lib.platforms.linux;
46+
};
47+
}

nix/heffte.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# heffte.nix
2+
{ stdenv, cmake, fftw, fftwFloat, openmpi, fetchFromGitHub }:
3+
4+
stdenv.mkDerivation {
5+
pname = "heffte";
6+
version = "2.4.1";
7+
8+
src = fetchFromGitHub {
9+
owner = "icl-utk-edu";
10+
repo = "heffte";
11+
rev = "v2.4.1";
12+
sha256 = "3qCF3nsxjjj3OOks8f4Uu1L3+budRPX1i+iwXy8hLhE=";
13+
};
14+
15+
nativeBuildInputs = [ cmake ];
16+
buildInputs = [ fftw fftwFloat openmpi ];
17+
18+
cmakeFlags = [
19+
"-DHeffte_ENABLE_FFTW=ON"
20+
"-DHeffte_ENABLE_CUDA=OFF"
21+
"-DHeffte_ENABLE_ROCM=OFF"
22+
"-DHeffte_ENABLE_ONEAPI=OFF"
23+
];
24+
}

nix/test-heffte.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# test-heffte.nix
2+
let
3+
pkgs = import <nixpkgs> {};
4+
5+
heffte = pkgs.callPackage ./pkgs/heffte.nix {
6+
cmake = pkgs.cmake;
7+
fftw = pkgs.fftw;
8+
fftwFloat = pkgs.fftwFloat;
9+
openmpi = pkgs.openmpi;
10+
fetchFromGitHub = pkgs.fetchFromGitHub;
11+
};
12+
in
13+
heffte

0 commit comments

Comments
 (0)