From 66817dde5b3e8a2c846e111e4032c71c86bfd51b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Aug 2022 09:36:18 -0700 Subject: [PATCH] template for zig compiler dev --- flake.nix | 6 ++++ templates/compiler-dev/.envrc | 4 +++ templates/compiler-dev/flake.lock | 60 +++++++++++++++++++++++++++++++ templates/compiler-dev/flake.nix | 39 ++++++++++++++++++++ templates/compiler-dev/shell.nix | 9 +++++ 5 files changed, 118 insertions(+) create mode 100644 templates/compiler-dev/.envrc create mode 100644 templates/compiler-dev/flake.lock create mode 100644 templates/compiler-dev/flake.nix create mode 100644 templates/compiler-dev/shell.nix diff --git a/flake.nix b/flake.nix index eecee7e..3b30b06 100644 --- a/flake.nix +++ b/flake.nix @@ -41,5 +41,11 @@ overlays.default = final: prev: { zigpkgs = outputs.packages.${prev.system}; }; + + # Templates for use with zig flake init + templates.compiler-dev = { + path = ./templates/compiler-dev; + description = "A development environment for Zig compiler development."; + }; }; } diff --git a/templates/compiler-dev/.envrc b/templates/compiler-dev/.envrc new file mode 100644 index 0000000..9384ad6 --- /dev/null +++ b/templates/compiler-dev/.envrc @@ -0,0 +1,4 @@ +# use nix shell if nix is available +if has nix; then + use nix +fi diff --git a/templates/compiler-dev/flake.lock b/templates/compiler-dev/flake.lock new file mode 100644 index 0000000..b00ec3d --- /dev/null +++ b/templates/compiler-dev/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1661239106, + "narHash": "sha256-C5OCLnrv2c4CHs9DMEtYKkjJmGL7ySAZ1PqPkHBonxQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "963d27a0767422be9b8686a8493dcade6acee992", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/compiler-dev/flake.nix b/templates/compiler-dev/flake.nix new file mode 100644 index 0000000..d48fe65 --- /dev/null +++ b/templates/compiler-dev/flake.nix @@ -0,0 +1,39 @@ +{ + description = "Zig compiler development."; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + # Used for shell.nix + flake-compat = { url = github:edolstra/flake-compat; flake = false; }; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + cmake + gdb + libxml2 + ninja + qemu + wasmtime + zlib + ] ++ (with llvmPackages_14; [ + clang + clang-unwrapped + lld + llvm + ]); + + hardeningDisable = [ "all" ]; + }; + + # For compatibility with older versions of the `nix` binary + devShell = self.devShells.${system}.default; + } + ); +} diff --git a/templates/compiler-dev/shell.nix b/templates/compiler-dev/shell.nix new file mode 100644 index 0000000..7e231b7 --- /dev/null +++ b/templates/compiler-dev/shell.nix @@ -0,0 +1,9 @@ +(import + ( + let flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz"; + sha256 = flake-compat.locked.narHash; + } + ) + { src = ./.; }).shellNix