Why is ~/.config/nixpkgs/config.nix being ignored?

I’m very new to nix. I have a directory that contains a simple shell.nix file that specifies a number of build dependencies for a software project. One of the annoying quirks of this software project is that it depends on python2. When I run nix-shell in this directory, I am given this error message:

error: Package ‘python-’ in /nix/store/5hwz775f3grzikafj1sbwx4lqkjwqswb-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:335 is marked as insecure, refusing to evaluate.

       Known issues:
        - Python 2.7 has reached its end of life after 2020-01-01. See https://www.python.org/doc/sunset-python-2/.

       You can install it anyway by allowing this package, using the
       following methods:

       a) To temporarily allow all insecure packages, you can use an environment
          variable for a single invocation of the nix tools:

            $ export NIXPKGS_ALLOW_INSECURE=1

          Note: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       b) for `nixos-rebuild` you can add ‘python-’ to
          `nixpkgs.config.permittedInsecurePackages` in the configuration.nix,
          like so:

              nixpkgs.config.permittedInsecurePackages = [

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
          ‘python-’ to `permittedInsecurePackages` in
          ~/.config/nixpkgs/config.nix, like so:

              permittedInsecurePackages = [
(use '--show-trace' to show detailed location information)

I created the ~/.config/nixpks/config.nix file and inserted the suggested content, but this error message is still printed each time I run nix-shell. I also tried running NIXPKGS_ALLOW_INSECURE=1 nix-shell and that does run successfully, but I am curious why the config file method isn’t working.

Any ideas?

The pkgs in your shell.nix is likely a different instance from your global pkgs at eval time.

One way to get what you want is to set config.permittedInsecurePackages on import of <nixpkgs> in you shell.nix

  pkgs ? (import <nixpkgs> {
    config.permittedInsecurePackages  = [ ... ];

pkgs.mkShell { ... }