Setup

Up a Level

The history[1] of how I've gotten to this point is winding and many decades long. But the end result is that I use two major tools for setting up my projects in a consistent manner: Direnv[2] and Nix Flakes[3].

1: ../history/

2: https://direnv.net/

3: https://wiki.nixos.org/wiki/Flakes

The main reason is history. I have projects that are twenty years old but they are based on languages that never stop changing. In some cases, such as the highly fluid NPM ecosystem, being off by a month can require days of refactoring to handle the current state of deprecations, shifting packages, and trying to get everything playing with each other again.

Nix Flakes help keep me “pinned” to specific versions and reduces the amount of refactoring I have to do to jump into a project, do a few changes, and finish up.

Flakes

Since flakes give me the consistency I need, that means many of my more recent projects have a `flake.nix` and a `flake.lock` associated with them. These will have a `devShell` which makes sure the programs to use the project are available.

I try to avoid using the “unstable” branch for NixOS but sometimes that isn't avoidable.

mfgames-project-setup

To simplify my common project layout, I created a setup flake[4] that does some initial configuration including setting up commit linting (since I useconventional commits[5]), formatting, and set up some of the boilerplate files.

4: //mfgames.com/mfgames-project-setup-flake/

5: //d.moonfire.us/tags/conventional-commits/

I'm pretty proud of that one, since it basically does 90% of my setup when starting a new project. There is also a second setup flake that sets up my writing projects[6] including getting the right tools installed.

6: //mfgames.com/mfgames-writing-setup-flake/

Direnv

To make it easier to get into the environment set up above, I use `direnv`. My shell is set up to automatically include this, and it sets up paths.

The `use flake` command above will automatically enter the environment configured by `flake.nix` and makes sure I have access to all the tools I need for a given project.

Environment

There are two places I set up environment variables.

For persisted ones, I put them into the `.envrc` file which is checked into the code. This is used by projects like Fiss to set the local cache file to the one inside the repository and to use the project-local configuration instead of using (and possibly corrupting) my day-to-day one.

For ones not checked in, I use `.env` to set those variables. This is where I put things like AWS authentication or Forgejo tokens. My Justfile[7] is set up to avoid removing those when I do a `just clean` and it also loads them using `set dotenv-load`.

7: ../just/

Footer

Below are various useful links within this site and to related sites (not all have been converted over to Gemini).

Now

Contact

Biography

Bibliography

Support

Fiction

Fedran

Coding

The Moonfires

Categories

Tags

Privacy

Colophon

License

Mailing List

https://d.moonfire.us/garden/project-layout/setup/