Skip to content

Commit a09f1f8

Browse files
committed
add template flake for use with nix flake init
1 parent d30d9c4 commit a09f1f8

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ Nix package manager together with NixOS-QChem (commit <10 digits of SHA-1>) [1].
2727

2828
## Usage
2929

30+
### Template Flake
31+
We provide a template [Nix Flake](https://nixos.wiki/wiki/Flakes) ready for use and with reasonable defaults and easy customisability.
32+
Get the template:
33+
34+
```bash
35+
nix flake init -t github:nix-qchem/nixos-qchem
36+
```
37+
38+
In the so obtained `flake.nix` look for `EDITME` tokens to find places for common modifications such as:
39+
40+
* CPU architecture specific optimisations
41+
* Enabling or disabling certain unfree packages
42+
* Definition of a custom Python environment with packages you require
43+
* ...
44+
45+
A useful directory layout for a project may look like this:
46+
47+
```
48+
PROJECT/
49+
├── calculations/
50+
├── .envrc
51+
└── nix
52+
├── flake.lock
53+
└── flake.nix
54+
```
55+
56+
With `.envrc` containing `use flake ./nix`.
57+
If you are using [DirEnv](https://direnv.net/) you get your software environment for your project by merely entering the `PROJECT` directory.
58+
59+
3060
### Overlay
3161
The repository comes as a nixpkgs overlay (see [Nixpkgs manual](https://nixos.org/nixpkgs/manual/#chap-overlays) for how to install an overlay).
3262
The contents of the overlay will be placed in an attribute set under nixpkgs (default `qchem`). The original, but overridden nixpkgs will be placed in `qchem.pkgs`. This allows for composition of the overlay with different variants.

flake.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,20 @@
8383
pythonQchem = import ./pythonPackages.nix pkgs.config.qchem-config.prefix pkgs.config.qchem-config pkgs nixpkgs;
8484
default = self.overlays.qchem;
8585
};
86+
87+
templates.default = {
88+
path = ./template;
89+
description = "NixOS-QChem template flake with reasonable defaults and editable configuration";
90+
welcomeText = ''
91+
Welcome to the NixOS-QChem template flake with optimised packages for computational chemistry!
92+
93+
If you use this flake and/or packages from NixOS-QChem, please cite https://doi.org/10.1002/qua.26872 in your work!
94+
95+
The flake aims for reasonable defaults but can be customised to your needs.
96+
Look for "EDITME" tokens in the flake.nix to find places where you can customise the flake,
97+
e.g. by adding or removing unfree packages, changing CPU architecture specific optimisations,
98+
or constructing a Python environment suiting your requirements.
99+
'';
100+
};
86101
};
87102
}

template/flake.nix

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
description = "A flake for computational chemistry, based on NixOS-QChem";
3+
4+
inputs = {
5+
#qchem.url = "github:nix-qchem/nixos-qchem";
6+
qchem.url = "../";
7+
};
8+
9+
nixConfig = {
10+
extra-substituters = [ "https://nix-qchem.cachix.org" ];
11+
12+
allow-import-from-derivation = "true";
13+
};
14+
15+
outputs = { self, qchem }:
16+
let
17+
# EDITME
18+
# Overlay to enable Gaussian support. Uncomment below in `pkgs` to enable.
19+
enableGaussian = final: prev: {
20+
qchem = prev.qchem // {
21+
gaussian = prev.callPackage "${qchem}/pkgs/apps/gaussian" {
22+
# Set a version
23+
version = "16c02";
24+
25+
# Either set optpath
26+
optpath = "/opt";
27+
# or g16Root and g16Dir
28+
#g16Root = "/cluster/apps/gaussian/g16_c02";
29+
#g16Dir = "/cluster/apps/gaussian/g16_c02/g16";
30+
};
31+
};
32+
};
33+
34+
# EDITME
35+
# Disables unfree packages by default to avoid non-building packages, that
36+
# use unfree ones as dependencies, e.g. Pysisyphus or SHARC.
37+
# Comment out lines to enable the respective package.
38+
filterUnfree = final: prev: {
39+
qchem = prev.qchem // {
40+
turbomole = null;
41+
cefine = null;
42+
cfour = null;
43+
gamess-us = null;
44+
gaussview = null;
45+
mrcc = null;
46+
orca = null;
47+
vmd = null;
48+
mesa-qc = null;
49+
mcdth = null;
50+
nixGL = null;
51+
};
52+
};
53+
54+
# EDITME
55+
# Python environment for computational chemistry. Add or remove packages
56+
# as needed.
57+
pyCompEnv = pkgs.qchem.python3.withPackages (ps: with ps; [
58+
jupyterlab
59+
numpy
60+
scipy
61+
scikit-learn
62+
ase
63+
pyscf
64+
psi4
65+
]);
66+
67+
system = "x86_64-linux";
68+
69+
pkgs = import qchem.inputs.nixpkgs {
70+
inherit system;
71+
72+
# EDITME
73+
overlays = [
74+
qchem.overlays.default
75+
filterUnfree
76+
# enableGaussian # Uncomment to enable Gaussian support
77+
];
78+
79+
config = {
80+
allowUnfree = true;
81+
82+
# EDITME
83+
qchem-config = {
84+
# Set to a GCC architecture to optimise packages for.
85+
# See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html for options.
86+
optArch = "haswell";
87+
88+
# Set to an installation path of Gaussian/MatLab outside the Nix
89+
# store if you have one. Should have a directory structure like this:
90+
# "${optpath}/gaussian/g16/"
91+
# "${optpath}/matlab-R2024/"
92+
#optpath = "/opt";
93+
94+
# Set and uncomment if you have a MolPro license key.
95+
#licMolpro = "XXXX-XXXX-XXXX-XXXX";
96+
97+
# Set and uncomment if you have a Q-Chem license key file.
98+
#licQChem = "/path/to/qchem.lic";
99+
100+
# Uncomment if you have a server from which non-redistributable
101+
# software can be downloaded
102+
#srcurl = "http://myserver/nix-src/";
103+
};
104+
};
105+
};
106+
in
107+
{
108+
# EDITME
109+
# A shell to obtain via `nix develop` or DirEnv, useful to run
110+
# programs interactively. Contains a Python environment for computational
111+
# chemistry. See above. Add/remove packages as needed.
112+
devShells."${system}".default = with pkgs; mkShell {
113+
buildInputs = [
114+
pyCompEnv
115+
pkgs.qchem.xtb
116+
];
117+
};
118+
119+
packages."${system}" = with pkgs.lib.attrsets;
120+
filterAttrs (_: val: isDerivation val)
121+
(pkgs.qchem // {
122+
inherit (pkgs) lammps lammps-mpi tachyon;
123+
});
124+
};
125+
}

0 commit comments

Comments
 (0)