31 lines
1.4 KiB
Nix
31 lines
1.4 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;
|
|
|
|
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;
|
|
};
|
|
in
|
|
if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args )
|
|
else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args)
|