From 2aec0c89fda0612d4b239b72a5372dc75f9c7beb Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 23 Jul 2024 13:57:51 +0200 Subject: [PATCH] lock: expose lock.isValid... this is useful to figure out which lock scripts to run in package collections. --- modules/dream2nix/core/lock/default.nix | 4 +++- modules/dream2nix/core/lock/interface.nix | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/dream2nix/core/lock/default.nix b/modules/dream2nix/core/lock/default.nix index ba2ea0cece..be5422795a 100644 --- a/modules/dream2nix/core/lock/default.nix +++ b/modules/dream2nix/core/lock/default.nix @@ -18,6 +18,7 @@ invalidationHashCurrent = l.hashString "sha256" (l.toJSON cfg.invalidationData); invalidationHashLocked = fileContent.invalidationHash or null; + isValid = invalidationHashCurrent == invalidationHashLocked; # script to remove the lock file if no fields are defined removeLockFileScript = config.deps.writePython3Bin "refresh" {} '' @@ -182,7 +183,7 @@ else throw (errorOutdatedField field); loadedContent = - if invalidationHashCurrent != invalidationHashLocked + if !isValid then throw errorOutdated else l.mapAttrs loadField cfg.fields; @@ -217,6 +218,7 @@ in { lock.content = mkLazy loadedContent; + lock.isValid = isValid; lock.lib = {inherit computeFODHash;}; deps = {nixpkgs, ...}: diff --git a/modules/dream2nix/core/lock/interface.nix b/modules/dream2nix/core/lock/interface.nix index 02423f8a19..462f4384ca 100644 --- a/modules/dream2nix/core/lock/interface.nix +++ b/modules/dream2nix/core/lock/interface.nix @@ -83,6 +83,14 @@ in { readOnly = true; }; + isValid = l.mkOption { + type = t.bool; + description = '' + Check whether the current lock file is valid, which means we don't need to lock again. + ''; + readOnly = true; + }; + lib.computeFODHash = l.mkOption { type = t.functionTo t.path; description = ''