Prepare, configure, and manage Firecracker microVMs in seconds!
virtualization
linux
microvm
firecracker
1{
2 description = "FireUp - a command line tool for getting started with Firecracker MicroVMs quickly";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6
7 crane = {
8 url = "github:ipetkov/crane";
9 inputs.nixpkgs.follows = "nixpkgs";
10 };
11
12 fenix = {
13 url = "github:nix-community/fenix";
14 inputs.nixpkgs.follows = "nixpkgs";
15 inputs.rust-analyzer-src.follows = "";
16 };
17
18 flake-utils.url = "github:numtide/flake-utils";
19
20 advisory-db = {
21 url = "github:rustsec/advisory-db";
22 flake = false;
23 };
24 };
25
26 outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
27 flake-utils.lib.eachDefaultSystem (system:
28 let
29 pkgs = import nixpkgs {
30 inherit system;
31 };
32
33 inherit (pkgs) lib;
34
35 craneLib = crane.mkLib pkgs;
36 src = craneLib.cleanCargoSource (craneLib.path ./.);
37
38 # Common arguments can be set here to avoid repeating them later
39 commonArgs = {
40 inherit src;
41
42 pname = "fireup";
43 version = "0.4.1";
44 cargoExtraArgs = "--package=fireup";
45
46 buildInputs = [
47 # Add additional build inputs here
48 pkgs.openssl.dev
49 pkgs.pkg-config
50 pkgs.gnumake
51 pkgs.perl
52 ] ++ lib.optionals pkgs.stdenv.isDarwin [
53 # Additional darwin specific inputs can be set here
54 pkgs.libiconv
55 pkgs.darwin.Security
56 ];
57
58 # Additional environment variables can be set directly
59 # MY_CUSTOM_VAR = "some value";
60 };
61
62 craneLibLLvmTools = craneLib.overrideToolchain
63 (fenix.packages.${system}.complete.withComponents [
64 "cargo"
65 "llvm-tools"
66 "rustc"
67 "rustfmt"
68 ]);
69
70 # Build *just* the cargo dependencies, so we can reuse
71 # all of that work (e.g. via cachix) when running in CI
72 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
73
74 # Build the actual crate itself, reusing the dependency
75 # artifacts from above.
76 fireup = craneLib.buildPackage (commonArgs // {
77 inherit cargoArtifacts;
78 });
79
80 in
81 {
82 checks = {
83 # Build the crate as part of `nix flake check` for convenience
84 inherit fireup;
85
86 # Run clippy (and deny all warnings) on the crate source,
87 # again, resuing the dependency artifacts from above.
88 #
89 # Note that this is done as a separate derivation so that
90 # we can block the CI if there are issues here, but not
91 # prevent downstream consumers from building our crate by itself.
92 fireup-clippy = craneLib.cargoClippy (commonArgs // {
93 inherit cargoArtifacts;
94 cargoClippyExtraArgs = "--all-targets -- --deny warnings";
95 });
96
97 fireup-doc = craneLib.cargoDoc (commonArgs // {
98 inherit cargoArtifacts;
99 });
100
101 # Check formatting
102 fireup-fmt = craneLib.cargoFmt {
103 inherit src;
104 };
105
106 # Audit dependencies
107 fireup-audit = craneLib.cargoAudit {
108 inherit src advisory-db;
109 };
110
111 # Run tests with cargo-nextest
112 # Consider setting `doCheck = false` on `fireup` if you do not want
113 # the tests to run twice
114 fireup-nextest = craneLib.cargoNextest (commonArgs // {
115 inherit cargoArtifacts;
116 partitions = 1;
117 partitionType = "count";
118 });
119 } // lib.optionalAttrs (system == "x86_64-linux") {
120 # NB: cargo-tarpaulin only supports x86_64 systems
121 # Check code coverage (note: this will not upload coverage anywhere)
122 fireup-coverage = craneLib.cargoTarpaulin (commonArgs // {
123 inherit cargoArtifacts;
124 });
125 };
126
127 packages = {
128 default = fireup;
129 fireup-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
130 inherit cargoArtifacts;
131 });
132 };
133
134 apps.default = flake-utils.lib.mkApp {
135 drv = fireup;
136 };
137
138 devShells.default = pkgs.mkShell {
139 inputsFrom = builtins.attrValues self.checks.${system};
140
141 # Additional dev-shell environment variables can be set directly
142 # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
143
144 # Extra inputs can be added here
145 nativeBuildInputs = with pkgs; [
146 cargo
147 rustc
148 rustfmt
149 gcc
150 mosquitto
151 firecracker
152 ];
153 };
154 });
155}