Skip to content

Commit

Permalink
Test Nix on CI (amber-lang#385)
Browse files Browse the repository at this point in the history
* Build Nix package on CI

* Resolve duplicate inputs and flake update

* Switch to rust-overlay

* Check that the `bc` command is included and set path works correctly

* Exit if check fails

* Move Nix checks to its own workflow
  • Loading branch information
ThetaSinner authored and Mte90 committed Sep 19, 2024
1 parent fde90a3 commit 37fa2cb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 65 deletions.
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 = {
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;
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
rustc
rustfmt
pre-commit
rustPackages.clippy
];
nativeBuildInputs = [ toolchain ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
] ++ [ toolchain ];
RUST_SRC_PATH = toolchain.availableComponents.rust-src;
};
}
);
Expand Down

0 comments on commit 37fa2cb

Please sign in to comment.