NIX: "error: cannot auto-call a function that has an argument without a default value" when calling a script from different folder than its root

Viewed 22

I'm very new to NIX so maybe this is something simple but I haven't managed to find a fix yet.

I have this python script (resource.py) that I have nixified. When I run the script from within it's own directory (./resource.py), everything runs fine. Nix gets all the packages needed and runs the script without any errors. But when I try to call the script from a different folder, then I get this error:

error: cannot auto-call a function that has an argument without a default value ('pkgs')

What I am aiming for is being able to call the script directly from any folder, ie call "/home/.../resource.py" from anywhere.

Here is my default.nix file:

{ pkgs }:
pkgs.poetry2nix.mkPoetryApplication {
  projectDir = ./.;
}

my shell.nix:

 { 
  pkgs ? (import (builtins.fetchTarball {
            # Release '22.05' is a tag which points to ce6aa13369b667ac2542593170993504932eb836
            url = "https://github.com/nixos/nixpkgs/tarball/22.05";
            # This hash is git-agnostic so nix can detect if the git-tag changes
            sha256 = "0d643wp3l77hv2pmg2fi7vyxn4rwy0iyr8djcw1h5x72315ck9ik";
          }) {}),

  allthepoetrystuff ? import ./default.nix { inherit pkgs; } 
}:

pkgs.mkShell {
  buildInputs = [
    pkgs.python3
    pkgs.poetry
    allthepoetrystuff   # This assumes lockfile is present
  ];
}

and the main script (resource.py):

#! /usr/bin/env nix-shell
#! nix-shell --pure -i "python3"

import resourcehandler

if __name__ == "__main__":
    resourcehandler.ResourceHandler()

Any help/tips/suggestions are highly appreciated!

0 Answers
Related