Prepare, configure, and manage Firecracker microVMs in seconds!
virtualization linux microvm firecracker

setup nix flakes

+268
+116
flake.lock
··· 1 + { 2 + "nodes": { 3 + "advisory-db": { 4 + "flake": false, 5 + "locked": { 6 + "lastModified": 1753275806, 7 + "narHash": "sha256-E+Cu/AFVGwoQo4KPgcWmFS9zU7fJgXoK0o25EP3j48g=", 8 + "owner": "rustsec", 9 + "repo": "advisory-db", 10 + "rev": "c62e71ad8c5256ffa3cafbb1a8c687db60869e98", 11 + "type": "github" 12 + }, 13 + "original": { 14 + "owner": "rustsec", 15 + "repo": "advisory-db", 16 + "type": "github" 17 + } 18 + }, 19 + "crane": { 20 + "locked": { 21 + "lastModified": 1753316655, 22 + "narHash": "sha256-tzWa2kmTEN69OEMhxFy+J2oWSvZP5QhEgXp3TROOzl0=", 23 + "owner": "ipetkov", 24 + "repo": "crane", 25 + "rev": "f35a3372d070c9e9ccb63ba7ce347f0634ddf3d2", 26 + "type": "github" 27 + }, 28 + "original": { 29 + "owner": "ipetkov", 30 + "repo": "crane", 31 + "type": "github" 32 + } 33 + }, 34 + "fenix": { 35 + "inputs": { 36 + "nixpkgs": [ 37 + "nixpkgs" 38 + ], 39 + "rust-analyzer-src": [] 40 + }, 41 + "locked": { 42 + "lastModified": 1754030776, 43 + "narHash": "sha256-EA7Qh5OUc3tgYrLHfG7zU6wxltvWsJ0+sFxOcVsbjOY=", 44 + "owner": "nix-community", 45 + "repo": "fenix", 46 + "rev": "451f184de2958f8e725acba046ec10670dd771a1", 47 + "type": "github" 48 + }, 49 + "original": { 50 + "owner": "nix-community", 51 + "repo": "fenix", 52 + "type": "github" 53 + } 54 + }, 55 + "flake-utils": { 56 + "inputs": { 57 + "systems": "systems" 58 + }, 59 + "locked": { 60 + "lastModified": 1731533236, 61 + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", 62 + "owner": "numtide", 63 + "repo": "flake-utils", 64 + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", 65 + "type": "github" 66 + }, 67 + "original": { 68 + "owner": "numtide", 69 + "repo": "flake-utils", 70 + "type": "github" 71 + } 72 + }, 73 + "nixpkgs": { 74 + "locked": { 75 + "lastModified": 1753939845, 76 + "narHash": "sha256-K2ViRJfdVGE8tpJejs8Qpvvejks1+A4GQej/lBk5y7I=", 77 + "owner": "NixOS", 78 + "repo": "nixpkgs", 79 + "rev": "94def634a20494ee057c76998843c015909d6311", 80 + "type": "github" 81 + }, 82 + "original": { 83 + "owner": "NixOS", 84 + "ref": "nixos-unstable", 85 + "repo": "nixpkgs", 86 + "type": "github" 87 + } 88 + }, 89 + "root": { 90 + "inputs": { 91 + "advisory-db": "advisory-db", 92 + "crane": "crane", 93 + "fenix": "fenix", 94 + "flake-utils": "flake-utils", 95 + "nixpkgs": "nixpkgs" 96 + } 97 + }, 98 + "systems": { 99 + "locked": { 100 + "lastModified": 1681028828, 101 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 102 + "owner": "nix-systems", 103 + "repo": "default", 104 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 105 + "type": "github" 106 + }, 107 + "original": { 108 + "owner": "nix-systems", 109 + "repo": "default", 110 + "type": "github" 111 + } 112 + } 113 + }, 114 + "root": "root", 115 + "version": 7 116 + }
+152
flake.nix
··· 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.2.0"; 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 + ]; 150 + }; 151 + }); 152 + }