this post was submitted on 26 Jan 2024
4 points (75.0% liked)

NixOS

232 readers
1 users here now

NixOS is a Linux distribution built on top of the Nix package manager. Its declarative configuration allows reliable system upgrades via several official channels of stability and size.

This community discusses NixOS, Nix, and everything related.

founded 1 year ago
MODERATORS
 

I want to start a new project, and I want to try to handle all the reproducibility / "containerization" in nix instead of dockerfiles. I see some examples online but I think they're including more uncommon procedures and/or don't do things the "nix" way.

What's the right way to manage a simple python project? Should I just make a derivation.nix for use in nix-shell -p and have the ephemeral shell be my container? Can/should I do it with nix flakes instead? What would a simple nix flake look like that:

pulls an initial python repo from github

possibly executes whatever build instructions might be included

extends other system packages or other versions of the same python package,

has local area network access,

and GPU access

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 10 months ago

Thanks, I think I finally got it, but I think I'll need to switch to flakes if I want to be able to install say numpy==1.10.0 instead of latest (is there a way to specify which python package version should be installed in mkShell?)

Does this explanation make sense?

{ pkgs ? import  {} }:
pkgs.mkShell {
  packages = with pkgs; [
    (python310Full.withPackages 
                        (python-pkgs: with python-pkgs;
                          [numpy pandas requests]))];
  #inputsFrom = [ pkgs.python310Full ];
}

To derive this ephemeral shell...

use a package manager defaulted from nix packages: {pkgs ? import {} }:

Make an ephemeral shell with programs located in the package manager: pkgs.mkShell {

Define the set of installed packages in the ephemeral shell

 packages = with pkgs; [
    (python310Full.withPackages # Include python310 in the set of installed packages
                        (python-pkgs: with python-pkgs; # not entirely sure what's going on here, is python-pkgs a predefined arg? fails with nativeBuildInputs if this isn't here 
                          [numpy pandas requests]))]; # the pip packages to include