From f5f6a98152c7ce76deb4ed5246ebd5836d40c815 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 16 Sep 2026 22:15:07 -0400 Subject: [PATCH] all nuing with versions --- flake.nix | 45 +++++++++++++++++++-------------------------- modules/host.nix | 17 +++++++++++++++++ nu/lib/common.nu | 8 ++++++++ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/flake.nix b/flake.nix index 91e35f8..298e9d5 100644 --- a/flake.nix +++ b/flake.nix @@ -15,22 +15,21 @@ let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; - - # nu/lib/common.nu holds helpers shared by every host-side tool below - # (say/note/ok/warn/die/step/ask/confirm/confirm-word/shquote, - # vsock-ssh-args, run-argv). It's never `use`d at runtime - once a - # script is wrapped into a single file in the Nix store, a relative - # `use` isn't reliably resolvable - so it's concatenated in here - # instead, in front of each tool's own script. nuScript = path: (builtins.readFile ./nu/lib/common.nu) + "\n" + (builtins.readFile path); + 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}-${shortRev}"; in { - nixosModules.default = ./modules/host.nix; + nixosModules.default = { lib, ... }: { + imports = [ ./modules/host.nix ]; + config.services.hermenix.version = lib.mkDefault version; + }; packages.${system} = { - # One-time bootstrap image. See the README: building this needs two - # extra substituter flags so you aren't compiling Determinate Nix - # yourself. hermes-guest-image = nixos-generators.nixosGenerate { inherit system; format = "raw-efi"; @@ -39,12 +38,6 @@ ./guest/common.nix ]; }; - - # The host-side CLI: `hermenix setup` (guided disk/cache/image setup) - # and `hermenix migrate ` (carry over an existing flat - # HERMES_HOME). A Nu script, wrapped so its external dependencies are - # always on PATH regardless of what the host happens to have - # installed. hermenix = pkgs.writers.writeNuBin "hermenix" { makeWrapperArgs = [ @@ -61,15 +54,13 @@ coreutils nix ])) + "--set" + "HERMENIX_VERSION" + version ]; } (nuScript ./nu/hermenix.nu); - # Host-side control of the VM itself (start/stop/console/snapshots/ - # backups) - see nu/hermes-vm.nu. Defaults match - # services.hermenix's own option defaults; modules/host.nix wraps - # this same script with the per-host values baked in via env vars - # instead (see its own writeNuBin calls). hermes-vm = pkgs.writers.writeNuBin "hermes-vm" { makeWrapperArgs = [ @@ -85,14 +76,13 @@ util-linux restic ])) + "--set" + "HERMENIX_VERSION" + version ]; } (nuScript ./nu/hermes-vm.nu); - # Host-side control of Hermes itself, inside the guest (identity, - # config, secrets, gateway service, passthrough to its own `hermes` - # CLI) - see nu/hermes-ctl.nu. Same per-host-defaults/module-override - # relationship as hermes-vm above. hermes-ctl = pkgs.writers.writeNuBin "hermes-ctl" { makeWrapperArgs = [ @@ -106,6 +96,9 @@ gnutar vim ])) + "--set" + "HERMENIX_VERSION" + version ]; } (nuScript ./nu/hermes-ctl.nu); diff --git a/modules/host.nix b/modules/host.nix index 29269f7..6220baf 100644 --- a/modules/host.nix +++ b/modules/host.nix @@ -384,6 +384,17 @@ in default = 77; description = "Host reaches the guest over vsock, so no inbound network path is needed."; }; + + version = mkOption { + type = types.str; + default = "dev"; + description = '' + "YYYY.MM.DD-" reported by hermes-vm/hermes-ctl's + `version` subcommand. Normally supplied for free by this flake's own + `nixosModules.default` (from its git metadata) - the "dev" default + here only shows up if this module is imported some other way. + ''; + }; }; config = mkIf cfg.enable { @@ -837,6 +848,9 @@ in "--set" "HERMES_DISK_BASE_DIR" cfg.disk.baseDir + "--set" + "HERMENIX_VERSION" + cfg.version ]; } ((builtins.readFile ../nu/lib/common.nu) + "\n" + (builtins.readFile ../nu/hermes-vm.nu))) @@ -872,6 +886,9 @@ in "--set" "HERMES_CLI_NAME" cfg.cliName + "--set" + "HERMENIX_VERSION" + cfg.version ]; } ((builtins.readFile ../nu/lib/common.nu) + "\n" + (builtins.readFile ../nu/hermes-ctl.nu))) diff --git a/nu/lib/common.nu b/nu/lib/common.nu index 4f67ea0..2069af7 100644 --- a/nu/lib/common.nu +++ b/nu/lib/common.nu @@ -55,3 +55,11 @@ def vsock-ssh-args [vsock_cid: int, guest_user: string, guest_host: string] { def run-argv [argv: list] { ^($argv | first) ...($argv | skip 1) } + +# --------------------------------------------------------------- version --- + +# HERMENIX_VERSION is baked in at build time (flake.nix / modules/host.nix) +# as "YYYY.MM.DD-" from this repo's own git metadata. "dev" is +# only seen running an unwrapped checkout of the script directly. +def hermenix-version [] { $env.HERMENIX_VERSION? | default "dev" } +def "main version" [] { print (hermenix-version) }