nixos-configuration/default.nix

29 lines
1.3 KiB
Nix
Raw Normal View History

2024-06-17 07:54:59 +02:00
# 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
2025-01-19 18:16:04 +01:00
# 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;
});
2024-06-17 07:54:59 +02:00
currentFilePath = (builtins.unsafeGetAttrPos "any" { any = "any"; }).file;
storePathLength = builtins.stringLength (builtins.toString builtins.storeDir);
evaluatingInStore = (builtins.substring 0 storePathLength currentFilePath) == builtins.storeDir;
selfInStore = builtins.filterSource (path: type:
2025-01-19 18:16:04 +01:00
let
selfPath = builtins.dirOf currentFilePath;
gitIgnoreFilters = lib.parseGitignore selfPath path;
2025-01-19 18:16:04 +01:00
result = type != "unknown"
&& type != "symlink"
&& builtins.baseNameOf path != ".git"
&& lib.runGitignoreFilter gitIgnoreFilters path type;
2025-01-19 18:16:04 +01:00
in result
2024-06-17 07:54:59 +02:00
) ./.;
in
2024-07-07 08:34:47 +02:00
if !(evaluatingInStore) then { ... }@args: import selfInStore ({ selfPath = selfInStore; } // args )
else { ... }@args: import ./outputs.nix ({ selfPath = selfInStore; } // args)