How to reference src directory in nix?

I’m trying to write a simple nix derivation but I can’t work out how to reference the directory that fetchFromGithub to:

with import <nixpkgs> {}; stdenv.mkDerivation {
  name = "nvchad";

  src = fetchFromGitHub {
    owner = "NvChad";
    repo = "NvChad";
    rev = "v1.0";
    sha256 = "08p9y19z6cfxsilljypp0bd74mxhi60s0vk202js6i1v9ml0rqsw";

  buildInputs = [ neovim ];

  buildPhase = ''
    export XDG_CONFIG_HOME= %=========SRC_DIRECTORY_FROM_ABOVE==============%
    nvim +PackerSync

does anybody know how I can do this?

not sure what you’re trying to do but

the unarchived source tarball is ./path/to or path/to if i remember correctly

the output derivation directory is $out/path/to

I’m not 100% confident in this, but my understanding:

  • $PWD should be the temporary build directory, which typically has the source copied into it already.
  • $src is a valid reference to the source (I think in the store)–but this isn’t a mutable copy and it isn’t the one that’ll have patches applied and such. You can definitely find packages using it, but it might be a mistake and can be a footgun. (For example, using it can cause people trouble with overriding in some additional patch/substitution.)

it’s which determines the unpacked directory name.

$NIX_BUILD_TOP/${}/ for the full path.

Related PR: [staging] fetchFromGitHub: name source with content intristic to the value by jonringer · Pull Request #153386 · NixOS/nixpkgs · GitHub