How to fetch a file whose name starts with a period?

How to fetch a file whose name starts with a period?

Here is my situation.
I want to fetch .gdbinit in GitHub - cyrus-and/gdb-dashboard: Modular visual interface for GDB in Python and place (symlink) it into my home directory by home-manager. I am currently stuck in fetching the .gdbinit.

Here is what I have done.
I have tried pkgs.fetchurl and builtins.fetchurl, and both of them throw error like this.

The path name '.gdbinit' is invalid: it is illegal to start the name with a period. Path names are alphanumeric and can include the symbols +-._?= and must not begin with a period. Note: If '.gdbinit' is a source file and you cannot rename it on disk, builtins.path { name = ... } can be used to give it an alternative name.

So I tried builtins.path like this.

builtins.path {
  path = builtins.fetchurl "https://raw.githubusercontent.com/cyrus-and/gdb-dashboard/master/.gdbinit";                                                             
  name = "gdbinit";                                                                                 
};

The same error.

I suspect builtins.fetchurl triggers the error, but I have no idea how to solve it.

OK, I find a compromise solution.

I fetch the whole github repo, then symlink the .gdbinit in the repo into my home directory. The code like this.

let
  gdb-dashboard-src = pkgs.fetchFromGitHub {...};
in
{
  home.file.gdbinit = {
    source = "${gdb-dashboard-src.outPath}/.gdbinit";
    target = ".gdbinit";
  };
}

Solved!

According to nixpkgs/pkgs/build-support/fetchurl/default.nix, pkgs.fetchurl {} has an arguement called name. This name is used as the file name. So the fetchurl is like this.

pkgs.fetchurl {
  url = "...";
  sha256 = "...";
  name = "name_not_start_with_period";
};
2 Likes