Added nix flake and shell files for nixos users who want to work on development. You can use flake method => 'nix develop' or non flake method =>`nix-shell'
The shell.nix file is used for both flake and non-flake invocations. The lock file is also set at a version where the project works. Note the none-flake method will follow the version of the system and isn't guaranteed to work on older installations if they haven't been updated in a while. Added Documentation for using Nix package manager for development ./Documentation/LinuxDevelopmentSetupUsingNix.md Signed-off-by: Ayman Jundi <ajundi@gmail.com>
This commit is contained in:
parent
2fca6b8b91
commit
bc8a35aedd
64
Documentation/LinuxDevelopmentSetupUsingNix.md
Normal file
64
Documentation/LinuxDevelopmentSetupUsingNix.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# Development Environment Setup using Nix or Nix Flakes on Linux x86_64
|
||||||
|
[Nix flakes](https://nixos.wiki/wiki/Flakes) can be used to provide version controlled reproducible and cross-platform development environments. The key files are:
|
||||||
|
- `flake.nix`: Defines the flake inputs and outputs, including development shells.
|
||||||
|
- `shell.nix`: This file defines the dependencies and additionally adds support for the Impure `nix-shell` method. This is used by the flake to create the dev environment.
|
||||||
|
- `flake.lock`: Locks the versions of inputs for reproducibility.
|
||||||
|
---
|
||||||
|
## Prerequisites
|
||||||
|
- [Nix](https://nixos.org/download.html) the package manager or NixOs installed on Linux (x86_64-linux)
|
||||||
|
- Optional: flakes support enabled.
|
||||||
|
---
|
||||||
|
## Using the Development Shell
|
||||||
|
You have two primary ways to enter the development shell with Nix:
|
||||||
|
### 1. Using `nix develop` (flake-native command)
|
||||||
|
This is the recommended way if you have Nix with flakes support. Flake guarantee the versions of the dependencies and can be controlled through `flake.nix` and `flake.lock`.
|
||||||
|
```
|
||||||
|
nix develop
|
||||||
|
```
|
||||||
|
This will open a shell with all dependencies and environment configured as per the `flake.nix` for (`x86_64-linux`) systems only at this time.
|
||||||
|
|
||||||
|
---
|
||||||
|
### 2. Using `nix-shell` (that's why shell.nix is a separate file)
|
||||||
|
If you want to use traditional `nix-shell` tooling which uses the nixpkgs version of your system:
|
||||||
|
```
|
||||||
|
nix-shell
|
||||||
|
```
|
||||||
|
This will drop you into the shell environment defined in `shell.nix`. Note that this is not flake-native method and does not use the locked nixpkgs in `flake.lock` so exact versions of the dependancies is not guaranteed.
|
||||||
|
|
||||||
|
---
|
||||||
|
## What’s inside the dev shell?
|
||||||
|
- The environment variables and packages configured in `shell.nix` will be available.
|
||||||
|
- The package set (`pkgs`) used aligns with the versions locked in `flake.lock` to ensure reproducibility.
|
||||||
|
|
||||||
|
---
|
||||||
|
## Example Workflow using flakes
|
||||||
|
```
|
||||||
|
# Navigate to the project root folder which contains the flake.nix, flake.lock and shell.nix files.
|
||||||
|
cd /home/user/dev/Libation
|
||||||
|
# Enter the flake development shell (Linux x86_64)
|
||||||
|
nix develop
|
||||||
|
# run VSCode or VSCodium from the current shell environment
|
||||||
|
code .
|
||||||
|
# Run or Debug using VSCode and VSCodium using the linux Launch configuration.
|
||||||
|
```
|
||||||
|

|
||||||
|
|
||||||
|
You can also Build and run your application inside the shell.
|
||||||
|
```
|
||||||
|
dotnet build ./Source/LibationAvalonia/LibationAvalonia.csproj -p:TargetFrameworks=net9.0 -p:TargetFramework=net9.0 -p:RuntimeIdentifier=linux-x64
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
- Leaving the current shell environemnt will drop all added dependancies and you will not be able to run or debug the program unless your system has those dependancies defined globally.
|
||||||
|
- To exit the shell environment voluntarily use `exit` inside the shell.
|
||||||
|
- Ensure you have no conflicting `nix.conf` or `global.json` that might affect SDK versions or runtime identifiers.
|
||||||
|
- Keep your `flake.lock` file committed to ensure builds are reproducible for all collaborators.
|
||||||
|
|
||||||
|
---
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Nix Flakes - NixOS Wiki](https://nixos.wiki/wiki/Flakes)
|
||||||
|
- [Nix.dev - Introduction to Nix flakes](https://nix.dev/manual/nix/2.28/command-ref/new-cli/nix3-flake-init)
|
||||||
|
- [Nix-shell Manual](https://nixos.org/manual/nix/stable/command-ref/nix-shell.html)
|
||||||
BIN
Documentation/images/StartingDebuggingInVSCode.png
Normal file
BIN
Documentation/images/StartingDebuggingInVSCode.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1749794982,
|
||||||
|
"narHash": "sha256-Kh9K4taXbVuaLC0IL+9HcfvxsSUx8dPB5s5weJcc9pc=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "ee930f9755f58096ac6e8ca94a1887e0534e2d81",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
16
flake.nix
Normal file
16
flake.nix
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
description =
|
||||||
|
"Generic flake to run shell.nix with a locked nixos pkgs version. If you have
|
||||||
|
flakes enabled just run 'nix develop' in the same folder as flake.nix";
|
||||||
|
inputs = {
|
||||||
|
#// use your preferred nixpkgs version
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { nixpkgs, ... }:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
|
in {
|
||||||
|
devShells.x86_64-linux.default = import ./shell.nix {inherit pkgs;};
|
||||||
|
};
|
||||||
|
}
|
||||||
19
shell.nix
Normal file
19
shell.nix
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{pkgs ? import <nixpkgs> {}}: let
|
||||||
|
libPath = with pkgs;
|
||||||
|
lib.makeLibraryPath [
|
||||||
|
# load external libraries that you need in your dotnet project here
|
||||||
|
xorg.libX11
|
||||||
|
xorg.libICE
|
||||||
|
xorg.libSM
|
||||||
|
libGL
|
||||||
|
fontconfig
|
||||||
|
];
|
||||||
|
in
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
dotnet-sdk_9
|
||||||
|
];
|
||||||
|
|
||||||
|
DOTNET_ROOT = "${pkgs.dotnet-sdk_9}/share/dotnet";
|
||||||
|
LD_LIBRARY_PATH =libPath;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user