Skip to content

A `flake-parts` module for finding your way to the project root directory

License

Notifications You must be signed in to change notification settings

srid/flake-root

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

flake-root

A flake-parts module for finding your way to the project root directory

Why?

Because Nix itself doesn't provide it:

Usage

{
  inputs = {
    flake-root.url = "github:srid/flake-root";
    ...
  };
  outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit self; } {
      imports = [
        inputs.flake-root.flakeModule
      ];
      perSystem = { pkgs, lib, config, ... }: {
        flake-root.projectRootFile = "flake.nix";  # Not necessary, as flake.nix is the default
        devShells.default = pkgs.mkShell {
          inputsFrom = [ config.flake-root.devShell ];  # Provides $FLAKE_ROOT in dev shell
        };
      };
    };
}

Now you have access to the program that returns the absolute path to the project root via ${lib.getExe config.flake-root.package}. There is also config.flake-root.devShell which exposes a shellHook providing the $FLAKE_ROOT environment variable.

Examples

Credit

The bash script is originally based on numtide/treefmt.

About

A `flake-parts` module for finding your way to the project root directory

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages