Skip to content

Commit db9377c

Browse files
committed
nix: switch to Nix Flake
This modernizes the Nix files of this project. Nix Flakes are the de-facto standard way in Nix to package projects and specify their inputs. Inputs can be any Nix or non-Nix project. Updating Nix dependencies now is as easy as `nix flake update` and a corresponding commit. As they are still not stabilized yet, you need the line experimental-features = nix-command flakes in /etc/nix/nix.conf to use the flake. By usage, I mean entering the Nix development shell using `$ nix develop .` or if you want to run `nix flake update`. The package manager niv, we used to have, is basically dead.
1 parent 07938b6 commit db9377c

File tree

9 files changed

+135
-336
lines changed

9 files changed

+135
-336
lines changed

.envrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# If your shell has direnv support, it will automatically open a "nix-shell".
2-
use nix
1+
# If your shell has direnv support, it will automatically open a Nix shell with
2+
# all relevant dependencies to develop this project.
3+
use flake

.github/workflows/developer_productivity.yml

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
pull_request:
66
jobs:
7-
# Job to run change detection
7+
# Job to run change detection for Nix-related files
88
changes:
99
runs-on: ubuntu-latest
1010
# Set job outputs to values from filter step.
@@ -19,13 +19,14 @@ jobs:
1919
filters: |
2020
nix-src:
2121
- 'nix/**'
22-
- 'shell.nix'
22+
- 'flake.nix'
23+
- 'flake.lock'
2324
# This is a convenience test to verify that the toolchain provided by
2425
# shell.nix is valid and can build + run the integration test.
2526
#
2627
# It only runs if the "nix-src" output of the "changes" job is true.
2728
nix_shell_toolchain:
28-
name: "Nix toolchain: `cargo xtask run` works"
29+
name: "Nix shell toolchain: `cargo xtask run` works"
2930
needs: changes
3031
if: ${{ needs.changes.outputs.nix-src == 'true' }}
3132
runs-on: ubuntu-latest
@@ -34,17 +35,13 @@ jobs:
3435
uses: actions/checkout@v4
3536
- uses: Swatinem/rust-cache@v2
3637
- uses: cachix/install-nix-action@v30
37-
with:
38-
# This channel is only required to invoke "nix-shell".
39-
# Everything inside that nix-shell will use a pinned version of nixpkgs.
40-
nix_path: nixpkgs=channel:nixpkgs-unstable
4138
# Dedicated step to separate all the
4239
# "copying path '/nix/store/...' from 'https://cache.nixos.org'."
43-
# messages from the actual build output. This job takes ~60secs.
40+
# messages from the actual build output.
4441
- name: Prepare Nix Store
45-
run: nix-shell --pure --run "cargo --version"
42+
run: nix develop --command bash -c "cargo --version"
4643
- name: Run VM tests
4744
run: |
4845
COMMAND="cargo xtask run --target x86_64 --headless --ci --tpm=v1"
49-
echo "Executing in nix shell: $COMMAND"
50-
nix-shell --pure --run "$COMMAND"
46+
echo "Executing in Nix shell: $COMMAND"
47+
nix develop --command bash -c "$COMMAND"

flake.lock

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
description = "uefi-rs";
3+
4+
inputs = {
5+
# We follow the latest stable release of nixpkgs
6+
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
7+
rust-overlay.url = "github:oxalica/rust-overlay";
8+
};
9+
10+
outputs =
11+
inputs@{ self, nixpkgs, ... }:
12+
let
13+
# Systems definition for dev shells and exported packages,
14+
# independent of the NixOS configurations and modules defined here. We
15+
# just use "every system" here to not restrict any user. However, it
16+
# likely happens that certain packages don't build for/under certain
17+
# systems.
18+
systems = nixpkgs.lib.systems.flakeExposed;
19+
forAllSystems =
20+
function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system});
21+
22+
# We directly instantiate the functionality, without using an
23+
# nixpkgs overlay.
24+
# https://github.com/oxalica/rust-overlay/blob/f4d5a693c18b389f0d58f55b6f7be6ef85af186f/docs/reference.md?plain=1#L26
25+
rustToolchain =
26+
pkgs:
27+
let
28+
rust-bin = (inputs.rust-overlay.lib.mkRustBin { }) pkgs;
29+
rustToolchainBuilder = import ./nix/rust-toolchain.nix;
30+
in
31+
rustToolchainBuilder { inherit rust-bin; };
32+
in
33+
{
34+
devShells = forAllSystems (pkgs: {
35+
default = pkgs.mkShell {
36+
packages = with pkgs; [
37+
nixfmt-rfc-style
38+
39+
# Integration test dependencies
40+
swtpm
41+
qemu
42+
43+
# Rust toolchain
44+
(rustToolchain pkgs)
45+
46+
# Other
47+
cargo-llvm-cov
48+
mdbook
49+
yamlfmt
50+
which # used by "cargo xtask fmt"
51+
];
52+
53+
# Set ENV vars.
54+
# OVMF_CODE="${pkgs.OVMF.firmware}";
55+
# OVMF_VARS="${pkgs.OVMF.variables}";
56+
# OVMF_SHELL="${pkgs.edk2-uefi-shell}";
57+
};
58+
});
59+
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
60+
};
61+
}

nix/nixpkgs.nix

-5
This file was deleted.

nix/rust-toolchain.nix

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Returns the Rust toolchain for Nix compliant to the rust-toolchain.toml file
2-
# but without rustup.
1+
# Returns a Rust toolchain for Nix that matches the one from the toolchain file.
32

43
{
54
# Comes from rust-overlay

nix/sources.json

-26
This file was deleted.

0 commit comments

Comments
 (0)