diff --git a/.gitignore b/.gitignore index 13c8d2c6..a8eda6ef 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ # direnv (https://direnv.net/) .envrc +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..b8ff3903 --- /dev/null +++ b/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1715063087, + "narHash": "sha256-cktPkcCmJ2sR0V/FaWEuCWmKuGPbwoMltih/EfF0mXg=", + "owner": "nix-community", + "repo": "fenix", + "rev": "f8f16c1f2c83bea4e51e6522d988ec8bfcc8420e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714971268, + "narHash": "sha256-IKwMSwHj9+ec660l+I4tki/1NRoeGpyA2GdtdYpAgEw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "27c13997bf450a01219899f5a83bd6ffbfc70d3c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1714936835, + "narHash": "sha256-M+PpgfRMBfHo8Jb2ou/s3maAZbps0XnuHXQU9Hv9vL0=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "c4618fe14d39992fbbb85c2d6cad028a232c13d2", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..c0cf0cc8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + + # The rustup equivalent for Nix. + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # Allows non-flakes users to still be able to `nix-shell` based on + # `shell.nix` instead of this `flake.nix`. + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, fenix, ... }: + let + inherit (nixpkgs) lib; + + eachSupportedSystem = lib.genAttrs supportedSystems; + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + mkDevShells = system: + let + pkgs = import nixpkgs { inherit system; }; + + # get the rust toolchain from the rustup + # `rust-toolchain.toml` configuration file + rust-toolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "opUgs6ckUQCyDxcB9Wy51pqhd0MPGHUVbwRKKPGiwZU="; + }; + + in + { + default = pkgs.mkShell { + buildInputs = [ rust-toolchain ]; + }; + }; + + in + { + devShells = eachSupportedSystem mkDevShells; + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..3ccec483 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +profile = "default" +components = [ "rust-src", "rust-analyzer" ] diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..9d07c80a --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +# Compatiblity file for non-flake Nix users. +# +# +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix