From 467f48b3ad64bd13e6ef633132c661865ea82146 Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Mon, 11 Sep 2023 13:17:32 +0200 Subject: [PATCH] Set up a development shell with Nix. Just for local development; no one's shipping anything with this thing. --- .envrc | 3 ++ .envrc.local | 5 ++++ .github/workflows/nix.yaml | 20 +++++++++++++ .gitignore | 4 +++ flake.lock | 61 ++++++++++++++++++++++++++++++++++++++ flake.nix | 39 ++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 .envrc create mode 100644 .envrc.local create mode 100644 .github/workflows/nix.yaml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..5de4a0859 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +source_env_if_exists ./.envrc.local diff --git a/.envrc.local b/.envrc.local new file mode 100644 index 000000000..3f4114658 --- /dev/null +++ b/.envrc.local @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +use flake + +source_env ../.envrc diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml new file mode 100644 index 000000000..3fa535ccb --- /dev/null +++ b/.github/workflows/nix.yaml @@ -0,0 +1,20 @@ +name: test Nix support + +on: push + +jobs: + evaluate-nix-shell: + name: Evaluate the Nix shell + runs-on: ubuntu-latest + steps: + - name: Checkout 🛎️ + uses: actions/checkout@v3 + + - name: Install Nix ❄ + uses: DeterminateSystems/nix-installer-action@v4 + + - name: Run the Magic Nix Cache 🔌 + uses: DeterminateSystems/magic-nix-cache-action@v2 + + - name: Evaluate the Nix shell + run: nix develop -c "true" diff --git a/.gitignore b/.gitignore index ea8c4bf7f..428674eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +# Rust /target + +# direnv +/.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..e5826ca7e --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1694430955, + "narHash": "sha256-01IHejnGTdivgQoXTh/fS740JsbOTuCtJkgTyQ+Buq8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bce7373adb44a76912a03548c4d31bf6f368f21b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "master", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..fefd4648e --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "ndc-sdk"; + + inputs = { + flake-utils.url = github:numtide/flake-utils; + nixpkgs.url = github:NixOS/nixpkgs/master; + }; + + outputs = + { self + , flake-utils + , nixpkgs + }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShells.default = pkgs.mkShell { + nativeBuildInputs = [ + pkgs.cargo + pkgs.cargo-edit + pkgs.cargo-machete + pkgs.clippy + pkgs.rust-analyzer + pkgs.rustPlatform.rustcSrc + pkgs.rustc + pkgs.rustfmt + ]; + + buildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.Security + pkgs.libiconv + ]; + }; + + formatter = pkgs.nixpkgs-fmt; + }); +}