Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Nix on CI #385

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build verify Amber Nix
on:
push:
branches:
- master
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
nix_build:
name: Nix build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
- name: Check Nix flake
run: nix flake check --all-systems
- name: Build in Nix shell
run: nix develop --command cargo build --release
- name: Build with Nix
run: |
nix build

# Ensure that the `amber` binary runs
./result/bin/amber --version

# Ensure that the `bc` command is correctly provided
echo "import { exit } from \"std/env\"\n\$which bc && bc --version\$ failed { echo \"Failed to run basic calculator\"\nexit(1) }" | ./result/bin/amber -
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
- Cargo.toml
- Cargo.lock
- rust-toolchain.toml
- flake.nix
- flake.lock
pull_request:
paths:
- src/**
Expand All @@ -18,6 +20,8 @@ on:
- Cargo.toml
- Cargo.lock
- rust-toolchain.toml
- flake.nix
- flake.lock

env:
CARGO_TERM_COLOR: always
Expand Down
68 changes: 31 additions & 37 deletions flake.lock

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

51 changes: 23 additions & 28 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
{
inputs = {
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixpkgs-unstable";

naersk = {
url = "github:nix-community/naersk?ref=master";
inputs.nixpkgs.follows = "nixpkgs";
};
utils.url = "github:numtide/flake-utils";
nixpkgs-mozilla = {
url = "github:mozilla/nixpkgs-mozilla";
flake = false;
rust-overlay = {
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{
self,
nixpkgs,
utils,
naersk,
nixpkgs-mozilla,
{ self
, nixpkgs
, utils
, naersk
, rust-overlay
,
}:
utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import nixpkgs-mozilla) ];
overlays = [ (import rust-overlay) ];
};
toolchain =
(pkgs.rustChannelOf {
rustToolchain = ./rust-toolchain.toml;
sha256 = "sha256-Ngiz76YP4HTY75GGdH2P+APE/DEIx2R/Dn+BwwOyzZU=";
}).rust;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
naersk-lib = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
in
{
formatter = pkgs.nixpkgs-fmt;
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
packages.default = naersk-lib.buildPackage {
src = ./.;
nativeBuildInputs = [ pkgs.makeWrapper ];
postInstall = ''
wrapProgram "$out/bin/amber" --set PATH ${nixpkgs.lib.makeBinPath [ pkgs.bc ]}
wrapProgram "$out/bin/amber" --prefix PATH : ${nixpkgs.lib.makeBinPath [ pkgs.bc ]}
'';
};
devShells.default =
with pkgs;
mkShell {
buildInputs = [
pkgs.mkShell {
packages = with pkgs; [
bc
cargo
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
rustc
rustfmt
pre-commit
rustPackages.clippy
];
nativeBuildInputs = [ toolchain ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
] ++ [ toolchain ];
RUST_SRC_PATH = toolchain.availableComponents.rust-src;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I'm not sure about, I assume this is for VSCode integration? I don't have that or know how to check if this is still making Rust's source code available for inspection with RLS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be necessary for rust-analyzer, for the development environment. See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570

Trying to run rust-analyzer from the dev environment, I get another problem though:

(nix:nix-shell-env) mks@Navi:~/Projects/amber$ rust-analyzer 
error: Unknown binary 'rust-analyzer' in official toolchain 'stable-x86_64-unknown-linux-gnu'.

};
}
);
Expand Down