scripts

lib.scripts.loadScript

Load a PEP-723 metadata script from file path or string.

structured function argument

: name

: Function argument

script

: Function argument

::: {.example #function-library-example-lib.scripts.loadScript}

lib.scripts.loadScript usage example

# loadScript { script = ./with-inline-metadata.py; }
{
  name = "with-inline-metadata";
  metadata = { ... }; # Contains dependencies and requires-python
  renderWithPackages = { python }: ...; # renderWithPackages with loaded script pre-applied
}

:::

lib.scripts.renderWithPackages

Render a loaded PEP-723 script as a string with a shebang line pointing to a wrapped Nix store interpreter.

structured function argument

: script

: Script loaded using loadScript

python

: Nixpkgs Python interpreter

environ

: Nixpkgs Python package set Python extras (optional-dependencies) to enable. PEP-508 environment

::: {.example #function-library-example-lib.scripts.renderWithPackages}

lib.scripts.renderWithPackages usage example

# Using renderWithPackages directly
let
  script = loadScript { script = ./with-inline-metadata.py; };
in pkgs.writeScript script.name (renderWithPackages { inherit script; python = pkgs.python3; })

# Using script render function
let
  script = loadScript { script = ./with-inline-metadata.py; };
in pkgs.writeScript script.name (script.render { python = pkgs.python3; })

:::