Skip to content

Latest commit

 

History

History
88 lines (68 loc) · 1.95 KB

README.md

File metadata and controls

88 lines (68 loc) · 1.95 KB

Nix Flake Template for Zig using Nixpkgs Builders

All of this information is also included in the README.md

Initialize using

nix flake init --template "github:nulladmin1/nix-flake-templates#zig"

This is how to structure of the template looks like:

📦 zig
├── ⚙️ .envrc
├── ⚙️ build.zig
├── ⚙️ build.zig.zon
├── ❄️ default.nix
├── 📃 README.md
├── ❄️ flake.nix
└── 📁 src
    └── 📝 main.zig

The flake is able to run in the specified systems listed in the flake. It contains a devShells as an output with Zig, a package that runs hello by building it with Nixpkgs' zig.hook, and an app that runs the previously mentioned package.

Run using Nix

nix run

Go into Development Shell

nix develop

(Optional) Format flake.nix using Alejandra

nix fmt

To customize it to you own needs:

  • In 'flake.nix'

    • Edit description

      {
          description = "project_name";
      }
    • Change details in mkDerivation

          default = pkgsFor.${system}.stdenv.mkDerivation {
          pname = "project_name";
          version = "0.1.0";
          src = ./.;
      
          nativeBuildInputs = with pkgsFor.${system}; [
            zig.hook
          ];
        };
  • In build.zig

    • Configure main executable details
          const exe = b.addExecutable(.{
            .name = "project_name",
            .root_source_file = b.path("src/main.zig"),
            .target = target,
            .optimize = optimize,
          });
  • In build.zig.zon

    • Configure package details
        .name = "project_name",
        .version = "0.1.0",
      
  • For the structure and code

    • Add necessary code into the src/ directory. Reflect changes in build.zig