This is a small collection of flake templates for use when developing software intended to be built or distributed with Nix flakes.
Initialising a Python virtual environment managed with poetry and Nix is as simple as
nix flake init -t "github:lukebfox/nix-flake-templates#python_nixpkgs_venv"
git init && git add .
which will give you
my_project
├─flake.nix
├─flake.lock
├─pyproject.toml
├─.gitignore
└─.envrc
When developing on NixOS reuse the nixpkgs instance which built your system for your ad-hoc dev environments will skip downloading a new nixpkgs when you initialise a project, and simplifies ensuring compatibility between system drivers, libraries and applications i.e nvidia/CUDA/Pytorch.
All the templates provided by this flake leave the 'nixpkgs' flake input to be resolved by the flake registry. In the flake providing your NixOS system, configure the local flake registry to use the flake's nixpkgs pin. Also, I find using the same registry technique with my flake-templates flake helpful.
Your system flake.nix:
{
inputs.nixpkgs = "NixOS/nixpkgs/nixos-unstable";
inputs.templates = "github:lukebfox/nix-flake-templates";
...
}
Your system configuration.nix
{
nix.registry = {
# Local flakes can use the system's nixpkgs.
nixpkgs.flake = inputs.nixpkgs;
# Can run anywhere: $ nix flake init -t "templates#<template_name>"
templates.flake = inputs.templates;
};
};
$ nix flake show "github:lukebfox/nix-flake-templates"
github:lukebfox/nix-configs/<commit-hash>
└───templates
├───python_nixpkgs_venv: template: A simple Python virtualenv, using nixpkgs packages.
└───python_poetry_venv: template: A python virtual environment, managed by Poetry.
If you want more like this feel free to open up an issue or a PR.