diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000..280c8d54 --- /dev/null +++ b/.github/workflows/nix.yml @@ -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 - diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 44a34f1a..f9914575 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,6 +10,8 @@ on: - Cargo.toml - Cargo.lock - rust-toolchain.toml + - flake.nix + - flake.lock pull_request: paths: - src/** @@ -18,6 +20,8 @@ on: - Cargo.toml - Cargo.lock - rust-toolchain.toml + - flake.nix + - flake.lock env: CARGO_TERM_COLOR: always diff --git a/flake.lock b/flake.lock index 654b9fbb..535c6270 100644 --- a/flake.lock +++ b/flake.lock @@ -2,14 +2,16 @@ "nodes": { "naersk": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1718727675, - "narHash": "sha256-uFsCwWYI2pUpt0awahSBorDUrUfBhaAiyz+BPTS2MHk=", + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", "owner": "nix-community", "repo": "naersk", - "rev": "941ce6dc38762a7cfb90b5add223d584feed299b", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "type": "github" }, "original": { @@ -21,39 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 0, - "narHash": "sha256-EYekUHJE2gxeo2pM/zM9Wlqw1Uw2XTJXOSAO79ksc4Y=", - "path": "/nix/store/qmh8bas1qni03drm0lnjas2azh7h87cn-source", - "type": "path" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs-mozilla": { - "flake": false, - "locked": { - "lastModified": 1704373101, - "narHash": "sha256-+gi59LRWRQmwROrmE1E2b3mtocwueCQqZ60CwLG+gbg=", - "owner": "mozilla", - "repo": "nixpkgs-mozilla", - "rev": "9b11a87c0cc54e308fa83aac5b4ee1816d5418a2", - "type": "github" - }, - "original": { - "owner": "mozilla", - "repo": "nixpkgs-mozilla", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1720955038, - "narHash": "sha256-GaliJqfFwyYxReFywxAa8orCO+EnDq2NK2F+5aSc8vo=", + "lastModified": 1722415718, + "narHash": "sha256-5US0/pgxbMksF92k1+eOa8arJTJiPvsdZj9Dl+vJkM4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "aa247c0c90ecf4ae7a032c54fdc21b91ca274062", + "rev": "c3392ad349a5227f4a3464dce87bcc5046692fce", "type": "github" }, "original": { @@ -66,11 +40,31 @@ "root": { "inputs": { "naersk": "naersk", - "nixpkgs": "nixpkgs_2", - "nixpkgs-mozilla": "nixpkgs-mozilla", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", "utils": "utils" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722479030, + "narHash": "sha256-98tsdV+N9wSVU0vlzjJ30+9QL2bescJs5jWFurTpvAw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "c02e7d32607e4e16c80152a40ee141c4877b00cb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "systems": { "locked": { "lastModified": 1681028828, diff --git a/flake.nix b/flake.nix index 64a3308a..6c419e8f 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } );