From 3abc719c76f681def9beb9d211f0ce3b64a907c5 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 4 May 2025 16:19:06 +0200 Subject: [PATCH 1/4] default: use `fetchGit` when in git repository --- default.nix | 30 ++++++++++++++++++------------ outputs.nix | 4 +++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/default.nix b/default.nix index d6c5e01..4fad081 100644 --- a/default.nix +++ b/default.nix @@ -13,19 +13,25 @@ let storePathLength = builtins.stringLength (builtins.toString builtins.storeDir); evaluatingInStore = (builtins.substring 0 storePathLength currentFilePath) == builtins.storeDir; - selfInStore = builtins.path { - path = ./.; - name = "source"; - filter = path: type: - let - selfPath = builtins.dirOf currentFilePath; - gitIgnoreFilters = lib.parseGitignore selfPath path; - result = type != "unknown" - && type != "symlink" - && builtins.baseNameOf path != ".git" - && lib.runGitignoreFilter gitIgnoreFilters path type; - in result; + gitlessSelfInStore = { + outPath = builtins.path { + path = ./.; + name = "source"; + filter = path: type: + let + selfPath = builtins.dirOf currentFilePath; + gitIgnoreFilters = lib.parseGitignore selfPath path; + result = type != "unknown" + && type != "symlink" + && builtins.baseNameOf path != ".git" + && lib.runGitignoreFilter gitIgnoreFilters path type; + in result; + }; }; + gitfullSelfInStore = builtins.fetchGit "file://${builtins.toString ./.}"; + + selfInStore' = builtins.tryEval gitfullSelfInStore; + selfInStore = if selfInStore'.success then selfInStore'.value else gitlessSelfInStore; in if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args ) else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args) diff --git a/outputs.nix b/outputs.nix index 4146c0f..8cc85cc 100644 --- a/outputs.nix +++ b/outputs.nix @@ -1,7 +1,9 @@ { inputsPath ? ./inputs.nix, inputs ? import inputsPath {}, - selfPath ? builtins.toString ./., + selfPath ? { + outPath = builtins.toString ./.; + }, }: let From 09f1929960205a9b35862841fcd6be66101baac8 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 4 May 2025 16:33:38 +0200 Subject: [PATCH 2/4] default: provide a way to check how we've been initialized --- default.nix | 11 +++++++++-- outputs.nix | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 4fad081..998d023 100644 --- a/default.nix +++ b/default.nix @@ -27,11 +27,18 @@ let && lib.runGitignoreFilter gitIgnoreFilters path type; in result; }; + selfMode = "path"; + }; + gitfullSelfInStore = builtins.fetchGit "file://${builtins.toString ./.}" // { + selfMode = "git"; }; - gitfullSelfInStore = builtins.fetchGit "file://${builtins.toString ./.}"; selfInStore' = builtins.tryEval gitfullSelfInStore; selfInStore = if selfInStore'.success then selfInStore'.value else gitlessSelfInStore; in -if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args ) +if !(evaluatingInStore) then { ... }@args: import selfInStore ({ + selfPath = selfInStore // { + selfMode = "store"; + }; +} // args ) else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args) diff --git a/outputs.nix b/outputs.nix index 8cc85cc..b95e04b 100644 --- a/outputs.nix +++ b/outputs.nix @@ -3,6 +3,7 @@ inputs ? import inputsPath {}, selfPath ? { outPath = builtins.toString ./.; + selfMode = "impure"; }, }: From f8a0c6a50c35c75bf2c45902c914378a9960cf4e Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 4 May 2025 16:34:55 +0200 Subject: [PATCH 3/4] default: properly set outPath when evaluating in store --- default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 998d023..9cd1637 100644 --- a/default.nix +++ b/default.nix @@ -37,7 +37,8 @@ let selfInStore = if selfInStore'.success then selfInStore'.value else gitlessSelfInStore; in if !(evaluatingInStore) then { ... }@args: import selfInStore ({ - selfPath = selfInStore // { + selfPath = { + outPath = builtins.toString ./.; selfMode = "store"; }; } // args ) From ee05202f5de8989f74f203635b250c825537dc3e Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 4 May 2025 16:39:18 +0200 Subject: [PATCH 4/4] nixos/nix: add nix-diff --- nix-os/nix.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix-os/nix.nix b/nix-os/nix.nix index 8d4c425..bce75a5 100644 --- a/nix-os/nix.nix +++ b/nix-os/nix.nix @@ -54,6 +54,7 @@ in { nix.package = wrappedNixExecutables false; environment.systemPackages = [ pkgs.nix-output-monitor + pkgs.nix-diff ] ++ lib.map (lib.hiPrio) [ (wrappedNixExecutables true) wrappedNixosExecutables