diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-03-10 14:59:14 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-03-10 14:59:14 +0100 |
| commit | 1100562e29f6476448b656dbddd4cf22505523f6 (patch) | |
| tree | 442eec492199104bd49dfd74474ce89ade8fcac9 /_posts/notes/2023-06-25-development-environments-with-nix.md | |
| parent | a40d80be378e46a6c490e1b99b0d8f4acd968503 (diff) | |
| download | mitjafelicijan.com-1100562e29f6476448b656dbddd4cf22505523f6.tar.gz | |
Move back to JBMAFP
Diffstat (limited to '_posts/notes/2023-06-25-development-environments-with-nix.md')
| -rw-r--r-- | _posts/notes/2023-06-25-development-environments-with-nix.md | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/_posts/notes/2023-06-25-development-environments-with-nix.md b/_posts/notes/2023-06-25-development-environments-with-nix.md deleted file mode 100644 index a905f10..0000000 --- a/_posts/notes/2023-06-25-development-environments-with-nix.md +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | --- | ||
| 2 | title: "Development environments with Nix" | ||
| 3 | permalink: /development-environments-with-nix.html | ||
| 4 | date: 2023-06-25T16:38:10+02:00 | ||
| 5 | layout: post | ||
| 6 | type: note | ||
| 7 | draft: false | ||
| 8 | tags: [random] | ||
| 9 | --- | ||
| 10 | |||
| 11 | Nix is amazing for making reproducible cross OS development environment. | ||
| 12 | |||
| 13 | First you need to [install Nix package | ||
| 14 | manager](https://nixos.org/download.html). | ||
| 15 | |||
| 16 | - Create a file `shell.nix` in your project folder. | ||
| 17 | - In the section that has `python3` etc add programs you want to use. These can | ||
| 18 | be CLI or GUI applications. It doesn't matter to Nix. | ||
| 19 | |||
| 20 | ```nix | ||
| 21 | { pkgs ? import <nixpkgs> {} }: | ||
| 22 | pkgs.mkShell { | ||
| 23 | nativeBuildInputs = with pkgs.buildPackages; [ | ||
| 24 | python3 | ||
| 25 | tinycc | ||
| 26 | ]; | ||
| 27 | } | ||
| 28 | ``` | ||
| 29 | |||
| 30 | And then run it `nix-shell`. By default it will look for `shell.nix` file. If | ||
| 31 | you want to specify a different file use `nix-shell file.nix`. That is about it. | ||
| 32 | |||
| 33 | When the shell is spawned it could happen that your `PS1` prompt will be | ||
| 34 | overwritten and your prompt will look differently. In that case you need to | ||
| 35 | either do `NIX_SHELL_PRESERVE_PROMPT=1 nix shell` or add | ||
| 36 | `NIX_SHELL_PRESERVE_PROMPT` variable to your `bashrc` or `zshrc` file and set it | ||
| 37 | to `1`. | ||
| 38 | |||
| 39 | I also have a modified `PS1` prompt for Bash that I use and it also catches the | ||
| 40 | usage of Nix shell. | ||
| 41 | |||
| 42 | ```sh | ||
| 43 | NIX_SHELL_PRESERVE_PROMPT=1 | ||
| 44 | |||
| 45 | parse_git_branch() { | ||
| 46 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | ||
| 47 | } | ||
| 48 | |||
| 49 | is_inside_nix_shell() { | ||
| 50 | nix_shell_name="$(basename "$IN_NIX_SHELL" 2>/dev/null)" | ||
| 51 | if [[ -n "$nix_shell_name" ]]; then | ||
| 52 | echo " \e[0;36m(nix-shell)\e[0m" | ||
| 53 | fi | ||
| 54 | } | ||
| 55 | |||
| 56 | export PS1="[\033[38;5;9m\]\u@\h\[$(tput sgr0)\]]$(is_inside_nix_shell)\[\033[33m\]\$(parse_git_branch)\[\033[00m\] \w\[$(tput sgr0)\] \n$ " | ||
| 57 | ``` | ||
| 58 | |||
| 59 | And this is what it looks like when you are in a Nix shell. Otherwise that part | ||
| 60 | of prompt is omitted | ||
| 61 | |||
| 62 | {:loading="lazy"} | ||
| 63 | |||
| 64 | More resources: | ||
| 65 | |||
| 66 | - https://nixos.wiki/wiki/Development_environment_with_nix-shell | ||
| 67 | - https://nixos.wiki/wiki/Main_Page | ||
| 68 | - https://itsfoss.com/why-use-nixos/ | ||
| 69 | - https://mynixos.com/ | ||
