# Turn your project into a flake

In some of the previous steps in Zero to Nix you learned about [Nix flakes][flakes] and Nix [development environments][dev-env].
Turning your own projects into flakes can be somewhat tricky, so we at [Determinate Systems][detsys] have created a tool that can help in many scenarios: [`fh`][fh], the CLI for the [FlakeHub] platform.
`fh` has a utility called [`fh init`][fh-init] that creates a `flake.nix` file based on two things:

1. The contents of your project
1. Your responses to its interactive questions

You can run `fh init` using Nix:

```shell title="Initialize your flake"
nix run "https://flakehub.com/f/DeterminateSystems/fh/*" -- init
```

This will start up an interactive builder that asks you a series of questions and then writes a `flake.nix` file into the root of your project (plus some other files if you say yes to some of those questions).
Once you've generated a new flake, you can see which outputs it has:

```shell title="Display the flake's outputs"
nix flake show
```

You should see something like this:

```text title="Flake outputs"
git+file:///path/to/fh-init-example-project
├───devShells
│   ├───aarch64-darwin
│   │   └───default: development environment 'nix-shell'
│   ├───aarch64-linux
│   │   └───default omitted (use '--all-systems' to show)
│   ├───x86_64-darwin
│   │   └───default omitted (use '--all-systems' to show)
│   └───x86_64-linux
│       └───default omitted (use '--all-systems' to show)
└───schemas: unknown
```

`fh init` supports a wide variety of [languages and tools][handlers].
If your project has a [`Cargo.toml`][cargo-toml] file in the root, for example, then `fh init` infers that it's a [Rust] project and asks if you want to add Rust dependencies to your Nix [development environment][dev-env].
If you say yes, then the generated `flake.nix` will include the `cargo` build tool plus some other Rust-specific tools.
Note that `fh init` currently only supports [`devShells`][dev-env] outputs.
That is, it only generates a development environment for you, not things like [package outputs][packages].

<Admonition
  warning
  title="The limitations of `fh init`"
  id="fh-init-limitations"
>
  Be aware that `fh init` operates on a "best-guess" basis to infer which
  languages and tools you use in your project. It's possible that it will miss
  things or make incorrect guesses. But we hope that the `flake.nix` that it
  creates for you will at least serve as a solid initial template that you can
  modify further.
</Admonition>

## Example project

We've created an example project that you can use to test out `fh init`:

```shell title="Test out fh init using the example project"
git clone https://github.com/DeterminateSystems/fh-init-example-project
cd fh-init-example-project
nix run "https://flakehub.com/f/DeterminateSystems/fh/*" -- init

# respond to the prompts

nix flake show
```

[cargo-toml]: https://doc.rust-lang.org/cargo/reference/manifest.html
[detsys]: https://determinate.systems
[dev-env]: /concepts/dev-env
[fh]: https://github.com/DeterminateSystems/fh
[fh-init]: https://github.com/determinateSystems/fh#initialize-a-new-flakenix-from-scratch
[flakehub]: /concepts/flakehub
[flakes]: /concepts/flakes
[handlers]: https://github.com/DeterminateSystems/fh/tree/main/src/cli/cmd/init/handlers
[packages]: /concepts/packages
[rust]: https://rust-lang.org