Files
hermenix/flake.nix
T
2026-09-23 13:24:07 -04:00

141 lines
4.4 KiB
Nix

{
description = "hermenix — Hermes Agent in a self-managing NixOS VM, two-disk btrfs-backed, under hardened QEMU";
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/3";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
devenv = {
url = "github:cachix/devenv";
inputs.nixpkgs.follows = "nixpkgs";
};
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# A nushell test framework, used by nu/tests/. No nixpkgs package exists
# for it, so it's pulled in as a plain source input instead.
nutest = {
url = "github:vyadh/nutest/v1.2.0";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
determinate,
nixos-generators,
devenv,
...
}@inputs:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
nuScript = builtins.concatStringsSep "\n" (
map builtins.readFile [
./nu/lib/common.nu
./nu/lib/guest.nu
./nu/host/setup.nu
./nu/host/migrate.nu
./nu/host/remote.nu
./nu/vm/vm.nu
./nu/ctl/ctl.nu
./nu/hermenix.nu
]
);
gitRev = self.rev or self.dirtyRev or "unknown";
shortRev = if gitRev == "unknown" then "unknown" else builtins.substring 0 7 gitRev;
version =
"${builtins.substring 0 4 self.lastModifiedDate}."
+ "${builtins.substring 4 2 self.lastModifiedDate}."
+ "${builtins.substring 6 2 self.lastModifiedDate}."
+ "${builtins.substring 8 2 self.lastModifiedDate}."
+ "${builtins.substring 10 2 self.lastModifiedDate}-${shortRev}";
in
{
nixosModules.default = { lib, ... }: {
imports = [ ./modules/host.nix ];
config.services.hermenix.version = lib.mkDefault version;
};
packages.${system} = {
hermes-guest-image = nixos-generators.nixosGenerate {
inherit system;
format = "raw-efi";
modules = [
determinate.nixosModules.default
./guest/common.nix
];
};
hermenix = pkgs.writers.writeNuBin "hermenix" {
makeWrapperArgs = [
"--prefix"
"PATH"
":"
(pkgs.lib.makeBinPath (
with pkgs;
[
openssh
socat
gnutar
gnused
btrfs-progs
e2fsprogs
util-linux
restic
coreutils
vim
nix
]
))
"--set"
"HERMENIX_VERSION"
version
];
} nuScript;
hermenix-completions = pkgs.writeTextFile {
name = "hermenix-completions";
destination = "/share/nushell/vendor/autoload/hermenix.nu";
text = builtins.readFile ./nu/completions.nu;
};
default = self.packages.${system}.hermenix;
};
devShells.${system}.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [ ./devenv.nix ];
};
# Never run by an agent — operator/CI only:
# nix build .#checks.x86_64-linux.guest-vm-unbridged --impure -L
# nix build .#checks.x86_64-linux.guest-vm-bridged --impure -L
# nix build .#checks.x86_64-linux.migrate-connections-vm --impure -L
#
# The guest VM tests (guest/vm-tests/) share their node config and
# mode-independent assertions via guest/vm-tests/common.nix; each test
# adds the checks that only apply to its mode. default.nix aggregates
# them into this attrset, which the static network-modes check joins.
checks.${system} =
(import ./guest/vm-tests {
inherit pkgs determinate;
hermenix = self.packages.${system}.hermenix;
})
// {
# No build, no VM boot: evaluates host.nix in both networking modes
# and guest/common.nix, and asserts on the generated rulesets/units.
network-modes = import ./tests/network-modes-check.nix { inherit pkgs; };
};
};
}