Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch nix recipe to flake #992

Merged
merged 17 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: nix
name: Test Nix
on: [push, pull_request]
jobs:
test:
Expand All @@ -11,12 +11,23 @@ jobs:
run:
working-directory: ./
steps:
- uses: actions/checkout@v2.3.4
- uses: cachix/install-nix-action@v14.1
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable
name: fipy
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
extraPullNames: nix-community
- run: nix-shell --pure --command "python setup.py test"
- run: nix-shell --pure --command "py.test --nbval --sanitize-with examples/sanitize.cfg examples/index.ipynb"
- run: echo "UID=${UID}" >> $GITHUB_ENV
- uses: actions/cache/restore@v3
with:
path: /run/user/${{ env.UID }}/http_cache.sqlite
key: ${{ runner.os}}-http_cache.sqlite
- run: nix develop --command bash -c "python setup.py test"
- run: nix develop --command bash -c "py.test --nbval --sanitize-with examples/sanitize.cfg examples/index.ipynb"
- uses: actions/cache/save@v3
if: always()
with:
path: /run/user/${{ env.UID }}/http_cache.sqlite
key: ${{ runner.os}}-http_cache.sqlite

52 changes: 7 additions & 45 deletions docs/source/NIX-README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,26 @@ Nix Installation
:term:`FiPy` now has a `Nix`_ expression for installing :term:`FiPy`
using `Nix`_. `Nix`_ is a powerful package manager for Linux and other
Unix systems that makes package management reliable and
reproducible. The recipe works on both Linux and Mac OS X.

Getting Started with Nix
------------------------

There are a number of tutorials on getting started with `Nix`_. The
page that I used when getting started is on the Blog of the HPC team
of GRICAD,

https://gricad.github.io/calcul/nix/tuto/2017/07/04/nix-tutorial.html

I also made my own notes,

https://github.com/wd15/nixes/blob/master/NIX-NOTES.md

which are a succinct steps that I use when setting up a new system with
Nix.
reproducible. The recipe works on both Linux and Mac OS X. Go to
`nix.dev`_ to get started with Nix.

Installing
----------

Once you have a working Nix installation use::

$ nix-shell --pure
$ nix develop

in the base :term:`FiPy` directory to install :term:`FiPy` with Python
3 by default. Modify the `shell.nix` file to use another version of
Python. ``nix-shell`` drops the user into a shell with a working
3 by default. ``nix develop`` drops the user into a shell with a working
version of :term:`FiPy`. To test your installation use::

$ nix-shell --pure --command "python setup.py test"
$ nix develop --command bash -c "python setup.py test"

.. note::

:term:`Trilinos` is currently not available as part of the Nix
:term:`FiPy` installation.


Additional Packages
-------------------

To install additional packages available from Nixpkgs_ include them in
the `nativeBuildInputs` list in `shell.nix`.


Using Pip
---------

Packages unavailable from Nix can be installed using :term:`Pip`. In
this case, the installation has been set up so that the Nix shell
knows about a ``.local`` directory in the base :term:`FiPy` directory
used by :term:`Pip` for installation. So, for example, to install the
``toolz`` package from within the Nix shell use::

$ python -m pip install --user toolz

The ``.local`` directory will persist after the Nix shell has been
closed.
The SciPy solvers are the only availabe solvers currently.
tkphd marked this conversation as resolved.
Show resolved Hide resolved

.. _Nix: https://nixos.org/nix/
.. _Nixpkgs: https://nixos.org/nixpkgs/
.. _nix.dev: https://nix.dev
25 changes: 17 additions & 8 deletions examples/index.ipynb

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion examples/sanitize.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[regex]
[regex1]
regex: <Figure size [0-9]{3,4}x[0-9]{3,4}(?:.[0-9])? with [0-9]{1,3} Axes>
replace: <Figure size>

[regex2]
regex: <fipy.viewers.matplotlibViewer.matplotlib2DGridViewer.Matplotlib2DGridViewer at .{1,}>
replace:
61 changes: 61 additions & 0 deletions flake.lock

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

47 changes: 47 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
description = "Python environment for fipy";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
tkphd marked this conversation as resolved.
Show resolved Hide resolved
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils}: (utils.lib.eachSystem ["x86_64-linux" "x86_64-darwin" ] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pypkgs = pkgs.python310Packages;

env = (pypkgs.fipy.overridePythonAttrs (old: rec {

src = pkgs.lib.cleanSource ./.;

nativeBuildInputs = with pypkgs; [
pip
pkgs.openssh
nbval
ipython
ipykernel
jupyterlab
traitlets
notebook
] ++ propagatedBuildInputs;

propagatedBuildInputs = old.propagatedBuildInputs;

postShellHook = ''
SOURCE_DATE_EPOCH=$(date +%s)
export PYTHONUSERBASE=$PWD/.local
export USER_SITE=`python -c "import site; print(site.USER_SITE)"`
export PYTHONPATH=$PYTHONPATH:$USER_SITE:$(pwd)
export PATH=$PATH:$PYTHONUSERBASE/bin

export OMPI_MCA_plm_rsh_agent=${pkgs.openssh}/bin/ssh

'';
}));
in
rec {
devShells.default = env;
}
));
}
61 changes: 0 additions & 61 deletions shell.nix

This file was deleted.