hooks + devenv
This commit is contained in:
1 parent
e07ae98c0b
commit
d47c401013
19 files changed
+956
-280
No files matched your search
@@ -1,3 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
watch_file devenv.nix
|
||||||
|
watch_file flake.nix
|
||||||
|
watch_file flake.lock
|
||||||
|
|
||||||
nix develop --no-pure-eval
|
# devenv needs impure eval (git metadata, DEVENV_ROOT, git-hooks install).
|
||||||
|
use flake . --no-pure-eval
|
||||||
+11
@@ -14,3 +14,14 @@ devenv.local.yaml
|
|||||||
|
|
||||||
# pre-commit
|
# pre-commit
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
|
||||||
|
# Devenv
|
||||||
|
.devenv*
|
||||||
|
devenv.local.nix
|
||||||
|
devenv.local.yaml
|
||||||
|
|
||||||
|
# direnv
|
||||||
|
.direnv
|
||||||
|
|
||||||
|
# pre-commit
|
||||||
|
.pre-commit-config.yaml
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env nu
|
||||||
|
#
|
||||||
|
# bin/test — run the full hermenix CLI test suite (nu/tests/).
|
||||||
|
#
|
||||||
|
# Requires the nutest module on NU_LIB_DIRS, which `nix develop`'s devShell
|
||||||
|
# sets up. For filtering to specific suites/tests, run
|
||||||
|
# `nutest run-tests --path nu/tests --match-tests <pattern>` directly.
|
||||||
|
|
||||||
|
use nutest
|
||||||
|
|
||||||
|
def main [] {
|
||||||
|
let repo_root = ($env.FILE_PWD | path dirname)
|
||||||
|
nutest run-tests --path ($repo_root | path join "nu" "tests") --fail
|
||||||
|
}
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
{ pkgs, inputs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
nu = "${pkgs.nushell}/bin/nu";
|
||||||
|
# nu-check based linter: fails on any file that does not parse.
|
||||||
|
nuCheck = pkgs.writeShellScript "nu-check-all" ''
|
||||||
|
status=0
|
||||||
|
for f in "$@"; do
|
||||||
|
if ! ${nu} --no-config-file -c "exit (if (nu-check --debug '$f') { 0 } else { 1 })"; then
|
||||||
|
echo "nu-check failed: $f" >&2
|
||||||
|
status=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit $status
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = with pkgs; [
|
||||||
|
nushell
|
||||||
|
nufmt
|
||||||
|
nixfmt
|
||||||
|
deadnix
|
||||||
|
statix
|
||||||
|
];
|
||||||
|
|
||||||
|
env.NU_LIB_DIRS = "${inputs.nutest}";
|
||||||
|
|
||||||
|
enterShell = ''
|
||||||
|
echo "Welcome to the Hermenix devshell!"
|
||||||
|
'';
|
||||||
|
|
||||||
|
# ── Formatters / linters ────────────────────────────────────────────────
|
||||||
|
treefmt = {
|
||||||
|
enable = true;
|
||||||
|
config = {
|
||||||
|
programs = {
|
||||||
|
nixfmt.enable = true; # nix formatter
|
||||||
|
deadnix.enable = true; # nix: dead code removal
|
||||||
|
statix.enable = true; # nix: anti-pattern lints
|
||||||
|
};
|
||||||
|
# No upstream treefmt-nix module for nushell, so wire nufmt manually.
|
||||||
|
settings.formatter.nufmt = {
|
||||||
|
command = "${pkgs.nufmt}/bin/nufmt";
|
||||||
|
includes = [ "*.nu" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# ── Git hooks ───────────────────────────────────────────────────────────
|
||||||
|
git-hooks.hooks = {
|
||||||
|
# Formats nix + nushell; package is wired up by the treefmt integration.
|
||||||
|
treefmt.enable = true;
|
||||||
|
|
||||||
|
nu-check = {
|
||||||
|
enable = true;
|
||||||
|
name = "nu-check";
|
||||||
|
description = "Parse-check nushell sources";
|
||||||
|
entry = "${nuCheck}";
|
||||||
|
language = "system";
|
||||||
|
pass_filenames = true;
|
||||||
|
files = "\\.nu$";
|
||||||
|
};
|
||||||
|
|
||||||
|
gen-completions = {
|
||||||
|
enable = true;
|
||||||
|
name = "gen-completions";
|
||||||
|
description = "Regenerate nu/completions.nu from usage blocks";
|
||||||
|
entry = "${nu} nu/gen-completions.nu";
|
||||||
|
language = "system";
|
||||||
|
pass_filenames = false;
|
||||||
|
files = "^nu/(hermenix\\.nu|vm/vm\\.nu|ctl/ctl\\.nu)$";
|
||||||
|
};
|
||||||
|
|
||||||
|
nu-tests = {
|
||||||
|
enable = true;
|
||||||
|
name = "nu-tests";
|
||||||
|
description = "Run the hermenix CLI test suite";
|
||||||
|
entry = "${nu} -I ${inputs.nutest} bin/test";
|
||||||
|
language = "system";
|
||||||
|
pass_filenames = false;
|
||||||
|
files = "^nu/";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Generated
+78
-1
@@ -168,6 +168,22 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-compat_3": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1767039857,
|
||||||
|
"narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": [
|
"nixpkgs-lib": [
|
||||||
@@ -274,6 +290,27 @@
|
|||||||
"url": "https://flakehub.com/f/cachix/git-hooks.nix/0.1.941"
|
"url": "https://flakehub.com/f/cachix/git-hooks.nix/0.1.941"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"git-hooks_2": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat_3",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1789514889,
|
||||||
|
"narHash": "sha256-PFD1nxptCXJyJoiYO1gf/5Vv43yqGpHtMC6LUhl9/pQ=",
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"rev": "59f4ca0d063a1a3ec722c88b51a33004862e5379",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "cachix",
|
||||||
|
"repo": "git-hooks.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nix": {
|
"nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
@@ -471,12 +508,32 @@
|
|||||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
|
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nutest": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1783281957,
|
||||||
|
"narHash": "sha256-IkDGL0yGIapatoaJiqjk+6CALIRe7FF1Pq2/5zHkIqw=",
|
||||||
|
"owner": "vyadh",
|
||||||
|
"repo": "nutest",
|
||||||
|
"rev": "c46af12bc6e3819b95d69f54f35526ca3e5810d6",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "vyadh",
|
||||||
|
"ref": "v1.2.0",
|
||||||
|
"repo": "nutest",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"determinate": "determinate",
|
"determinate": "determinate",
|
||||||
"devenv": "devenv",
|
"devenv": "devenv",
|
||||||
|
"git-hooks": "git-hooks_2",
|
||||||
"nixos-generators": "nixos-generators",
|
"nixos-generators": "nixos-generators",
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3",
|
||||||
|
"nutest": "nutest",
|
||||||
|
"treefmt-nix": "treefmt-nix_2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
@@ -521,6 +578,26 @@
|
|||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"treefmt-nix_2": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1786901030,
|
||||||
|
"narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
@@ -12,23 +12,46 @@
|
|||||||
url = "github:cachix/devenv";
|
url = "github:cachix/devenv";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
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 =
|
outputs =
|
||||||
{ self, nixpkgs, determinate, nixos-generators, devenv, ... }@inputs:
|
{
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
determinate,
|
||||||
|
nixos-generators,
|
||||||
|
devenv,
|
||||||
|
...
|
||||||
|
}@inputs:
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
nuScript = builtins.concatStringsSep "\n" (map builtins.readFile [
|
nuScript = builtins.concatStringsSep "\n" (
|
||||||
./nu/lib/common.nu
|
map builtins.readFile [
|
||||||
./nu/lib/guest.nu
|
./nu/lib/common.nu
|
||||||
./nu/host/setup.nu
|
./nu/lib/guest.nu
|
||||||
./nu/host/migrate.nu
|
./nu/host/setup.nu
|
||||||
./nu/host/remote.nu
|
./nu/host/migrate.nu
|
||||||
./nu/vm/vm.nu
|
./nu/host/remote.nu
|
||||||
./nu/ctl/ctl.nu
|
./nu/vm/vm.nu
|
||||||
./nu/hermenix.nu
|
./nu/ctl/ctl.nu
|
||||||
]);
|
./nu/hermenix.nu
|
||||||
|
]
|
||||||
|
);
|
||||||
gitRev = self.rev or self.dirtyRev or "unknown";
|
gitRev = self.rev or self.dirtyRev or "unknown";
|
||||||
shortRev = if gitRev == "unknown" then "unknown" else builtins.substring 0 7 gitRev;
|
shortRev = if gitRev == "unknown" then "unknown" else builtins.substring 0 7 gitRev;
|
||||||
version =
|
version =
|
||||||
@@ -51,13 +74,14 @@
|
|||||||
./guest/common.nix
|
./guest/common.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
hermenix = pkgs.writers.writeNuBin "hermenix"
|
hermenix = pkgs.writers.writeNuBin "hermenix" {
|
||||||
{
|
makeWrapperArgs = [
|
||||||
makeWrapperArgs = [
|
"--prefix"
|
||||||
"--prefix"
|
"PATH"
|
||||||
"PATH"
|
":"
|
||||||
":"
|
(pkgs.lib.makeBinPath (
|
||||||
(pkgs.lib.makeBinPath (with pkgs; [
|
with pkgs;
|
||||||
|
[
|
||||||
openssh
|
openssh
|
||||||
socat
|
socat
|
||||||
gnutar
|
gnutar
|
||||||
@@ -69,13 +93,13 @@
|
|||||||
coreutils
|
coreutils
|
||||||
vim
|
vim
|
||||||
nix
|
nix
|
||||||
]))
|
]
|
||||||
"--set"
|
))
|
||||||
"HERMENIX_VERSION"
|
"--set"
|
||||||
version
|
"HERMENIX_VERSION"
|
||||||
];
|
version
|
||||||
}
|
];
|
||||||
nuScript;
|
} nuScript;
|
||||||
|
|
||||||
hermenix-completions = pkgs.writeTextFile {
|
hermenix-completions = pkgs.writeTextFile {
|
||||||
name = "hermenix-completions";
|
name = "hermenix-completions";
|
||||||
@@ -88,39 +112,7 @@
|
|||||||
|
|
||||||
devShells.${system}.default = devenv.lib.mkShell {
|
devShells.${system}.default = devenv.lib.mkShell {
|
||||||
inherit inputs pkgs;
|
inherit inputs pkgs;
|
||||||
modules = [{
|
modules = [ ./devenv.nix ];
|
||||||
packages = with pkgs; [
|
|
||||||
nushell
|
|
||||||
nufmt
|
|
||||||
];
|
|
||||||
|
|
||||||
enterShell = ''
|
|
||||||
Welcom to Hermenix DevShell!
|
|
||||||
'';
|
|
||||||
|
|
||||||
git-hooks.hooks = {
|
|
||||||
# Format all .nu files with nufmt.
|
|
||||||
nufmt = {
|
|
||||||
enable = true;
|
|
||||||
name = "nufmt";
|
|
||||||
entry = "${pkgs.nufmt}/bin/nufmt";
|
|
||||||
language = "system";
|
|
||||||
types = [ "file" ];
|
|
||||||
files = "\\.nu$";
|
|
||||||
};
|
|
||||||
|
|
||||||
# Regenerate nu/completions.nu whenever a usage block changes.
|
|
||||||
gen-completions = {
|
|
||||||
enable = true;
|
|
||||||
name = "gen-completions";
|
|
||||||
description = "Regenerate nu/completions.nu from usage blocks";
|
|
||||||
entry = "${pkgs.nushell}/bin/nu nu/gen-completions.nu";
|
|
||||||
language = "system";
|
|
||||||
pass_filenames = false;
|
|
||||||
files = "^nu/(hermenix\\.nu|vm/vm\\.nu|ctl/ctl\\.nu)$";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+80
-26
@@ -1,4 +1,9 @@
|
|||||||
{ config, lib, pkgs, modulesPath, ... }:
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
modulesPath,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
# These must match services.hermenix.* on the host. If you changed the
|
# These must match services.hermenix.* on the host. If you changed the
|
||||||
@@ -17,10 +22,7 @@ let
|
|||||||
# either need a checkout to hold it or get baked into the immutable store
|
# either need a checkout to hold it or get baked into the immutable store
|
||||||
# copy Nix fetches. Falls back to safe defaults (no host cache, no SSH
|
# copy Nix fetches. Falls back to safe defaults (no host cache, no SSH
|
||||||
# access) if it hasn't been created yet.
|
# access) if it hasn't been created yet.
|
||||||
local =
|
local = if builtins.pathExists /etc/hermenix/local.nix then import /etc/hermenix/local.nix else { };
|
||||||
if builtins.pathExists /etc/hermenix/local.nix
|
|
||||||
then import /etc/hermenix/local.nix
|
|
||||||
else { };
|
|
||||||
cachePublicKey = local.cachePublicKey or "";
|
cachePublicKey = local.cachePublicKey or "";
|
||||||
authorizedKeys = local.authorizedKeys or [ ];
|
authorizedKeys = local.authorizedKeys or [ ];
|
||||||
|
|
||||||
@@ -41,11 +43,33 @@ let
|
|||||||
# third-party install script that shells out to some common Unix tool by
|
# third-party install script that shells out to some common Unix tool by
|
||||||
# bare name doesn't trigger another one of these round-trips.
|
# bare name doesn't trigger another one of these round-trips.
|
||||||
hermesInstallDeps = with pkgs; [
|
hermesInstallDeps = with pkgs; [
|
||||||
git curl jq ripgrep fd tree htop
|
git
|
||||||
uv nodejs ffmpeg
|
curl
|
||||||
direnv nix-direnv nix-output-monitor
|
jq
|
||||||
gcc gnumake pkg-config python3 xz
|
ripgrep
|
||||||
bash coreutils gnutar gzip which gnugrep gnused gawk findutils
|
fd
|
||||||
|
tree
|
||||||
|
htop
|
||||||
|
uv
|
||||||
|
nodejs
|
||||||
|
ffmpeg
|
||||||
|
direnv
|
||||||
|
nix-direnv
|
||||||
|
nix-output-monitor
|
||||||
|
gcc
|
||||||
|
gnumake
|
||||||
|
pkg-config
|
||||||
|
python3
|
||||||
|
xz
|
||||||
|
bash
|
||||||
|
coreutils
|
||||||
|
gnutar
|
||||||
|
gzip
|
||||||
|
which
|
||||||
|
gnugrep
|
||||||
|
gnused
|
||||||
|
gawk
|
||||||
|
findutils
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -56,7 +80,12 @@ in
|
|||||||
# driver support for the VM environment itself is needed either way.
|
# driver support for the VM environment itself is needed either way.
|
||||||
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
|
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
|
||||||
boot.initrd.availableKernelModules = [
|
boot.initrd.availableKernelModules = [
|
||||||
"virtio_pci" "virtio_blk" "virtio_scsi" "ahci" "sd_mod" "xhci_pci"
|
"virtio_pci"
|
||||||
|
"virtio_blk"
|
||||||
|
"virtio_scsi"
|
||||||
|
"ahci"
|
||||||
|
"sd_mod"
|
||||||
|
"xhci_pci"
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "hermes";
|
networking.hostName = "hermes";
|
||||||
@@ -76,7 +105,10 @@ in
|
|||||||
device = "/dev/disk/by-label/hermes-state";
|
device = "/dev/disk/by-label/hermes-state";
|
||||||
fsType = "ext4";
|
fsType = "ext4";
|
||||||
neededForBoot = true;
|
neededForBoot = true;
|
||||||
options = [ "defaults" "noatime" ];
|
options = [
|
||||||
|
"defaults"
|
||||||
|
"noatime"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
@@ -88,7 +120,10 @@ in
|
|||||||
# worked out. Use `hermes-ctl reseed` when you actually mean to overwrite.
|
# worked out. Use `hermes-ctl reseed` when you actually mean to overwrite.
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
system.activationScripts.seedHermesState = {
|
system.activationScripts.seedHermesState = {
|
||||||
deps = [ "users" "groups" ];
|
deps = [
|
||||||
|
"users"
|
||||||
|
"groups"
|
||||||
|
];
|
||||||
text = ''
|
text = ''
|
||||||
install -d -o hermes -g hermes -m 0750 ${stateDir}
|
install -d -o hermes -g hermes -m 0750 ${stateDir}
|
||||||
install -d -o hermes -g hermes -m 0750 ${stateDir}/workspace
|
install -d -o hermes -g hermes -m 0750 ${stateDir}/workspace
|
||||||
@@ -141,10 +176,16 @@ in
|
|||||||
systemd.network.networks."10-eth" = {
|
systemd.network.networks."10-eth" = {
|
||||||
matchConfig.Type = "ether";
|
matchConfig.Type = "ether";
|
||||||
address = [ "${guestAddress}/${toString prefixLength}" ];
|
address = [ "${guestAddress}/${toString prefixLength}" ];
|
||||||
routes = [{ Gateway = hostAddress; }];
|
routes = [ { Gateway = hostAddress; } ];
|
||||||
networkConfig.DNS = [ "9.9.9.9" "149.112.112.112" ];
|
networkConfig.DNS = [
|
||||||
|
"9.9.9.9"
|
||||||
|
"149.112.112.112"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
networking.nameservers = [ "9.9.9.9" "149.112.112.112" ];
|
networking.nameservers = [
|
||||||
|
"9.9.9.9"
|
||||||
|
"149.112.112.112"
|
||||||
|
];
|
||||||
|
|
||||||
services.openssh = {
|
services.openssh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -173,12 +214,8 @@ in
|
|||||||
trusted-users = root hermes
|
trusted-users = root hermes
|
||||||
extra-experimental-features = nix-command flakes
|
extra-experimental-features = nix-command flakes
|
||||||
|
|
||||||
extra-substituters = https://cache.flakehub.com${
|
extra-substituters = https://cache.flakehub.com${lib.optionalString useHostCache " http://${hostAddress}:${toString cachePort}"}
|
||||||
lib.optionalString useHostCache " http://${hostAddress}:${toString cachePort}"
|
extra-trusted-public-keys = cache.flakehub.com-3:hJuILl5sVK4iKm86JzgdXW12Y2Hwd5G07qKtHTOcDCM=${lib.optionalString useHostCache " ${cachePublicKey}"}
|
||||||
}
|
|
||||||
extra-trusted-public-keys = cache.flakehub.com-3:hJuILl5sVK4iKm86JzgdXW12Y2Hwd5G07qKtHTOcDCM=${
|
|
||||||
lib.optionalString useHostCache " ${cachePublicKey}"
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Keep enough generations that a bad self-rebuild is one boot-menu entry
|
# Keep enough generations that a bad self-rebuild is one boot-menu entry
|
||||||
@@ -198,7 +235,10 @@ in
|
|||||||
createHome = false; # the state disk is mounted here and seeded above
|
createHome = false; # the state disk is mounted here and seeded above
|
||||||
linger = true;
|
linger = true;
|
||||||
group = "hermes";
|
group = "hermes";
|
||||||
extraGroups = [ "wheel" "systemd-journal" ];
|
extraGroups = [
|
||||||
|
"wheel"
|
||||||
|
"systemd-journal"
|
||||||
|
];
|
||||||
openssh.authorizedKeys.keys = authorizedKeys;
|
openssh.authorizedKeys.keys = authorizedKeys;
|
||||||
};
|
};
|
||||||
users.groups.hermes = { };
|
users.groups.hermes = { };
|
||||||
@@ -243,9 +283,23 @@ in
|
|||||||
programs.nix-ld = {
|
programs.nix-ld = {
|
||||||
enable = true;
|
enable = true;
|
||||||
libraries = with pkgs; [
|
libraries = with pkgs; [
|
||||||
stdenv.cc.cc zlib openssl curl libxml2 libxslt
|
stdenv.cc.cc
|
||||||
glib nss nspr at-spi2-core cups dbus expat
|
zlib
|
||||||
libGL libdrm mesa alsa-lib
|
openssl
|
||||||
|
curl
|
||||||
|
libxml2
|
||||||
|
libxslt
|
||||||
|
glib
|
||||||
|
nss
|
||||||
|
nspr
|
||||||
|
at-spi2-core
|
||||||
|
cups
|
||||||
|
dbus
|
||||||
|
expat
|
||||||
|
libGL
|
||||||
|
libdrm
|
||||||
|
mesa
|
||||||
|
alsa-lib
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -21,7 +21,10 @@
|
|||||||
fileSystems."/boot" = {
|
fileSystems."/boot" = {
|
||||||
device = "/dev/disk/by-label/ESP";
|
device = "/dev/disk/by-label/ESP";
|
||||||
fsType = "vfat";
|
fsType = "vfat";
|
||||||
options = [ "fmask=0077" "dmask=0077" ];
|
options = [
|
||||||
|
"fmask=0077"
|
||||||
|
"dmask=0077"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.loader.systemd-boot.enable = true;
|
boot.loader.systemd-boot.enable = true;
|
||||||
|
|||||||
+290
-166
@@ -1,7 +1,18 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption mkEnableOption mkIf types optionalString;
|
inherit (lib)
|
||||||
|
mkOption
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
types
|
||||||
|
optionalString
|
||||||
|
;
|
||||||
cfg = config.services.hermenix;
|
cfg = config.services.hermenix;
|
||||||
net = cfg.network;
|
net = cfg.network;
|
||||||
|
|
||||||
@@ -34,11 +45,13 @@ let
|
|||||||
|
|
||||||
# Freeze the guest filesystems around a snapshot so it captures a consistent
|
# Freeze the guest filesystems around a snapshot so it captures a consistent
|
||||||
# state rather than the equivalent of pulling the power.
|
# state rather than the equivalent of pulling the power.
|
||||||
qga = verb: pkgs.writeShellScript "hermes-vm-fs${verb}" ''
|
qga =
|
||||||
set -eu
|
verb:
|
||||||
printf '%s' '{"execute":"guest-fs${verb}"}' \
|
pkgs.writeShellScript "hermes-vm-fs${verb}" ''
|
||||||
| ${pkgs.socat}/bin/socat -t2 - UNIX-CONNECT:${runDir}/qga.sock >/dev/null 2>&1 || true
|
set -eu
|
||||||
'';
|
printf '%s' '{"execute":"guest-fs${verb}"}' \
|
||||||
|
| ${pkgs.socat}/bin/socat -t2 - UNIX-CONNECT:${runDir}/qga.sock >/dev/null 2>&1 || true
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.hermenix = {
|
options.services.hermenix = {
|
||||||
@@ -156,7 +169,14 @@ in
|
|||||||
|
|
||||||
keep = mkOption {
|
keep = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [ "--keep-daily" "14" "--keep-weekly" "8" "--keep-monthly" "12" ];
|
default = [
|
||||||
|
"--keep-daily"
|
||||||
|
"14"
|
||||||
|
"--keep-weekly"
|
||||||
|
"8"
|
||||||
|
"--keep-monthly"
|
||||||
|
"12"
|
||||||
|
];
|
||||||
description = "Arguments passed to restic forget.";
|
description = "Arguments passed to restic forget.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -206,21 +226,31 @@ in
|
|||||||
|
|
||||||
lanAccess = mkOption {
|
lanAccess = mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [ { address = "192.168.1.50"; port = 11434; } ];
|
example = [
|
||||||
|
{
|
||||||
|
address = "192.168.1.50";
|
||||||
|
port = 11434;
|
||||||
|
}
|
||||||
|
];
|
||||||
description = ''
|
description = ''
|
||||||
Specific endpoints elsewhere on your network that the guest may reach,
|
Specific endpoints elsewhere on your network that the guest may reach,
|
||||||
punched through the default RFC1918 drop. One entry per service.
|
punched through the default RFC1918 drop. One entry per service.
|
||||||
'';
|
'';
|
||||||
type = types.listOf (types.submodule {
|
type = types.listOf (
|
||||||
options = {
|
types.submodule {
|
||||||
address = mkOption { type = types.str; };
|
options = {
|
||||||
port = mkOption { type = types.port; };
|
address = mkOption { type = types.str; };
|
||||||
proto = mkOption {
|
port = mkOption { type = types.port; };
|
||||||
type = types.enum [ "tcp" "udp" ];
|
proto = mkOption {
|
||||||
default = "tcp";
|
type = types.enum [
|
||||||
|
"tcp"
|
||||||
|
"udp"
|
||||||
|
];
|
||||||
|
default = "tcp";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
hostAccess = mkOption {
|
hostAccess = mkOption {
|
||||||
@@ -230,43 +260,76 @@ in
|
|||||||
Ports on this host itself that the guest may reach. The service must
|
Ports on this host itself that the guest may reach. The service must
|
||||||
also be bound to an address the guest can see - see the README.
|
also be bound to an address the guest can see - see the README.
|
||||||
'';
|
'';
|
||||||
type = types.listOf (types.submodule {
|
type = types.listOf (
|
||||||
options = {
|
types.submodule {
|
||||||
port = mkOption { type = types.port; };
|
options = {
|
||||||
proto = mkOption {
|
port = mkOption { type = types.port; };
|
||||||
type = types.enum [ "tcp" "udp" ];
|
proto = mkOption {
|
||||||
default = "tcp";
|
type = types.enum [
|
||||||
|
"tcp"
|
||||||
|
"udp"
|
||||||
|
];
|
||||||
|
default = "tcp";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
publish = mkOption {
|
publish = mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [ { hostPort = 8080; guestPort = 8080; } ];
|
example = [
|
||||||
|
{
|
||||||
|
hostPort = 8080;
|
||||||
|
guestPort = 8080;
|
||||||
|
}
|
||||||
|
];
|
||||||
description = ''
|
description = ''
|
||||||
Guest ports to publish on the host's uplink, reachable from the wider
|
Guest ports to publish on the host's uplink, reachable from the wider
|
||||||
network. You do not need this to reach the guest from the host itself.
|
network. You do not need this to reach the guest from the host itself.
|
||||||
'';
|
'';
|
||||||
type = types.listOf (types.submodule {
|
type = types.listOf (
|
||||||
options = {
|
types.submodule {
|
||||||
hostPort = mkOption { type = types.port; };
|
options = {
|
||||||
guestPort = mkOption { type = types.port; };
|
hostPort = mkOption { type = types.port; };
|
||||||
proto = mkOption {
|
guestPort = mkOption { type = types.port; };
|
||||||
type = types.enum [ "tcp" "udp" ];
|
proto = mkOption {
|
||||||
default = "tcp";
|
type = types.enum [
|
||||||
|
"tcp"
|
||||||
|
"udp"
|
||||||
|
];
|
||||||
|
default = "tcp";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
});
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
network = {
|
network = {
|
||||||
bridge = mkOption { type = types.str; default = "hermes-br"; };
|
bridge = mkOption {
|
||||||
tapId = mkOption { type = types.str; default = "vm-hermes"; };
|
type = types.str;
|
||||||
mac = mkOption { type = types.str; default = "02:00:00:7e:00:01"; };
|
default = "hermes-br";
|
||||||
hostAddress = mkOption { type = types.str; default = "10.77.0.1"; };
|
};
|
||||||
guestAddress = mkOption { type = types.str; default = "10.77.0.2"; };
|
tapId = mkOption {
|
||||||
prefixLength = mkOption { type = types.int; default = 24; };
|
type = types.str;
|
||||||
|
default = "vm-hermes";
|
||||||
|
};
|
||||||
|
mac = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "02:00:00:7e:00:01";
|
||||||
|
};
|
||||||
|
hostAddress = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "10.77.0.1";
|
||||||
|
};
|
||||||
|
guestAddress = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "10.77.0.2";
|
||||||
|
};
|
||||||
|
prefixLength = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 24;
|
||||||
|
};
|
||||||
externalInterface = mkOption {
|
externalInterface = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
default = null;
|
||||||
@@ -277,7 +340,12 @@ in
|
|||||||
|
|
||||||
passthrough = {
|
passthrough = {
|
||||||
iommu = mkOption {
|
iommu = mkOption {
|
||||||
type = types.nullOr (types.enum [ "intel" "amd" ]);
|
type = types.nullOr (
|
||||||
|
types.enum [
|
||||||
|
"intel"
|
||||||
|
"amd"
|
||||||
|
]
|
||||||
|
);
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Enable IOMMU kernel parameters for your CPU vendor. Required for any
|
Enable IOMMU kernel parameters for your CPU vendor. Required for any
|
||||||
@@ -289,8 +357,14 @@ in
|
|||||||
pci = mkOption {
|
pci = mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [
|
example = [
|
||||||
{ address = "0000:01:00.0"; id = "10de:2204"; }
|
{
|
||||||
{ address = "0000:01:00.1"; id = "10de:1aef"; }
|
address = "0000:01:00.0";
|
||||||
|
id = "10de:2204";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
address = "0000:01:00.1";
|
||||||
|
id = "10de:1aef";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
description = ''
|
description = ''
|
||||||
PCI devices handed to the guest via VFIO. The host loses them
|
PCI devices handed to the guest via VFIO. The host loses them
|
||||||
@@ -304,26 +378,33 @@ in
|
|||||||
initrd, before a host driver can. Strongly recommended for GPUs;
|
initrd, before a host driver can. Strongly recommended for GPUs;
|
||||||
unbinding an active amdgpu or nvidia driver later is unreliable.
|
unbinding an active amdgpu or nvidia driver later is unreliable.
|
||||||
'';
|
'';
|
||||||
type = types.listOf (types.submodule {
|
type = types.listOf (
|
||||||
options = {
|
types.submodule {
|
||||||
address = mkOption {
|
options = {
|
||||||
type = types.str;
|
address = mkOption {
|
||||||
example = "0000:01:00.0";
|
type = types.str;
|
||||||
description = "Full PCI address, as shown by lspci -D.";
|
example = "0000:01:00.0";
|
||||||
|
description = "Full PCI address, as shown by lspci -D.";
|
||||||
|
};
|
||||||
|
id = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "10de:2204";
|
||||||
|
description = "vendor:device, from lspci -nn. Enables early binding.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
id = mkOption {
|
}
|
||||||
type = types.nullOr types.str;
|
);
|
||||||
default = null;
|
|
||||||
example = "10de:2204";
|
|
||||||
description = "vendor:device, from lspci -nn. Enables early binding.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
usb = mkOption {
|
usb = mkOption {
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [ { vendorId = "8087"; productId = "0026"; } ];
|
example = [
|
||||||
|
{
|
||||||
|
vendorId = "8087";
|
||||||
|
productId = "0026";
|
||||||
|
}
|
||||||
|
];
|
||||||
description = ''
|
description = ''
|
||||||
USB devices forwarded to the guest, matched by vendor and product
|
USB devices forwarded to the guest, matched by vendor and product
|
||||||
ID from lsusb. Integrated Bluetooth radios are USB devices and go
|
ID from lsusb. Integrated Bluetooth radios are USB devices and go
|
||||||
@@ -332,12 +413,20 @@ in
|
|||||||
QEMU resolves these at start, so a device that is unplugged when the
|
QEMU resolves these at start, so a device that is unplugged when the
|
||||||
VM boots will not appear later without a restart.
|
VM boots will not appear later without a restart.
|
||||||
'';
|
'';
|
||||||
type = types.listOf (types.submodule {
|
type = types.listOf (
|
||||||
options = {
|
types.submodule {
|
||||||
vendorId = mkOption { type = types.str; example = "046d"; };
|
options = {
|
||||||
productId = mkOption { type = types.str; example = "c52b"; };
|
vendorId = mkOption {
|
||||||
};
|
type = types.str;
|
||||||
});
|
example = "046d";
|
||||||
|
};
|
||||||
|
productId = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "c52b";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -423,7 +512,10 @@ in
|
|||||||
systemd.services.hermes-vm = {
|
systemd.services.hermes-vm = {
|
||||||
description = "Hermes Agent VM";
|
description = "Hermes Agent VM";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" "hermes-vm-tap.service" ];
|
after = [
|
||||||
|
"network-online.target"
|
||||||
|
"hermes-vm-tap.service"
|
||||||
|
];
|
||||||
requires = [ "hermes-vm-tap.service" ];
|
requires = [ "hermes-vm-tap.service" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
|
|
||||||
@@ -451,50 +543,52 @@ in
|
|||||||
StateDirectory = "hermes-vm";
|
StateDirectory = "hermes-vm";
|
||||||
RuntimeDirectoryMode = "0750";
|
RuntimeDirectoryMode = "0750";
|
||||||
|
|
||||||
ExecStart = lib.concatStringsSep " " ([
|
ExecStart = lib.concatStringsSep " " (
|
||||||
"${pkgs.qemu_kvm}/bin/qemu-system-x86_64"
|
[
|
||||||
"-name ${cfg.name}"
|
"${pkgs.qemu_kvm}/bin/qemu-system-x86_64"
|
||||||
"-machine q35,accel=kvm,smm=on"
|
"-name ${cfg.name}"
|
||||||
"-cpu host"
|
"-machine q35,accel=kvm,smm=on"
|
||||||
"-smp ${toString cfg.vcpu}"
|
"-cpu host"
|
||||||
"-m ${toString cfg.mem}"
|
"-smp ${toString cfg.vcpu}"
|
||||||
"-nodefaults"
|
"-m ${toString cfg.mem}"
|
||||||
"-no-user-config"
|
"-nodefaults"
|
||||||
"-display none"
|
"-no-user-config"
|
||||||
"-serial stdio"
|
"-display none"
|
||||||
# QEMU's own seccomp sandbox, everything denied that we don't need.
|
"-serial stdio"
|
||||||
"-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny"
|
# QEMU's own seccomp sandbox, everything denied that we don't need.
|
||||||
# UEFI: firmware read-only, variables per-VM and writable.
|
"-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny"
|
||||||
"-drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}"
|
# UEFI: firmware read-only, variables per-VM and writable.
|
||||||
"-drive if=pflash,format=raw,unit=1,file=${stateDir}/OVMF_VARS.fd"
|
"-drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}"
|
||||||
# System disk: NixOS and the Nix store. Rebuildable, never snapshotted.
|
"-drive if=pflash,format=raw,unit=1,file=${stateDir}/OVMF_VARS.fd"
|
||||||
# aio=threads and a writeback cache because these are files on a
|
# System disk: NixOS and the Nix store. Rebuildable, never snapshotted.
|
||||||
# filesystem, not block devices; aio=native wants the latter.
|
# aio=threads and a writeback cache because these are files on a
|
||||||
"-drive if=none,id=system,format=raw,file=${systemImage},cache=writeback,aio=threads,discard=unmap"
|
# filesystem, not block devices; aio=native wants the latter.
|
||||||
"-device virtio-blk-pci,drive=system"
|
"-drive if=none,id=system,format=raw,file=${systemImage},cache=writeback,aio=threads,discard=unmap"
|
||||||
# State disk: everything irreplaceable. Mounted at /var/lib/hermes.
|
"-device virtio-blk-pci,drive=system"
|
||||||
"-drive if=none,id=state,format=raw,file=${stateImage},cache=writeback,aio=threads,discard=unmap"
|
# State disk: everything irreplaceable. Mounted at /var/lib/hermes.
|
||||||
"-device virtio-blk-pci,drive=state"
|
"-drive if=none,id=state,format=raw,file=${stateImage},cache=writeback,aio=threads,discard=unmap"
|
||||||
# Pre-created tap. vhost=off on purpose: vhost-net would move packet
|
"-device virtio-blk-pci,drive=state"
|
||||||
# handling into the host kernel, which is exactly the surface we are
|
# Pre-created tap. vhost=off on purpose: vhost-net would move packet
|
||||||
# trying not to expose. Costs throughput we do not need.
|
# handling into the host kernel, which is exactly the surface we are
|
||||||
"-netdev tap,id=net0,ifname=${net.tapId},script=no,downscript=no,vhost=off"
|
# trying not to expose. Costs throughput we do not need.
|
||||||
"-device virtio-net-pci,netdev=net0,mac=${net.mac}"
|
"-netdev tap,id=net0,ifname=${net.tapId},script=no,downscript=no,vhost=off"
|
||||||
# Host -> guest management, no network involved.
|
"-device virtio-net-pci,netdev=net0,mac=${net.mac}"
|
||||||
"-device vhost-vsock-pci,guest-cid=${toString cfg.vsockCid}"
|
# Host -> guest management, no network involved.
|
||||||
"-device virtio-rng-pci"
|
"-device vhost-vsock-pci,guest-cid=${toString cfg.vsockCid}"
|
||||||
"-qmp unix:${runDir}/qmp.sock,server=on,wait=off"
|
"-device virtio-rng-pci"
|
||||||
] ++ lib.optionals cfg.disk.quiesce [
|
"-qmp unix:${runDir}/qmp.sock,server=on,wait=off"
|
||||||
"-chardev socket,path=${runDir}/qga.sock,server=on,wait=off,id=qga0"
|
]
|
||||||
"-device virtio-serial-pci"
|
++ lib.optionals cfg.disk.quiesce [
|
||||||
"-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"
|
"-chardev socket,path=${runDir}/qga.sock,server=on,wait=off,id=qga0"
|
||||||
]
|
"-device virtio-serial-pci"
|
||||||
# Passed-through PCI devices. The host cannot use these while the VM
|
"-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"
|
||||||
# is running.
|
]
|
||||||
++ map (d: "-device vfio-pci,host=${d.address}") pt.pci
|
# Passed-through PCI devices. The host cannot use these while the VM
|
||||||
# A USB controller, only if something needs plugging into it.
|
# is running.
|
||||||
++ lib.optional anyUsb "-device qemu-xhci,id=xhci"
|
++ map (d: "-device vfio-pci,host=${d.address}") pt.pci
|
||||||
++ map (u: "-device usb-host,vendorid=0x${u.vendorId},productid=0x${u.productId}") pt.usb
|
# A USB controller, only if something needs plugging into it.
|
||||||
|
++ lib.optional anyUsb "-device qemu-xhci,id=xhci"
|
||||||
|
++ map (u: "-device usb-host,vendorid=0x${u.vendorId},productid=0x${u.productId}") pt.usb
|
||||||
);
|
);
|
||||||
|
|
||||||
ExecStop = stopScript;
|
ExecStop = stopScript;
|
||||||
@@ -530,10 +624,18 @@ in
|
|||||||
RestrictNamespaces = true;
|
RestrictNamespaces = true;
|
||||||
RestrictRealtime = true;
|
RestrictRealtime = true;
|
||||||
RestrictSUIDSGID = true;
|
RestrictSUIDSGID = true;
|
||||||
RestrictAddressFamilies = [ "AF_UNIX" "AF_NETLINK" "AF_VSOCK" ];
|
RestrictAddressFamilies = [
|
||||||
|
"AF_UNIX"
|
||||||
|
"AF_NETLINK"
|
||||||
|
"AF_VSOCK"
|
||||||
|
];
|
||||||
LockPersonality = true;
|
LockPersonality = true;
|
||||||
SystemCallArchitectures = "native";
|
SystemCallArchitectures = "native";
|
||||||
SystemCallFilter = [ "@system-service" "~@resources" "~@obsolete" ];
|
SystemCallFilter = [
|
||||||
|
"@system-service"
|
||||||
|
"~@resources"
|
||||||
|
"~@obsolete"
|
||||||
|
];
|
||||||
# KVM means no JIT, so W^X is safe. If QEMU refuses to start, this is
|
# KVM means no JIT, so W^X is safe. If QEMU refuses to start, this is
|
||||||
# the first thing to flip.
|
# the first thing to flip.
|
||||||
MemoryDenyWriteExecute = true;
|
MemoryDenyWriteExecute = true;
|
||||||
@@ -595,7 +697,8 @@ in
|
|||||||
path = [ pkgs.kmod ];
|
path = [ pkgs.kmod ];
|
||||||
script = ''
|
script = ''
|
||||||
modprobe vfio-pci
|
modprobe vfio-pci
|
||||||
'' + lib.concatMapStrings (d: ''
|
''
|
||||||
|
+ lib.concatMapStrings (d: ''
|
||||||
dev=/sys/bus/pci/devices/${d.address}
|
dev=/sys/bus/pci/devices/${d.address}
|
||||||
if [ ! -e "$dev" ]; then
|
if [ ! -e "$dev" ]; then
|
||||||
echo "${d.address} is not present on this machine" >&2
|
echo "${d.address} is not present on this machine" >&2
|
||||||
@@ -646,7 +749,7 @@ in
|
|||||||
networking.nat = {
|
networking.nat = {
|
||||||
enable = true;
|
enable = true;
|
||||||
internalInterfaces = [ net.bridge ];
|
internalInterfaces = [ net.bridge ];
|
||||||
externalInterface = net.externalInterface;
|
inherit (net) externalInterface;
|
||||||
forwardPorts = map (s: {
|
forwardPorts = map (s: {
|
||||||
sourcePort = s.hostPort;
|
sourcePort = s.hostPort;
|
||||||
destination = "${net.guestAddress}:${toString s.guestPort}";
|
destination = "${net.guestAddress}:${toString s.guestPort}";
|
||||||
@@ -675,33 +778,37 @@ in
|
|||||||
'') cfg.hostAccess;
|
'') cfg.hostAccess;
|
||||||
|
|
||||||
# Order matters here. Allowlists must precede the RFC1918 drop.
|
# Order matters here. Allowlists must precede the RFC1918 drop.
|
||||||
networking.firewall.extraForwardRules =
|
networking.firewall.extraForwardRules = ''
|
||||||
''
|
iifname != "${net.bridge}" accept
|
||||||
iifname != "${net.bridge}" accept
|
ct state established,related accept
|
||||||
ct state established,related accept
|
''
|
||||||
''
|
# Guest reaching named services elsewhere on your network.
|
||||||
# Guest reaching named services elsewhere on your network.
|
+ lib.concatMapStrings (s: ''
|
||||||
+ lib.concatMapStrings (s: ''
|
iifname "${net.bridge}" ip daddr ${s.address} ${s.proto} dport ${toString s.port} accept
|
||||||
iifname "${net.bridge}" ip daddr ${s.address} ${s.proto} dport ${toString s.port} accept
|
'') cfg.lanAccess
|
||||||
'') cfg.lanAccess
|
# Inbound to guest services published on the uplink.
|
||||||
# Inbound to guest services published on the uplink.
|
+ lib.concatMapStrings (s: ''
|
||||||
+ lib.concatMapStrings (s: ''
|
oifname "${net.bridge}" ip daddr ${net.guestAddress} ${s.proto} dport ${toString s.guestPort} accept
|
||||||
oifname "${net.bridge}" ip daddr ${net.guestAddress} ${s.proto} dport ${toString s.guestPort} accept
|
'') cfg.publish
|
||||||
'') cfg.publish
|
+ (
|
||||||
+ (if cfg.allowLan then ''
|
if cfg.allowLan then
|
||||||
iifname "${net.bridge}" accept
|
''
|
||||||
'' else ''
|
iifname "${net.bridge}" accept
|
||||||
iifname "${net.bridge}" ip daddr {
|
''
|
||||||
10.0.0.0/8,
|
else
|
||||||
172.16.0.0/12,
|
''
|
||||||
192.168.0.0/16,
|
iifname "${net.bridge}" ip daddr {
|
||||||
169.254.0.0/16,
|
10.0.0.0/8,
|
||||||
127.0.0.0/8,
|
172.16.0.0/12,
|
||||||
100.64.0.0/10
|
192.168.0.0/16,
|
||||||
} drop
|
169.254.0.0/16,
|
||||||
iifname "${net.bridge}" ip6 daddr { fc00::/7, fe80::/10, ::1/128 } drop
|
127.0.0.0/8,
|
||||||
iifname "${net.bridge}" accept
|
100.64.0.0/10
|
||||||
'');
|
} drop
|
||||||
|
iifname "${net.bridge}" ip6 daddr { fc00::/7, fe80::/10, ::1/128 } drop
|
||||||
|
iifname "${net.bridge}" accept
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
# Host store as a read-only cache for the guest
|
# Host store as a read-only cache for the guest
|
||||||
@@ -723,7 +830,11 @@ in
|
|||||||
# =====================================================================
|
# =====================================================================
|
||||||
systemd.services.hermes-vm-snapshot = mkIf cfg.snapshots.enable {
|
systemd.services.hermes-vm-snapshot = mkIf cfg.snapshots.enable {
|
||||||
description = "Snapshot the Hermes VM state disk";
|
description = "Snapshot the Hermes VM state disk";
|
||||||
path = with pkgs; [ btrfs-progs coreutils socat ];
|
path = with pkgs; [
|
||||||
|
btrfs-progs
|
||||||
|
coreutils
|
||||||
|
socat
|
||||||
|
];
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
script = ''
|
script = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -772,7 +883,12 @@ in
|
|||||||
# =====================================================================
|
# =====================================================================
|
||||||
systemd.services.hermes-vm-backup = mkIf cfg.backup.enable {
|
systemd.services.hermes-vm-backup = mkIf cfg.backup.enable {
|
||||||
description = "Back up Hermes state";
|
description = "Back up Hermes state";
|
||||||
path = with pkgs; [ restic openssh socat gnutar ];
|
path = with pkgs; [
|
||||||
|
restic
|
||||||
|
openssh
|
||||||
|
socat
|
||||||
|
gnutar
|
||||||
|
];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
EnvironmentFile = lib.mkIf (cfg.backup.environmentFile != null) cfg.backup.environmentFile;
|
EnvironmentFile = lib.mkIf (cfg.backup.environmentFile != null) cfg.backup.environmentFile;
|
||||||
@@ -826,18 +942,21 @@ in
|
|||||||
"--prefix"
|
"--prefix"
|
||||||
"PATH"
|
"PATH"
|
||||||
":"
|
":"
|
||||||
(lib.makeBinPath (with pkgs; [
|
(lib.makeBinPath (
|
||||||
openssh
|
with pkgs;
|
||||||
socat
|
[
|
||||||
coreutils
|
openssh
|
||||||
gnutar
|
socat
|
||||||
gnused
|
coreutils
|
||||||
btrfs-progs
|
gnutar
|
||||||
util-linux
|
gnused
|
||||||
restic
|
btrfs-progs
|
||||||
vim
|
util-linux
|
||||||
nix
|
restic
|
||||||
]))
|
vim
|
||||||
|
nix
|
||||||
|
]
|
||||||
|
))
|
||||||
"--set"
|
"--set"
|
||||||
"HERMES_VSOCK_CID"
|
"HERMES_VSOCK_CID"
|
||||||
(toString cfg.vsockCid)
|
(toString cfg.vsockCid)
|
||||||
@@ -858,16 +977,21 @@ in
|
|||||||
cfg.version
|
cfg.version
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
(builtins.concatStringsSep "\n" (map builtins.readFile [
|
(
|
||||||
../nu/lib/common.nu
|
builtins.concatStringsSep "\n" (
|
||||||
../nu/lib/guest.nu
|
map builtins.readFile [
|
||||||
../nu/host/setup.nu
|
../nu/lib/common.nu
|
||||||
../nu/host/migrate.nu
|
../nu/lib/guest.nu
|
||||||
../nu/host/remote.nu
|
../nu/host/setup.nu
|
||||||
../nu/vm/vm.nu
|
../nu/host/migrate.nu
|
||||||
../nu/ctl/ctl.nu
|
../nu/host/remote.nu
|
||||||
../nu/hermenix.nu
|
../nu/vm/vm.nu
|
||||||
])))
|
../nu/ctl/ctl.nu
|
||||||
|
../nu/hermenix.nu
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+30
-25
@@ -117,32 +117,37 @@ def render-header [] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ── main ────────────────────────────────────────────────────────────────
|
# ── main ────────────────────────────────────────────────────────────────
|
||||||
|
#
|
||||||
|
# Guarded so nu/tests/completions_test.nu can `source` this file to reach
|
||||||
|
# the pure parse-usage/render-* functions above without regenerating
|
||||||
|
# nu/completions.nu as a side effect of the test.
|
||||||
|
if not ($env.HERMENIX_TEST_SOURCING? | default false) {
|
||||||
|
let repo_root = $env.FILE_PWD | path dirname
|
||||||
|
let out_file = $repo_root | path join "nu" "completions.nu"
|
||||||
|
let top = parse-usage ($repo_root | path join "nu" "hermenix.nu") "hermenix"
|
||||||
|
let vm = parse-usage ($repo_root | path join "nu" "vm" "vm.nu")
|
||||||
|
let ctl = parse-usage ($repo_root | path join "nu" "ctl" "ctl.nu")
|
||||||
|
|
||||||
let repo_root = $env.FILE_PWD | path dirname
|
if ($top | is-empty) { print -e "warn: no top-level completions found in hermenix.nu" }
|
||||||
let out_file = $repo_root | path join "nu" "completions.nu"
|
if ($vm | is-empty) { print -e "warn: no vm completions found in vm/vm.nu" }
|
||||||
let top = parse-usage ($repo_root | path join "nu" "hermenix.nu") "hermenix"
|
if ($ctl | is-empty) { print -e "warn: no ctl completions found in ctl/ctl.nu" }
|
||||||
let vm = parse-usage ($repo_root | path join "nu" "vm" "vm.nu")
|
|
||||||
let ctl = parse-usage ($repo_root | path join "nu" "ctl" "ctl.nu")
|
|
||||||
|
|
||||||
if ($top | is-empty) { print -e "warn: no top-level completions found in hermenix.nu" }
|
[
|
||||||
if ($vm | is-empty) { print -e "warn: no vm completions found in vm/vm.nu" }
|
(render-header)
|
||||||
if ($ctl | is-empty) { print -e "warn: no ctl completions found in ctl/ctl.nu" }
|
""
|
||||||
|
(render-complete "hermenix top" $top)
|
||||||
|
""
|
||||||
|
(render-complete "hermenix vm" $vm)
|
||||||
|
""
|
||||||
|
(render-complete "hermenix ctl" $ctl)
|
||||||
|
""
|
||||||
|
(render-ctx)
|
||||||
|
""
|
||||||
|
(render-extern)
|
||||||
|
""
|
||||||
|
] | str join "\n" | save -f $out_file
|
||||||
|
|
||||||
[
|
nufmt $out_file
|
||||||
(render-header)
|
|
||||||
""
|
|
||||||
(render-complete "hermenix top" $top)
|
|
||||||
""
|
|
||||||
(render-complete "hermenix vm" $vm)
|
|
||||||
""
|
|
||||||
(render-complete "hermenix ctl" $ctl)
|
|
||||||
""
|
|
||||||
(render-ctx)
|
|
||||||
""
|
|
||||||
(render-extern)
|
|
||||||
""
|
|
||||||
] | str join "\n" | save -f $out_file
|
|
||||||
|
|
||||||
nufmt $out_file
|
print $"wrote ($out_file) [top=($top | length) vm=($vm | length) ctl=($ctl | length)]"
|
||||||
|
}
|
||||||
print $"wrote ($out_file) [top=($top | length) vm=($vm | length) ctl=($ctl | length)]"
|
|
||||||
+2
-1
@@ -56,7 +56,8 @@ def "main migrate" [
|
|||||||
^tar --ignore-failed-read -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
^tar --ignore-failed-read -C $source -cf - . | run-argv ($ssh_base ++ [$"mkdir -p '($dest)' && tar -C '($dest)' -xf -"])
|
||||||
|
|
||||||
step 3 "rewriting stale hostnames in the guest"
|
step 3 "rewriting stale hostnames in the guest"
|
||||||
let sed_expr = 0..(($rewrite_from | length) - 1
|
let last_idx = ($rewrite_from | length) - 1
|
||||||
|
let sed_expr = (0..$last_idx
|
||||||
| each {|i| $"s#($rewrite_from | get $i)#($rewrite_to | get $i)#g" }
|
| each {|i| $"s#($rewrite_from | get $i)#($rewrite_to | get $i)#g" }
|
||||||
| str join "; ")
|
| str join "; ")
|
||||||
for f in $rewrite_files {
|
for f in $rewrite_files {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Reproduces flake.nix's `nuScript` concatenation (flake.nix:22-31) so
|
||||||
|
# cli_smoke_test.nu sees the exact same command tree the real `hermenix`
|
||||||
|
# binary has. Other test files only need a subset of these files (see each
|
||||||
|
# source file's own "Depends on:" header) and source those directly instead
|
||||||
|
# — `source` is parse-time and order-dependent, so pulling in more than a
|
||||||
|
# test needs just adds fragility.
|
||||||
|
#
|
||||||
|
# Keep this list in sync with flake.nix's `nuScript` — if one changes, the
|
||||||
|
# other must too.
|
||||||
|
source ../lib/common.nu
|
||||||
|
source ../lib/guest.nu
|
||||||
|
source ../host/setup.nu
|
||||||
|
source ../host/migrate.nu
|
||||||
|
source ../host/remote.nu
|
||||||
|
source ../vm/vm.nu
|
||||||
|
source ../ctl/ctl.nu
|
||||||
|
source ../hermenix.nu
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source _bundle.nu
|
||||||
|
|
||||||
|
# `source` is a parse-time keyword, so if any subcommand's argument/flag
|
||||||
|
# signature anywhere in the bundle were malformed, sourcing _bundle.nu
|
||||||
|
# above would already have failed before any test here could run. These
|
||||||
|
# tests additionally assert the full dispatch tree ends up registered
|
||||||
|
# under the names the real CLI is invoked with (`hermenix vm ssh` etc.
|
||||||
|
# dispatches to `main vm ssh`), without invoking any subcommand's body —
|
||||||
|
# same "parse only" check GUIDELINES.md recommends doing by hand.
|
||||||
|
|
||||||
|
def command-names [] {
|
||||||
|
scope commands | where name =~ '^main( |$)' | get name
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "top-level subcommands are registered" [] {
|
||||||
|
let names = (command-names)
|
||||||
|
for n in [
|
||||||
|
"main" "main setup" "main migrate" "main remote"
|
||||||
|
"main vm" "main ctl" "main version"
|
||||||
|
] {
|
||||||
|
assert ($n in $names) $"missing top-level command: ($n)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "vm subcommands are registered" [] {
|
||||||
|
let names = (command-names)
|
||||||
|
for n in [
|
||||||
|
"main vm ssh" "main vm console" "main vm start" "main vm stop"
|
||||||
|
"main vm restart" "main vm config" "main vm config-pull"
|
||||||
|
"main vm snapshot" "main vm snapshots" "main vm rollback"
|
||||||
|
"main vm backup" "main vm backups"
|
||||||
|
] {
|
||||||
|
assert ($n in $names) $"missing vm command: ($n)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "ctl subcommands are registered" [] {
|
||||||
|
let names = (command-names)
|
||||||
|
for n in [
|
||||||
|
"main ctl" "main ctl soul" "main ctl memory" "main ctl conf"
|
||||||
|
"main ctl secrets" "main ctl status" "main ctl logs" "main ctl restart"
|
||||||
|
"main ctl units" "main ctl reseed" "main ctl pull"
|
||||||
|
] {
|
||||||
|
assert ($n in $names) $"missing ctl command: ($n)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "vm rollback requires a snapshot argument" [] {
|
||||||
|
let sig = (scope commands | where name == "main vm rollback" | get 0.signatures)
|
||||||
|
assert (($sig | values | first | any {|p| $p.parameter_name == "snapshot"}))
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source ../lib/common.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "shquote passes through a plain string" [] {
|
||||||
|
assert equal (shquote "hello") "'hello'"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "shquote escapes embedded single quotes" [] {
|
||||||
|
assert equal (shquote "it's here") "'it'\\''s here'"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "vsock-ssh-args builds the expected argv" [] {
|
||||||
|
let argv = vsock-ssh-args 77 "hermes" "hermes"
|
||||||
|
assert equal $argv [
|
||||||
|
"ssh"
|
||||||
|
"-o" "ProxyCommand=socat - VSOCK-CONNECT:77:22"
|
||||||
|
"-o" "StrictHostKeyChecking=accept-new"
|
||||||
|
"hermes@hermes"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "hermenix-version defaults to dev when unset" [] {
|
||||||
|
with-env { HERMENIX_VERSION: null } {
|
||||||
|
assert equal (hermenix-version) "dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "hermenix-version passes through when set" [] {
|
||||||
|
with-env { HERMENIX_VERSION: "2026.01.01-abc1234" } {
|
||||||
|
assert equal (hermenix-version) "2026.01.01-abc1234"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
|
||||||
|
# gen-completions.nu is not part of the CLI bundle (nu/tests/_bundle.nu) —
|
||||||
|
# it's a standalone driver script with its own file-writing tail. That tail
|
||||||
|
# is guarded behind HERMENIX_TEST_SOURCING (see gen-completions.nu) so
|
||||||
|
# sourcing it here to reach the pure parse-usage/render-* functions doesn't
|
||||||
|
# regenerate nu/completions.nu as a side effect.
|
||||||
|
$env.HERMENIX_TEST_SOURCING = true
|
||||||
|
source ../gen-completions.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "parse-usage extracts value and description pairs" [] {
|
||||||
|
let tmp = (mktemp)
|
||||||
|
[
|
||||||
|
"def main [] {"
|
||||||
|
' print " setup guided host-side setup"'
|
||||||
|
' print " migrate <source> carry over existing data"'
|
||||||
|
"}"
|
||||||
|
] | str join "\n" | save -f $tmp
|
||||||
|
let result = (parse-usage $tmp)
|
||||||
|
rm $tmp
|
||||||
|
assert equal $result [
|
||||||
|
{ value: "setup", description: "guided host-side setup" }
|
||||||
|
{ value: "migrate", description: "carry over existing data" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "parse-usage strips a prefix and skips passthrough/quoted lines" [] {
|
||||||
|
let tmp = (mktemp)
|
||||||
|
[
|
||||||
|
"def main [] {"
|
||||||
|
' print " hermenix setup guided host-side setup"'
|
||||||
|
' print " hermenix \"example\" skipped, quoted"'
|
||||||
|
"}"
|
||||||
|
] | str join "\n" | save -f $tmp
|
||||||
|
let result = (parse-usage $tmp "hermenix")
|
||||||
|
rm $tmp
|
||||||
|
assert equal $result [
|
||||||
|
{ value: "setup", description: "guided host-side setup" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "render-complete renders a nu-complete def with the given entries" [] {
|
||||||
|
let out = (render-complete "hermenix top" [{ value: "setup", description: "guided host-side setup" }])
|
||||||
|
assert ($out | str contains "nu-complete hermenix top")
|
||||||
|
assert ($out | str contains "setup")
|
||||||
|
assert ($out | str contains "guided host-side setup")
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "render-header documents that the file is generated" [] {
|
||||||
|
let out = (render-header)
|
||||||
|
assert ($out | str contains "GENERATED")
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "render-extern references the context completer" [] {
|
||||||
|
assert equal (render-extern) 'extern "hermenix" [...args: string@"nu-complete hermenix ctx"]'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "render-ctx dispatches on the second word" [] {
|
||||||
|
let out = (render-ctx)
|
||||||
|
assert ($out | str contains "nu-complete hermenix vm")
|
||||||
|
assert ($out | str contains "nu-complete hermenix ctl")
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source ../lib/common.nu
|
||||||
|
source ../lib/guest.nu
|
||||||
|
source ../ctl/ctl.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "home-dir defaults to the vm state disk path" [] {
|
||||||
|
with-env { HERMES_HOME_DIR: null } {
|
||||||
|
assert equal (home-dir) "/var/lib/hermes-vm/.hermes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "home-dir honors HERMES_HOME_DIR" [] {
|
||||||
|
with-env { HERMES_HOME_DIR: "/tmp/.hermes" } {
|
||||||
|
assert equal (home-dir) "/tmp/.hermes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "gateway-unit defaults to hermes-agent" [] {
|
||||||
|
with-env { HERMES_GATEWAY_UNIT: null } {
|
||||||
|
assert equal (gateway-unit) "hermes-agent"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "gateway-unit honors HERMES_GATEWAY_UNIT" [] {
|
||||||
|
with-env { HERMES_GATEWAY_UNIT: "hermes-agent-2" } {
|
||||||
|
assert equal (gateway-unit) "hermes-agent-2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source ../lib/common.nu
|
||||||
|
source ../lib/guest.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "guest-user is always hermes" [] {
|
||||||
|
assert equal (guest-user) "hermes"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "guest-host defaults to hermes" [] {
|
||||||
|
with-env { HERMES_GUEST_NAME: null } {
|
||||||
|
assert equal (guest-host) "hermes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "guest-host honors HERMES_GUEST_NAME" [] {
|
||||||
|
with-env { HERMES_GUEST_NAME: "other-guest" } {
|
||||||
|
assert equal (guest-host) "other-guest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "vsock-cid defaults to 77" [] {
|
||||||
|
with-env { HERMES_VSOCK_CID: null } {
|
||||||
|
assert equal (vsock-cid) 77
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "vsock-cid honors HERMES_VSOCK_CID" [] {
|
||||||
|
with-env { HERMES_VSOCK_CID: "99" } {
|
||||||
|
assert equal (vsock-cid) 99
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "ssh-args composes vsock-ssh-args from guest defaults" [] {
|
||||||
|
with-env { HERMES_GUEST_NAME: null, HERMES_VSOCK_CID: null } {
|
||||||
|
assert equal (ssh-args) (vsock-ssh-args 77 "hermes" "hermes")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source ../lib/common.nu
|
||||||
|
source ../host/setup.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "normalize-size adds G to a bare number" [] {
|
||||||
|
assert equal (normalize-size "80") "80G"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "normalize-size leaves an existing suffix alone" [] {
|
||||||
|
assert equal (normalize-size "80G") "80G"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "normalize-size passes non-numeric input through unchanged" [] {
|
||||||
|
assert equal (normalize-size "lots") "lots"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "normalize-size passes an empty string through unchanged" [] {
|
||||||
|
assert equal (normalize-size "") ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
use std/assert
|
||||||
|
use std/testing *
|
||||||
|
source ../lib/common.nu
|
||||||
|
source ../lib/guest.nu
|
||||||
|
source ../vm/vm.nu
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "disk-base-dir defaults to var-lib path" [] {
|
||||||
|
with-env { HERMES_DISK_BASE_DIR: null } {
|
||||||
|
assert equal (disk-base-dir) "/var/lib/hermes-vm"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "disk-base-dir honors HERMES_DISK_BASE_DIR" [] {
|
||||||
|
with-env { HERMES_DISK_BASE_DIR: "/tmp/hermes-vm" } {
|
||||||
|
assert equal (disk-base-dir) "/tmp/hermes-vm"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
def "snap-dir is a snapshots subdir of disk-base-dir" [] {
|
||||||
|
with-env { HERMES_DISK_BASE_DIR: "/tmp/hermes-vm" } {
|
||||||
|
assert equal (snap-dir) "/tmp/hermes-vm/snapshots"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user