A posteriori Nix shell#
Warning
Very fresh paint!
So you have a non-Nix software environment that you would like to reproduce in Nix?
You can try to use third party tools such as Devbox, but generating a proper Nix Flake also seems like a decent idea.
The Nix4Science flake provides a way to generate a flake.nix from a YAML description of the desired software environments.
Imagine that you need to nixify two seperate shells. One for your C++ code built with CMake, and the other one for some analysis in python.
You can then describe the desired environment in a YAML file such as the one below:
- shell: analysis
packages:
- name: python310
version: "3.10.8"
with_packages:
- name: numpy
version: "1.24.2"
- name: matplotlib
version: "3.7.1"
- shell: dev
packages:
- name: gcc
version: "12.3.0"
- name: cmake
version: "3.24.3"
shellsets the name of the shellpackagesis a list of pairs (name,version)for some packages (
python,R, …), you can use thewith_packagesfields to add some packages (numpyandmatplotlibin the example above)
Then run mop:
nix run n4s#mop -- envs.yaml
mop will generate a flake.nix file that tries to match as best as it can the desired environments.
Notes and Warnings#
mopcalls Nixhub under the hood to retrieve the correctnixpkgscommitsyou do want to call a nix formatter on the generated
flake.nix!!for now, the
with_packagessupports fullypython, and partiallyRit might require you to edit the
flake.nixto fill up somesha256orhash