From c3337158193c5d82e006ab64cbfff41cb363af95 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:06:57 -0400 Subject: [PATCH] fix(blog/nix-shells): typos, grammar, capitalization, etc (#26) --- content/nix-shells.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/content/nix-shells.md b/content/nix-shells.md index e7babb6..a4af514 100644 --- a/content/nix-shells.md +++ b/content/nix-shells.md @@ -8,7 +8,7 @@ tags: ## Introduction -Handling dependencies is hard to say the least. Issue after issue of missing and confilicting dependencies. And no good way to fix this util ~~docker~~ Nix came along. +Handling dependencies is hard to say the least. Issue after issue of missing and conflicting dependencies. And no good way to fix this util ~~Docker~~ Nix came along. ## Getting started @@ -22,9 +22,9 @@ First we are going to create a basic file tree, such that you can understand how └── flake.nix ``` -At first when seeing this tree you may think why are we polluting our root directory with all these files. But in this is a good way to help us write less nix code. +At first when seeing this tree you may think why are we polluting our root directory with all these files. But in this is a good way to help us write less Nix! -Now we are going to create a `flake.nix` file. This is pretty agnostic when it comes to what language your project is in by comparision to other files later on. +Now we are going to create a `flake.nix` file. This is pretty agnostic when it comes to what language your project is in by comparison to other files later on. ```nix { @@ -70,7 +70,7 @@ If you were lucky enough to have read my last blog post on [experimenting with n Now we have something more useable for our `flake.nix` file we can now start making our `default.nix` file and `shell.nix` files. -We are going to start with the `default.nix` file for a basic rust project. We start with the `default.nix` file to identify the dependencies of our project, this is perticularly easy to do with nix since the build system is isolated. +We are going to start with the `default.nix` file for a basic Rust project. We start with the `default.nix` file to identify the dependencies of our project, which is particularly easy to do with Nix since the build system is isolated. ```nix { @@ -85,12 +85,12 @@ rustPlatform.buildRustPackage { pname = "kittysay"; # The name of the package version = "0.5.2"; # The version of the package - # you can use lib here to make a more accurate source here + # You can use lib here to make a more accurate source src = ./.; # The source of the package # The lock file of the package, this can be done in other ways - # like cargoHash, we are not doing it in this case beacuse this - # is much simplier, especially if we have access to the lock file + # like cargoHash, we are not doing it in this case because this + # is much simpler, especially if we have access to the lock file # in our source tree cargoLock.lockFile = ./Cargo.lock; @@ -114,9 +114,9 @@ rustPlatform.buildRustPackage { } ``` -You may have noticed `buildInputs` and `nativeBuildInputs` these are the dependencies of the project. At a basic level `buildInputs` are the dependencies that are needed at runtime whilst `nativeBuildInputs` are the dependencies that are only needed during the build process. +You may have noticed `buildInputs` and `nativeBuildInputs`, which contain the dependencies of the project. At a basic level `buildInputs` are the dependencies that are needed at runtime whilst `nativeBuildInputs` are the dependencies that are only needed during the build process. -These dependencies can be reused in our `shell.nix` file. We can do this a little like so: +These dependencies can be reused in our `shell.nix` file. We can do this like so: ```nix { @@ -130,7 +130,7 @@ let in mainPkg.overrideAttrs (oa: { nativeBuildInputs = [ - # Additional rust tooling + # Additional Rust tooling clippy rustfmt rust-analyzer @@ -138,11 +138,11 @@ mainPkg.overrideAttrs (oa: { }) ``` -In this example we are adding additional rust tooling to our shell. This is beacuse those inputs are not there in our dependencies that we have defined in our `default.nix` file. +In this example we are adding additional Rust tooling to our shell. This is because those inputs are not there in our dependencies that we have defined in our `default.nix` file. ## But what if I don't want to have `default.nix` file? -Lucky for you nix still has a solution for this `pkgs.mkShell` or `pkgs.mkShellNoCC`. Your first question after seeing these is likely what is the difference between the two. The difference is that `mkShell` includes a c compiler in the shell environment, whilst `mkShellNoCC` does not. +Nix still has a solution for this — `pkgs.mkShell` or `pkgs.mkShellNoCC`. Your first question after seeing these is likely how are these two different? The difference is that `mkShell` includes a C compiler in the shell environment, whilst `mkShellNoCC` does not. ```nix { @@ -159,6 +159,7 @@ mkShell { ]; } ``` + But what if you also need all the dependencies of another program? I've personally never needed this but you can do it like so: ```nix @@ -177,15 +178,14 @@ Now you have a shell with all the dependencies of `rust-analyzer` and any other ### But what about the environment variables? -I see a number of people using the `shellHook` but you could argue that this is wrong, ideally we should use `env`. +I see a number of people using `shellHook`, but I'd argue that this is wrong — ideally we should use `env`. + ```nix shellHook = '' export LD_LIBRARY_PATH=${"$LD_LIBRARY_PATH:${libglvnd}/lib";} ''; ``` -Compared to before the `env` approch below seems a lot cleaner and more readable. - ```nix env = { # Force linking to libEGL and libwayland-client @@ -193,11 +193,14 @@ env = { LD_LIBRARY_PATH = lib.makeLibraryPath [ libglvnd ]; }; ``` + +Comparing these two code snippets, `env` seems a lot cleaner and more readable. + ## The cherry on top -[direnv](https://github.com/nix-community/nix-direnv). This is a tool that allows you to have a `.envrc` file in your project that will automatically load the nix shell when you enter the directory. This is a great way to make sure that you are always in the correct environment. +[nix-direnv](https://github.com/nix-community/nix-direnv) is a tool that allows you to have a `.envrc` file in your project that will automatically load the nix shell when you enter the directory. This is a great way to make sure that you are always in the correct environment. -The files from before will not change but now the `.envrc` file will be added to the projet, and this will contain something like so: +The files from before will not change but now the `.envrc` file will be added to the project, and this will contain something like so: ```sh if has nix_direnv_version; then -- 2.51.2