Using NixOS module from shell.nix without additional imports

I’m taking my first steps with Nix/NixOS, setting it up on a Jetson AGX SBC with jetpack-nixos. The base set-up is working fine: I have a bootable OS with a configuration.nix that lists some essential services (ssh, tailscale, etc) and packages (git, screen, ripgrep, etc), configures users, etc.

I now want to use this system for more traditional development, so I figured that it would be clean to have a shell.nix in my project’s workdir that sets up a FHS env with tools and libraries I need to be available at more traditional locations (because I’m using precompiled binaries, and software that expects libraries to be easily discoverable). This includes packages from jetpack-nixos, however, where in configuration.nix I could just do fetchTarball "http://...", in shell.nix I seem to need to inherit (pkgs) bunch of stuff for these imports to work, or nix-shell errors with e.g.

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'Julia-shell-env'
         whose name attribute is located at /nix/store/c1nvlh9lqqvk9syr7pdjq3q7g5akwv06-nixos-23.11pre-git/nixos/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'shellHook' of derivation 'Julia-shell-env'

         at /nix/store/c1nvlh9lqqvk9syr7pdjq3q7g5akwv06-nixos-23.11pre-git/nixos/pkgs/build-support/build-fhsenv-bubblewrap/default.nix:231:7:

          230|     env = runCommandLocal "${name}-shell-env" {
          231|       shellHook = bwrapCmd {};
             |       ^
          232|     } ''

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: function 'anonymous lambda' called without required argument 'fetchurl'

       at /nix/store/nszwggq88davccbn18py5j30hnmzhm7q-source/default.nix:1:1:

            1| { callPackage
             | ^
            2| , callPackages

Working version of shell.nix:

{ pkgs ? import <nixpkgs> {} }:

let
  jetpack = import (builtins.fetchTarball "https://github.com/anduril/jetpack-nixos/archive/master.tar.gz") {
    inherit (pkgs) pkgs stdenv lib fetchurl writeShellApplication runtimeShell stdenvNoCC runCommand callPackage callPackages python3 bzip2_1_1 dtc dpkg;
  };

  fhs = pkgs.buildFHSUserEnv {
    name = "Julia";
    targetPkgs = pkgs: with pkgs; [
      glibc
      stdenv.cc.cc

      jetpack.l4t-cuda
      # ...
    ];
    runScript = "zsh";
  };
in fhs.env

I feel like I’m doing something wrong, or at least un-idiomatic here, so any suggestions are appreciated!

❯ nix-info -m
 - system: `"aarch64-linux"`
 - host os: `Linux 5.10.104, NixOS, 23.11 (Tapir), 23.11pre-git`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

You probably just need to use pkgs.callPackage instead of import. Then you shouldn’t need to manually provide all those arguments (still need to give it an empty {})

For terminology’s sake, that’s not a NixOS module. The default.nix file that you’re importing is not the same as the nixos module’s default.nix file. The former is just a package expression that you can use callPackage on to import. The latter is a NixOS module that provides NixOS options and includes configuration of other options.

Thanks, works perfectly!