Skip to content

Add flake support#2360

Open
mazunki wants to merge 4 commits intoincludeos:mainfrom
mazunki:flakify
Open

Add flake support#2360
mazunki wants to merge 4 commits intoincludeos:mainfrom
mazunki:flakify

Conversation

@mazunki
Copy link
Contributor

@mazunki mazunki commented Mar 24, 2026

Depends on includeos/vmrunner#49.

This PR adds flake support to IncludeOS, allowing users to build the kernel, and build+run their unikernel through the flake interface. This reduces the pipeline of running the example unikernel to nix run .#example, which handles all the rebuilding.

Furthermore, this allows standalone unikernels to be able to make their own nix run wrappers which will propagate inputs automatically.

There are no changes for non-flake users, and tests are still using the old mechanisms. This support is just added as a convenience, for now. We expose the following:

  • nix build which simply rebuilds IncludeOS
  • nix build .#chainloader will build the chainloader
  • nix build .#example will build the unikernel from ./example/.
  • nix run .#example builds and runs the example unikernel image.
  • nix run . -- ./path/to/result will run boot -j vm.json result.elf.bin from an already built unikernel.

This approach allows us to override inputs both locally and remotely:

  • --override-input vmrunner ~/path/to/vmrunner
  • --override-input vmrunner github:mazunki/vmrunner

And IncludeOS itself doesn't need to be cloned. This "just works": nix run github:mazunki/includeos/flakify#example.

Note that mkUnikernel.nix is largely the same as unikernel.nix, but rewritten in a way that makes sense for flakes. Eventually, I'm not sure it makes sense to keep both.

@mazunki
Copy link
Contributor Author

mazunki commented Mar 24, 2026

For reference, this is a flake.nix I use in a unikernel:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/25.05";
    includeos.url = "github:mazunki/IncludeOS/flakify";
    # includeos.url = "github:includeos/IncludeOS";
    vmrunner.url = "github:mazunki/vmrunner/flakify";
    # vmrunner.url = "github:includeos/vmrunner";

    includeos.inputs.nixpkgs.follows = "nixpkgs";
    includeos.inputs.vmrunner.follows = "vmrunner";
    vmrunner.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = { self, nixpkgs, includeos, vmrunner }:
    let
      system = "x86_64-linux";
      mkUnikernel = includeos.lib.${system}.mkUnikernel;
    in {
      packages.${system}.default = mkUnikernel {
        unikernel = ./src;
        vmrunner = vmrunner.packages.${system}.default;
      };

      apps.${system}.default = {
        type = "app";
        program = "${nixpkgs.legacyPackages.${system}.writeShellScript "run" ''
          set -e
          built=$(nix build --no-link --print-out-paths)
          exec ${includeos.apps.${system}.boot-unikernel.program} "$built" "$@"
        ''}";
      };
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant