mimoo / nixbyexample

Learn nix by example
https://mimoo.github.io/nixbyexample
11 stars 1 forks source link

no simplistic development example via shell.nix and direnv #3

Open matu3ba opened 1 year ago

matu3ba commented 1 year ago

Your examples assume that the user wants to build everything with flakes etc, but the user might also just want to reuse upstream as environment and use relative paths.

Reasoning:

Paths:

~/dev/zdev/zig/
~/dev/zdev/zig-bootstrap/
~/dev/zdev/shell.nix
~/dev/zdev/.envrc
~/dev/zi/shell.nix
~/dev/zi/.envrc

~/dev/zdev/shell.nix

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/01441e14af5e29c9d27ace398e6dd0b293e25a54.tar.gz") {} }:
pkgs.stdenvNoCC.mkDerivation {
  name = "shell";
  nativeBuildInputs = with pkgs; [
      cmake
      gdb
      libxml2
      ninja
      python3
      qemu
      valgrind
      wasmtime
  ] ++ (with llvmPackages_16; [
    clang
    clang-unwrapped
    lld
    llvm
  ]);
}

~/dev/zi/shell.nix with shellHook example:

{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/01441e14af5e29c9d27ace398e6dd0b293e25a54.tar.gz") {} }:
pkgs.stdenvNoCC.mkDerivation {
  name = "shell";
  nativeBuildInputs = with pkgs; [
      gdb
      qemu
      valgrind
      wasmtime
  ];
  PROJECT_ROOT = builtins.toString ./.;
  shellHook = ''
    PATH=$PATH:$PROJECT_ROOT/../zdev/zig/master/rel/bin/
  '';
}
mimoo commented 1 year ago

I think this guide was meant to be a "best practice to start a project with nix today", but things get more and more complicated/complex as you go through the guide