getting flake to work

This commit is contained in:
Bart Koolen 2025-10-19 14:26:49 +02:00
parent fec2a451c6
commit d65f3e119f
2 changed files with 51 additions and 21 deletions

8
flake.lock generated
View file

@ -2,16 +2,16 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1760580664, "lastModified": 1760524057,
"narHash": "sha256-/YdfibIrnqXAL8p5kqCU345mzpHoOtuVIkMiI2pF4Dc=", "narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "98ff3f9af2684f6136c24beef08f5e2033fc5389", "rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-25.05", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }

View file

@ -1,21 +1,51 @@
{ {
description = "Python dev environment using Nix"; description = "A development shell for Python 3.12 with Pandas and Requests.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; # Define the inputs (dependencies) for the flake
inputs = {
# Pin nixpkgs to a specific channel (e.g., nixos-unstable) for a reproducible environment
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: let # Define the outputs (what the flake provides)
system = "x86_64-linux"; outputs = { self, nixpkgs, ... }@inputs:
pkgs = import nixpkgs { inherit system; }; let
in { # Define the systems this flake supports
devShells.${system}.default = pkgs.mkShell { supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
# Create a function that maps the supported systems to the nixpkgs instance
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Get the packages set for all systems
pkgs = forAllSystems (system: import nixpkgs { inherit system; });
in
{
# Define the development shells
devShells = forAllSystems (system: {
default = pkgs.${system}.mkShell {
name = "python-312-dev-shell";
# 1. Select the specific Python interpreter (Python 3.12)
# 2. Use .withPackages to create an environment that includes the specified libraries
packages = [ packages = [
(pkgs.python312.withPackages (ps: with ps; [ (pkgs.${system}.python312.withPackages (python-pkgs: with python-pkgs; [
pip # Python libraries
virtualenv pandas
black requests
pytest
# Optional: Add other helpful dev tools outside of the python-pkgs set if needed
# (e.g., git, pre-commit, bash-completion)
])) ]))
]; ];
# Optional: Define environment variables for the shell
shellHook = ''
echo "🐍 Entering Python 3.12 development environment."
echo " (Pandas and Requests are available)"
python --version
'';
}; };
});
}; };
} }