From da7cb17f9eec592d2c958f96e27e5b0d017e6897 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 31 May 2025 19:13:33 +0200 Subject: [PATCH] base: stabilize system.build.toplevel.outPath for vmVariant This is done by not depending on the flake itself, allowing the bits of a dirty tree to not affect the hash. This enables equivalence testing with `just eval-vm bob` and checking if the system closure hash changes or not. --- base/nix.nix | 17 +++++++++++------ base/services/auto-upgrade.nix | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/base/nix.nix b/base/nix.nix index a485cdb..5e21fc6 100644 --- a/base/nix.nix +++ b/base/nix.nix @@ -1,4 +1,4 @@ -{ inputs, ... }: +{ lib, config, inputs, ... }: { nix = { gc = { @@ -21,11 +21,16 @@ ** use the same channel the system ** was built with */ - registry = { - "nixpkgs".flake = inputs.nixpkgs; - "nixpkgs-unstable".flake = inputs.nixpkgs-unstable; - "pvv-nix".flake = inputs.self; - }; + registry = lib.mkMerge [ + { + "nixpkgs".flake = inputs.nixpkgs; + "nixpkgs-unstable".flake = inputs.nixpkgs-unstable; + } + # We avoid the reference to self in vmVariant to get a stable system .outPath for equivalence testing + (lib.mkIf (!config.virtualisation.isVmVariant) { + "pvv-nix".flake = inputs.self; + }) + ]; nixPath = [ "nixpkgs=${inputs.nixpkgs}" "unstable=${inputs.nixpkgs-unstable}" diff --git a/base/services/auto-upgrade.nix b/base/services/auto-upgrade.nix index 098d744..8d90b66 100644 --- a/base/services/auto-upgrade.nix +++ b/base/services/auto-upgrade.nix @@ -1,4 +1,4 @@ -{ inputs, pkgs, lib, ... }: +{ config, inputs, pkgs, lib, ... }: let inputUrls = lib.mapAttrs (input: value: value.url) (import "${inputs.self}/flake.nix").inputs; @@ -26,12 +26,14 @@ in # workaround for https://github.com/NixOS/nix/issues/6895 # via https://git.lix.systems/lix-project/lix/issues/400 - environment.etc."current-system-flake-inputs.json".source - = pkgs.writers.writeJSON "flake-inputs.json" ( - lib.flip lib.mapAttrs inputs (name: input: - # inputs.*.sourceInfo sans outPath, since writeJSON will otherwise serialize sourceInfo like a derivation - lib.removeAttrs (input.sourceInfo or {}) [ "outPath" ] - // { store-path = input.outPath; } # comment this line if you don't want to retain a store reference to the flake inputs - ) - ); + environment.etc = lib.mkIf (!config.virtualisation.isVmVariant) { + "current-system-flake-inputs.json".source + = pkgs.writers.writeJSON "flake-inputs.json" ( + lib.flip lib.mapAttrs inputs (name: input: + # inputs.*.sourceInfo sans outPath, since writeJSON will otherwise serialize sourceInfo like a derivation + lib.removeAttrs (input.sourceInfo or {}) [ "outPath" ] + // { store-path = input.outPath; } # comment this line if you don't want to retain a store reference to the flake inputs + ) + ); + }; }