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

python # predefined undocumented variables? How/where to find those? #1086

Open
InLaw opened this issue Dec 29, 2024 · 1 comment
Open

python # predefined undocumented variables? How/where to find those? #1086

InLaw opened this issue Dec 29, 2024 · 1 comment

Comments

@InLaw
Copy link
Contributor

InLaw commented Dec 29, 2024

falke.nix

{
  # This example flake.nix is pretty generic and the same for all
  # examples, except when they define devShells or extra packages.
  description = "d2n Dream2nix example flake";

  # We import the latest commit of dream2nix main branch and instruct nix to
  # re-use the nixpkgs revision referenced by dream2nix.
  # This is what we test in CI with, but you can generally refer to any
  # recent nixpkgs commit here.
  inputs = {
    dream2nix.url = "github:nix-community/dream2nix";
    nixpkgs.follows = "dream2nix/nixpkgs";
  };

  outputs = {
    self,
    dream2nix,
    nixpkgs,
  }: 
  let
    # A helper that helps us define the attributes below for
    # all systems we care about.
    eachSystem = nixpkgs.lib.genAttrs [
      "aarch64-darwin"
      "aarch64-linux"
      "x86_64-darwin"
      "x86_64-linux"
    ];

    pkgs = import nixpkgs {
        system = "x86_64-linux";
      };

  in 
  {
    packages = eachSystem (system: {
      # For each system, we define our default package
      # by passing in our desired nixpkgs revision plus
      # any dream2nix modules needed by it.
      default = dream2nix.lib.evalModules {
        packageSets.nixpkgs = nixpkgs.legacyPackages.${system};

        modules = [
          # Import our actual package definiton as a dream2nix module from ./default.nix
          ./default.nix 
          {
            # Aid dream2nix to find the project root. This setup should also works for mono
            # repos. If you only have a single project, the defaults should be good enough.
            paths.projectRoot = ./.;
            # can be changed to ".git" or "flake.nix" to get rid of .project-root
            paths.projectRootFile = "flake.nix";
            paths.package = ./.;
            }
        ];
      };

    });

    devShells = eachSystem (system: {
      default = nixpkgs.legacyPackages.${system}.mkShell {
        # inherit from the dream2nix generated dev shell
        inputsFrom = [self.packages.${system}.default.devShell];
        # add extra packages
        packages = ( with nixpkgs.legacyPackages.${system} ; [
          python.pkgs.ipython
        ] ) ;
      };

    });
  };


}

python[.pkgs.ipython] is not defined before? The code should fail, no?
The code works and python is

  • error: Package ‘python-2.7.18.8’ in /nix/store/jyw83fn5spbdgzdj110620dm0zl43q2y-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:341 is marked as insecure, refusing to evaluate.

default.nix

{
  config,
  lib,
  dream2nix,
  ...
}: 
let
  
in
{
  imports = [
    dream2nix.modules.dream2nix.WIP-python-pdm
  ];

  mkDerivation = {
    src = lib.cleanSourceWith { 
      src = lib.cleanSource ./.;
      filter = name: type:
        !(builtins.any (x: x) [
          (lib.hasSuffix ".nix" name)
          (lib.hasPrefix "." (builtins.baseNameOf name))
          (lib.hasSuffix "flake.lock" name)
        ]);
    };

  };
  pdm.lockfile = ./pdm.lock;
  pdm.pyproject = ./pyproject.toml; 

  buildPythonPackage = {
    pythonImportsCheck = [
      "my_tool"
    ];
  };
}

Where is python 2.7 defined?
How to show all other already defined variables?

@a-gavin
Copy link

a-gavin commented Feb 1, 2025

While I can't necessarily speak to this specific project configuration, I would like to highlight that python and python3 are different nixpkgs. The python package is Python 2, which may be related to the cause of your issue.

Possibly try changing this to use python3.11-ipython or python3.12-ipython instead?

        packages = ( with nixpkgs.legacyPackages.${system} ; [
          python.pkgs.ipython
        ] ) ;

I stumbled across this issue through Google (also saw the Package ‘python-2.7.18.8’ ... is marked as insecure, refusing to evaluate. error). In my case, I was trying to start a Nix shell using the python nixpkg, whereas I needed the python3 nixpkg instead.

# Shows 'Package ‘python-2.7.18.8’ ... is marked as insecure, refusing to evaluate.' error
nix-shell -p python

# Works
nix-shell -p python3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants