Development environment with nix-shell: Difference between revisions
imported>Kendofriendo m fix grammar |
TYPO |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
If you already have a nix package definition of your project it's easy: Just use <code>nix-shell</code> instead of <code>nix-build</code> and you will end up in a bash shell that reproduce the build-environment of your package. You can also override[https://nixos.org/nixpkgs/manual/#sec-pkg-override] your package in a <code>shell.nix</code> file to add test and coverage dependencies, that are not necessary for the actual build of the package, but that you want for your development environment. | If you already have a nix package definition of your project it's easy: Just use <code>nix-shell</code> instead of <code>nix-build</code> and you will end up in a bash shell that reproduce the build-environment of your package. You can also override[https://nixos.org/nixpkgs/manual/#sec-pkg-override] your package in a <code>shell.nix</code> file to add test and coverage dependencies, that are not necessary for the actual build of the package, but that you want for your development environment. | ||
But, if you don't (or you don't want to) have a package definition you can still use a nix-shell to provide a reproducible development environment. To do so, you have to create a <code>shell.nix</code> file at the root of your repository. For example, if you want to have Ruby 2 | But, if you don't (or you don't want to) have a package definition you can still use a nix-shell to provide a reproducible development environment. To do so, you have to create a <code>shell.nix</code> file at the root of your repository. For example, if you want to have Ruby 3.2 and not one provided by your system you can write: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
pkgs.mkShell { | pkgs.mkShell { | ||
# nativeBuildInputs is usually what you want -- tools you need to run | # nativeBuildInputs is usually what you want -- tools you need to run | ||
nativeBuildInputs = | nativeBuildInputs = with pkgs.buildPackages; [ ruby_3_2 ]; | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 18: | Line 18: | ||
{{Commands|$ nix-shell shell.nix}} | {{Commands|$ nix-shell shell.nix}} | ||
Now you have ruby 2 | Now you have ruby 3.2 available in your shell: | ||
<syntaxHighlight lang=bash> | <syntaxHighlight lang=bash> | ||
$ ruby --version | $ ruby --version | ||
ruby 2. | ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux] | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 195: | Line 195: | ||
For packages we use <code>wrapGAppsHook</code> in <code>nativeBuildInputs</code>, however in nix-shell this is not working as expected. | For packages we use <code>wrapGAppsHook</code> in <code>nativeBuildInputs</code>, however in nix-shell this is not working as expected. | ||
To get your application to work in nix-shell you will need to add the following to your <code>mkShell</code> expression: | To get your application to work in nix-shell you will need to add the following to your <code>mkShell</code> expression: | ||
< | <syntaxhighlight lang="nix"> | ||
mkShell { | mkShell { | ||
... | ... | ||
buildInputs = [ gtk3 ]; | buildInputs = [ gtk3 ]; | ||
shellHook = '' | shellHook = '' | ||
export XDG_DATA_DIRS=$ | export XDG_DATA_DIRS=$GSETTINGS_SCHEMAS_PATH | ||
''; | ''; | ||
} | } | ||
</ | </syntaxhighlight> | ||
This may also called: <code>$GSETTINGS_SCHEMA'''S'''_PATH</code>. | This may also called: <code>$GSETTINGS_SCHEMA'''S'''_PATH</code>. | ||
Line 210: | Line 210: | ||
Similar to the Gsettings issue, icons can be added with XDG_DATA_DIRS: | Similar to the Gsettings issue, icons can be added with XDG_DATA_DIRS: | ||
<pre> XDG_DATA_DIRS=...:${hicolor-icon-theme}/share:${gnome3.adwaita-icon-theme}/share</pre> | <pre> XDG_DATA_DIRS=...:${hicolor-icon-theme}/share:${gnome3.adwaita-icon-theme}/share</pre> | ||
[[Category:Development]] | |||
[[Category:nix]] |