nixos-configuration/default.nix
2025-05-04 18:28:06 +02:00

47 lines
1.7 KiB
Nix

# if evaluating outside of the store, copy the current directory to the store and import it
# filtering out .gitignore files and .git directories
# if evaluating inside the store, import the outputs.nix file
let
# Ideally this file should be selfcontained, but I like the utilities in nixpkgs lib
lib = (import "${(import ./inputs.nix {}).nixpkgs}/lib").extend (self: super: {
proot = import ./lib/gitignore-filter.nix { lib = self; };
inherit (self.proot) parseGitignore runGitignoreFilter toGitignoreMatcher;
});
currentFilePath = (builtins.unsafeGetAttrPos "any" { any = "any"; }).file;
storePathLength = builtins.stringLength (builtins.toString builtins.storeDir);
evaluatingInStore = (builtins.substring 0 storePathLength currentFilePath) == builtins.storeDir;
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;
};
selfMode = "path";
};
gitfullSelfInStore = builtins.fetchGit "file://${builtins.toString ./.}" // {
selfMode = "git";
};
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 = {
outPath = builtins.toString ./.;
selfMode = "store";
};
} // args)