Skip to content

Commit

Permalink
Nix flake build (#237)
Browse files Browse the repository at this point in the history
* nix flake build

* set toolchain to 1.67.0

* Test Rust install on CI

* Another test

* Fix CI

* Fix CI

---------

Co-authored-by: Samuel Burnham <[email protected]>
  • Loading branch information
johnchandlerburnham and samuelburnham authored Feb 2, 2023
1 parent a246de8 commit 00dbd07
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 11 deletions.
18 changes: 8 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ commands:
steps:
- save_cache:
name: "Save rustup cache"
key: cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
key: cargo-v2-{{ checksum "rust-toolchain.toml" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
paths:
- "~/.cargo"
- "~/.rustup"
Expand All @@ -55,7 +55,7 @@ commands:
steps:
- restore_cache:
keys:
- cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- cargo-v2-{{ checksum "rust-toolchain.toml" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}

install_gpu_deps:
steps:
Expand All @@ -69,10 +69,10 @@ jobs:
- checkout
- run:
name: Update submodules
command: git submodule update --init --recursive
- run: curl https://sh.rustup.rs -sSf | sh -s -- -y
- run: rustup install $(cat rust-toolchain)
- run: rustup default $(cat rust-toolchain)
command: |
git submodule update --init --recursive
curl https://sh.rustup.rs -sSf | sh -s -- -y
- run: rustup show
- run: cargo --version
- run: rustc --version
- run:
Expand Down Expand Up @@ -133,8 +133,7 @@ jobs:
name: Install Rust
command: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
- run: rustup install $(cat rust-toolchain)
- run: rustup default $(cat rust-toolchain)
- run: rustup show
- run: cargo --version
- run: cargo update
- run: cargo fetch
Expand All @@ -157,8 +156,7 @@ jobs:
name: Install Rust
command: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
- run: rustup install $(cat rust-toolchain)
- run: rustup default $(cat rust-toolchain)
- run: rustup show
- run: cargo --version
- run: cargo update
- run: cargo fetch
Expand Down
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
102 changes: 102 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, naersk, fenix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
};

toolchain = with fenix.packages.${system}; fromToolchainFile {
file = ./rust-toolchain.toml; # alternatively, dir = ./.;
sha256 = "sha256-riZUc+R9V35c/9e8KJUE+8pzpXyl0lRXt3ZkKlxoY0g=";
};

in rec {
defaultPackage = (naersk.lib.${system}.override {
# For `nix build` & `nix run`:
cargo = toolchain;
rustc = toolchain;
}).buildPackage {
src = ./.;
};

# For `nix develop` or `direnv allow`:
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
ocl-icd
toolchain
];
};
}
);
}
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

7 changes: 7 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[toolchain]
channel = "1.67.0"
targets = [ "aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-unknown-unknown" ]
components = [ "rustc", "cargo", "clippy", "rustfmt", "rust-src",
"rust-analysis", "rust-analyzer" ]
profile = "default"

0 comments on commit 00dbd07

Please sign in to comment.