From 2afaae4f5b2e6da95825446d11e46bdf1888afc6 Mon Sep 17 00:00:00 2001 From: DavHau Date: Fri, 25 Feb 2022 15:11:15 +0700 Subject: [PATCH] fix and improve prepareSourceTree --- src/lib/default.nix | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/lib/default.nix b/src/lib/default.nix index 4c34977f..2f3eb9b6 100644 --- a/src/lib/default.nix +++ b/src/lib/default.nix @@ -71,7 +71,7 @@ let if prefix == "" then name else - "${prefix}/name"; + "${prefix}/${name}"; directories = l.mapAttrs @@ -85,19 +85,41 @@ let files = l.mapAttrs - (fname: _: l.trace fname rec { + (fname: _: rec { name = fname; fullPath = "${fullPath'}/${fname}"; - relPath = makeNewPath relPath fname; + relPath = makeNewPath relPath' fname; content = readTextFile fullPath; jsonContent = l.fromJSON content; tomlContent = l.fromTOML content; }) fileNames; + getNodeFromPath = path: + let + pathSplit = l.splitString "/" path; + dirSplit = l.init pathSplit; + leaf = l.last pathSplit; + + dirAttrPath = + l.init + (l.concatMap + (x: [x] ++ ["directories"]) + dirSplit); + + dir = l.getAttrFromPath dirAttrPath directories; + + in + if dir ? directories."${leaf}" then + dir.directories."${leaf}" + else if dir ? files."${leaf}" then + dir.files."${leaf}" + else + throw "could not find file or directory ${path} in ${fullPath'}"; + in { - inherit name files relPath; + inherit files getNodeFromPath name relPath; fullPath = fullPath'; }