Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srid/flake-root
A `flake-parts` module for finding your way to the project root directory
https://github.com/srid/flake-root
flake-parts nix
Last synced: 4 months ago
JSON representation
A `flake-parts` module for finding your way to the project root directory
- Host: GitHub
- URL: https://github.com/srid/flake-root
- Owner: srid
- License: mit
- Created: 2022-12-17T15:48:38.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T02:53:37.000Z (6 months ago)
- Last Synced: 2024-10-11T23:49:18.376Z (4 months ago)
- Topics: flake-parts, nix
- Language: Nix
- Homepage:
- Size: 10.7 KB
- Stars: 34
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flake-root
A `flake-parts` module for finding your way to the project root directory
## Why?
Because Nix itself doesn't provide it:
- https://github.com/NixOS/nix/issues/8034
- https://github.com/NixOS/nix/issues/6241## Usage
```nix
{
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
- This module is in turn used by the following `flake-parts` modules:
- https://github.com/Platonic-Systems/mission-control
- https://github.com/srid/proc-flake## Credit
The bash script is originally based on [numtide/treefmt](https://github.com/numtide/treefmt/blob/66959743ba9e955819a16960319a09d152acff9a/module-options.nix#L98-L109).