|
|
To "nixify" a project, it only needs a `flake.nix` file at its root. To create one, you can use the `nix flake new` command. |
|
To build a nix project, you can then use `nix build` which will find the `flake.nix` at the root of the project and build it. Unfortunately, by default mac is not supported. |
|
You can also launch a shell that will act as a development environment by running `nix develop -i`. Unfortunately, this won't work on mac by default as well. |
|
If you are on mac, modify the flake file and replace `linux` with `darwin` and run `nix build` again. You should see two new files: a lock file and a result file symlinking to the built artifacts. |
|
In the folder symlinked by the `result` file you can find binaries and outputs produced by the build of the `hello` package. |
|
Thix `nix flake show` command shows you what is encoded by the `flake.nix` file. |
|
|
|
A .nix file is written using the nix language (more on that later). |
|
We obtain the `hello` package from [nixpkgs](https://github.com/NixOS/nixpkgs), the place for all softwares that were packaged with nix. Note that `packages` is a list of `packages` we want to package, and it is a special keyword recognized by `nix` (so you can write `nix build#hello`). For this reason, `nixpkgs` had to use a different keyword called `legacyPackages`. |
|
the `defaultPackage` points to what `nix build` will build by default. It is a deprecated keyword, which is still used by the nix CLI for some reason. Don't worry too much about the content of our `flake.nix` for now, you'll have to learn a bit more about the nix language before we go back to that. |
|
|
|
The `flake.lock` file is created when you build for the first time. It is then used to track the hash of each dependencies you listed, so that they do not change under you in the future. |
|