Flake input from local git repo

I have a nix tarball on s3 so want to use fetchtarball. s3 is not a supported type for a nix flake input, so I’m trying to do something along the following lines [1]. But as the errors in the comments indicate that doesn’t work.

What would be the best way to get an input from a local repo? Maybe I’m thinking about this wrong?

[1]

{
  inputs = {
    #  error: cannot fetch input 'path:./config.nix' because it uses a relative path
    config = { type = "path"; path = "./config.nix"; };
    #  error: flake input attribute 'path' is a path while a string, Boolean, or integer is expected
    config = { type = "path"; path = ./config.nix; };
  };
  outputs = { self, config }:
      let nixpkgs = import (builtins.fetchTarball {
      url = config.url;
      sha256 = config.sha256;})
    { };
    in
  {
  };
}

Can you clarify your usecase just a bit? You mention s3 but then you are attempting to import local paths.

If it’s paths you don’t need to fetch them, you can just referent them directly, or if you are in a flake and referencing an arbitrary file path you would use builtins.path and provide a hash as an argument.

For s3, you are right that nix cannot fetch from s3 directly yet (afaik), but many s3 providers offer htttp endpoints, so your best bet would be to target that.

I’m not sure where the s3 part fits in, but if you want to use a repo on a local directory, you can set the URL to be git+file type. Something like:

inputs.mylocalrepo.url = "git+file:///path/to/local/repo";

A second option, in case the directory might move or something, is to add the path to your registry and use that as your URL instead:

$ nix registry add flake:mylocalrepo git+file:///path/to/local/repo
$ nix registry list
...
user   flake:mylocalrepo git+file:///path/to/local/repo
...
inputs.mylocalrepo.url = "flake:mylocalrepo";

I prefer the second option when using local repos as inputs, as it allows me to keep the flake agnostic to the actual location of the repo.

1 Like

The s3 part would be that I set e.g. config.url = s3://my-bucket/nixpkgs/22.11.tar.gz?region=eu-west-1

The downside of git+file:/// or any other absolute path is that it doesn’t work well for multiple users with e.g. different home directories.

What I’m after is a way to load a repository-local input wherever that repository may be located in the filesystem.

The second option I proposed should solve that though, as each user has a different registry.

If you have users user_a and user_b, they can each add their own path like so:

[user_a@system:~]$ nix registry add flake:mylocalrepo git+file:///home/user_a/path/to/repo
[user_a@system:~]$ nix registry list
...
user   flake:mylocalrepo git+file:///home/user_a/path/to/repo
...
[user_b@system:~]$ nix registry add flake:mylocalrepo git+file:///home/user_b/completely/different/path/to/repo
[user_b@system:~]$ nix registry list
...
user   flake:mylocalrepo git+file:///home/user_b/completely/different/path/to/repo
...

Then if you use the registry name as the url, it will alias to their own repos:

inputs.mylocalrepo.url = "flake:mylocalrepo";

When user_a uses the flake, inputs.mylocalrepo.url will point to git+file:///home/user_a/path/to/repo, but when user_b uses the flake, it will point to git+file:///home/user_b/completely/different/path/to/repo.