From 16cb5d1851a770c5bce3f836cbade5be312d6737 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 10 Nov 2022 14:02:57 -0800 Subject: [PATCH] add "init" template for an empty dev env --- flake.nix | 5 +++++ templates/init/.envrc | 5 +++++ templates/init/flake.nix | 46 ++++++++++++++++++++++++++++++++++++++++ templates/init/shell.nix | 12 +++++++++++ 4 files changed, 68 insertions(+) create mode 100644 templates/init/.envrc create mode 100644 templates/init/flake.nix create mode 100644 templates/init/shell.nix diff --git a/flake.nix b/flake.nix index 9f94121..466e26a 100644 --- a/flake.nix +++ b/flake.nix @@ -47,5 +47,10 @@ path = ./templates/compiler-dev; description = "A development environment for Zig compiler development."; }; + + templates.init = { + path = ./templates/init; + description = "A basic, empty development environment."; + }; }; } diff --git a/templates/init/.envrc b/templates/init/.envrc new file mode 100644 index 0000000..24e67d2 --- /dev/null +++ b/templates/init/.envrc @@ -0,0 +1,5 @@ +# If we are a computer with nix-shell available, then use that to setup +# the build environment with exactly what we need. +if has nix; then + use nix +fi diff --git a/templates/init/flake.nix b/templates/init/flake.nix new file mode 100644 index 0000000..30cc48b --- /dev/null +++ b/templates/init/flake.nix @@ -0,0 +1,46 @@ +{ + description = "An empty project that uses Zig."; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/release-22.05"; + flake-utils.url = "github:numtide/flake-utils"; + zig.url = "github:mitchellh/zig-overlay"; + + # Used for shell.nix + flake-compat = { + url = github:edolstra/flake-compat; + flake = false; + }; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + ... + } @ inputs: let + overlays = [ + # Other overlays + (final: prev: { + zigpkgs = inputs.zig.packages.${prev.system}; + }) + ]; + + # Our supported systems are the same supported systems as the Zig binaries + systems = builtins.attrNames inputs.zig.packages; + in + flake-utils.lib.eachSystem systems ( + system: let + pkgs = import nixpkgs {inherit overlays system;}; + in rec { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + zigpkgs.master + ]; + }; + + # For compatibility with older versions of the `nix` binary + devShell = self.devShells.${system}.default; + } + ); +} diff --git a/templates/init/shell.nix b/templates/init/shell.nix new file mode 100644 index 0000000..a15057a --- /dev/null +++ b/templates/init/shell.nix @@ -0,0 +1,12 @@ +(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