summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyze312 <ryze312@tutanota.com>2024-04-07 18:57:00 +0300
committerRyze312 <ryze312@tutanota.com>2024-04-07 18:57:00 +0300
commit82799d734cadfc92172bc1ca63038902fe38066a (patch)
tree85caa279532ea8e17fe62f50640ddb1e59143667
parent3be57519a819291ef77087116e21ae9e167434dc (diff)
downloadaxis-82799d734cadfc92172bc1ca63038902fe38066a.tar.gz
axis-82799d734cadfc92172bc1ca63038902fe38066a.tar.bz2
axis-82799d734cadfc92172bc1ca63038902fe38066a.zip
Add Nix devshell and direnv support
-rw-r--r--.envrc2
-rw-r--r--.gitignore2
-rw-r--r--flake.lock65
-rw-r--r--flake.nix33
-rw-r--r--shell.nix39
5 files changed, 141 insertions, 0 deletions
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..af0cc93
--- /dev/null
+++ b/.envrc
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+use flake
diff --git a/.gitignore b/.gitignore
index ed8080f..fb2185d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
/axisc/target
/axis-rt/target
/demo
+
+/.direnv
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..79e3c18
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,65 @@
+{
+ "nodes": {
+ "fenix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "rust-analyzer-src": "rust-analyzer-src"
+ },
+ "locked": {
+ "lastModified": 1712384501,
+ "narHash": "sha256-AZmYmEnc1ZkSlxUJVUtGh9VFAqWPr+xtNIiBqD2eKfc=",
+ "owner": "nix-community",
+ "repo": "fenix",
+ "rev": "99c6241db5ca5363c05c8f4acbdf3a4e8fc42844",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "fenix",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1712439257,
+ "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599",
+ "type": "github"
+ },
+ "original": {
+ "id": "nixpkgs",
+ "ref": "nixos-unstable",
+ "type": "indirect"
+ }
+ },
+ "root": {
+ "inputs": {
+ "fenix": "fenix",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "rust-analyzer-src": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1712156296,
+ "narHash": "sha256-St7ZQrkrr5lmQX9wC1ZJAFxL8W7alswnyZk9d1se3Us=",
+ "owner": "rust-lang",
+ "repo": "rust-analyzer",
+ "rev": "8e581ac348e223488622f4d3003cb2bd412bf27e",
+ "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 0000000..cec4abb
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,33 @@
+{
+ inputs = {
+ nixpkgs.url = "nixpkgs/nixos-unstable";
+
+ fenix = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs = { self, nixpkgs, fenix }:
+ let
+ overlays = [ fenix.overlays.default ];
+
+ getPkgsFor = (system: import nixpkgs {
+ inherit system overlays;
+ });
+
+ forEachSystem = func: nixpkgs.lib.genAttrs [
+ "x86_64-linux"
+ "i686-linux"
+ "aarch64-linux"
+
+ "aarch64-darwin"
+ "x86_64-darwin"
+ ] (system: func (getPkgsFor system));
+
+ in {
+ devShells = forEachSystem (pkgs: {
+ default = pkgs.callPackage ./shell.nix {};
+ });
+ };
+}
diff --git a/shell.nix b/shell.nix
new file mode 100644
index 0000000..7ed5296
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,39 @@
+{ mkShell, pkgsCross, fenix }:
+
+# Reference: https://github.com/nix-community/naersk/blob/aeb58d5e8faead8980a807c840232697982d47b9/examples/cross-windows/flake.nix
+
+let
+ channel = "stable";
+
+ targets = with fenix.targets; [
+ x86_64-unknown-linux-gnu
+ i686-unknown-linux-gnu
+ aarch64-unknown-linux-gnu
+
+ aarch64-apple-darwin
+ x86_64-apple-darwin
+ ];
+
+ crossCompileTargets = with fenix.targets; [
+ x86_64-pc-windows-gnu
+ ];
+
+ toolchain = fenix.combine (with fenix.${channel}; [
+ cargo
+ rustc
+ ] ++ map (target: target.${channel}.toolchain) targets
+ ++ map (target: target.${channel}.rust-std) crossCompileTargets);
+
+in
+
+mkShell {
+ buildInputs = with pkgsCross.mingwW64; [
+ stdenv.cc
+ ];
+
+ packages = [ toolchain ];
+
+ # Link to libpthreads manually otherwise build fails
+ # See: https://github.com/NixOS/nixpkgs/issues/139966#issuecomment-1385222547
+ env.CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS = "-L native=${pkgsCross.mingwW64.windows.pthreads}/lib";
+}