diff --git a/.tack/default.nix b/.tack/default.nix index c37bd56..3678f76 100644 --- a/.tack/default.nix +++ b/.tack/default.nix @@ -1,6 +1,6 @@ # SPDX-License-Identifier: EUPL-1.2 # tack-managed resolver. delete this line to take ownership; tack will leave it alone afterwards. -# tack-resolver: patched tag version signedBy +# tack-resolver: patched patchedDiff tag version signedBy groups archive defaultType nestedGroups topFollows public flakeInputs let inherit (builtins) @@ -8,30 +8,41 @@ let all attrNames attrValues + compareVersions concatMap + concatStringsSep any elem elemAt + fetchGit filter foldl' fromJSON + genericClosure hashFile head intersectAttrs isAttrs isList isString + length listToAttrs mapAttrs match + nixVersion + path pathExists readFile + readFileType removeAttrs + replaceStrings split stringLength substring tail + toFile trace + warn ; validateInputNames = @@ -41,6 +52,41 @@ let else value; + isPinGroup = + entry: + isAttrs entry + && !(entry ? url) + && all isAttrs (attrValues entry) + && any (pin: pin ? url) (attrValues entry); + + flattenInputs = + inputs: + foldl' ( + acc: name: + let + entry = inputs.${name}; + pins = + if isPinGroup entry then + mapAttrs ( + pin: value: + if value ? group then + throw "tack: input '${pin}' sits under [inputs.${name}], so it can't also set group" + else + value // { group = name; } + ) entry + else + { ${name} = entry; }; + clashes = filter (pin: acc ? ${pin}) (attrNames pins); + in + if clashes != [ ] then throw "tack: input '${head clashes}' is defined twice" else acc // pins + ) { } (attrNames inputs); + + pinsOf = + toml: + mapAttrs (_: pin: if pin ? group then (toml.groups or { }).${pin.group} or { } // pin else pin) ( + flattenInputs (toml.inputs or { }) + ); + knownTypes = [ "github" "gitlab" @@ -99,19 +145,182 @@ let treeHash = null; }; + fetchGitAttrs = { + url = null; + ref = null; + rev = null; + narHash = null; + submodules = null; + shallow = null; + allRefs = null; + lfs = null; + verifyCommit = null; + keytype = null; + publicKey = null; + publicKeys = null; + }; + + # recursive NAR hash of an empty file (`file:///dev/null`), used for placeholder flake inputs + emptyFileHash = "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY="; + + # fetchTarball ignores access-tokens, so prefer fetchTree when available, except + # for the public pins tack update marks + fetchLocked = + { + what, + locked, + public ? false, + }: + let + type = locked.type or ""; + host = default: locked.host or default; + verifyCommit = locked.verifyCommit or (locked ? publicKey || locked ? publicKeys); + archiveUrl = { + github = "https://${host "github.com"}/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz"; + gitlab = "https://${host "gitlab.com"}/api/v4/projects/${locked.owner}%2F${locked.repo}/repository/archive.tar.gz?sha=${locked.rev}"; + sourcehut = "https://${host "git.sr.ht"}/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz"; + }; + revInfo = + if locked ? rev then + { + inherit (locked) rev; + shortRev = substring 0 7 locked.rev; + } + else + { }; + dateInfo = + if locked ? lastModified then + { + inherit (locked) lastModified; + lastModifiedDate = formatEpoch locked.lastModified; + } + else + { }; + tarball = url: { + outPath = fetchTarball { + inherit url; + sha256 = locked.narHash; + }; + inherit (locked) narHash; + }; + in + if (locked.narHash or null) == emptyFileHash then + { + outPath = toFile "source" ""; + inherit (locked) narHash; + } + else if + builtins ? fetchTree && !(public && archiveUrl ? ${type} && locked ? rev && locked ? narHash) + then + builtins.fetchTree locked + else if !(locked ? narHash) then + throw "tack: ${what} has no narHash and requires builtins.fetchTree" + else if archiveUrl ? ${type} && locked ? rev then + tarball archiveUrl.${type} // revInfo // dateInfo + else if type == "tarball" then + tarball locked.url // revInfo // dateInfo + else if type == "git" && locked ? rev then + dateInfo + // { + submodules = locked.submodules or false; + } + // removeAttrs (fetchGit ( + removeAttrs (intersectAttrs fetchGitAttrs locked) ( + (if locked.lfs or false then [ ] else [ "lfs" ]) + ++ ( + if verifyCommit then + [ ] + else + [ + "verifyCommit" + "keytype" + "publicKey" + "publicKeys" + ] + ) + ) + # nix 2.20 added exportIgnore and enabled it by default, and lix and older nix reject + # it, lfs and verifyCommit outright. lix reports 2.18.3-lix + // ( + if compareVersions nixVersion "2.20" >= 0 then + { exportIgnore = locked.exportIgnore or false; } + else + { } + ) + // (if locked.allRefs or false then { } else { shallow = locked.shallow or true; }) + )) [ "revCount" ] + // (if locked ? revCount then { inherit (locked) revCount; } else { }) + else if type == "path" && substring 0 1 locked.path == "/" then + { + outPath = path { + inherit (locked) path; + sha256 = locked.narHash; + name = "source"; + }; + inherit (locked) narHash; + lastModified = locked.lastModified or 0; + lastModifiedDate = formatEpoch (locked.lastModified or 0); + } + else + throw "tack: ${what} has type '${type}', which requires builtins.fetchTree"; + call = { overrides ? { }, + # flake `outputs` args; non-placeholder inputs override same-named pins + flakeInputs ? { }, resolverDir ? ./., + pkgs ? null, + system ? builtins.currentSystem or null, + fetch_mode ? null, }: let pins = fromTOML (readFile (resolverDir + "/pins.toml")); lock = fromJSON (readFile (resolverDir + "/pins.lock.json")); declared = - if pins.inputs or { } ? _meta then - throw "tack: '_meta' is reserved by tack, rename that input" + if + any (reserved: pins.inputs or { } ? ${reserved}) [ + "_meta" + "_patched" + "_nested" + ] + then + throw "tack: '_meta', '_patched' and '_nested' are reserved by tack, rename that input" else - pins.inputs or { }; + removeAttrs allPins (attrNames topFollowsRaw); + allPins = pinsOf pins; + topFollowsRaw = listToAttrs ( + concatMap ( + name: + let + pin = allPins.${name}; + in + if !isString (pin.follows or null) then + [ ] + else if attrNames pin != [ "follows" ] then + throw "tack: input '${name}' follows '${pin.follows}', so it can't set any other key or sit in a group" + else + [ + { + inherit name; + value = pin.follows; + } + ] + ) (attrNames allPins) + ); + flattenTarget = + seen: target: + let + path = filter isString (split "/" target); + first = head path; + in + if !isString target || !(topFollowsRaw ? ${first}) then + target + else if elem first seen then + throw "tack: top-level follows loop through ${concatStringsSep " -> " (seen ++ [ first ])}" + else + flattenTarget (seen ++ [ first ]) (concatStringsSep "/" ([ topFollowsRaw.${first} ] ++ tail path)); + topFollows = mapAttrs (name: flattenTarget [ name ]) topFollowsRaw; all_follow_raw = pins.all_follow or { }; # tackOverrides carries this reserved entry across nested resolver boundaries inheritedPolicy = overrides.__tack_policy or { }; @@ -120,7 +329,34 @@ let inheritedOverrideMeta = inheritedPolicy.meta or { }; inheritedOmitted = inheritedPolicy.omitted or [ ]; inheritedOmitLayers = (inheritedPolicy.omit or { }).layers or [ ]; + flakeCandidates = intersectAttrs allPins ( + removeAttrs flakeInputs [ + "self" + "tackOverrides" + ] + ); + isPlaceholder = cand: cand == null || (cand.narHash or null) == emptyFileHash; pinOverrides = removeAttrs overrides [ "__tack_policy" ]; + forcedMode = + let + value = if fetch_mode != null then fetch_mode else inheritedPolicy.fetchMode or null; + in + if + elem value [ + null + "build" + "eval" + ] + then + value + else + throw "tack: fetch_mode must be 'build' or 'eval', got '${toString value}'"; + pinFetchMode = + pin: + if forcedMode != null then + forcedMode + else + pin.fetch_mode or (pins.tack or { }).fetch_mode or "eval"; all_omit_inputs = if !(pins ? omit_inputs) then @@ -179,49 +415,67 @@ let # path nodes are convenience pins, so return the live local path directly # because fetchTree rejects unlocked paths in pure eval + fetchNode = + { + dir, + name, + node, + }: + let + type = node.type or ""; + in + if type == "path" then + { + outPath = if substring 0 1 node.path == "/" then node.path else dir + ("/" + node.path); + lastModified = node.lastModified or 0; + } + // (if node ? narHash then { inherit (node) narHash; } else { }) + # a cold fetcher cache makes fetchTree re-unpack a locked tarball into the + # git cache even when its store path exists, fetchTarball checks the store first + else if type == "tarball" && node ? narHash && node ? lastModified then + { + outPath = fetchTarball { + inherit (node) url; + sha256 = node.narHash; + }; + inherit (node) narHash lastModified; + lastModifiedDate = formatEpoch node.lastModified; + } + // ( + if node ? rev then + { + inherit (node) rev; + shortRev = substring 0 7 node.rev; + } + else + { } + ) + else if !(elem type knownTypes) then + throw "tack: unknown lock type '${type}' for pin '${name}'" + else + # nix's fetchTree downloads a rev again even when tack update added it to + # the store, fetchTarball finds it there + fetchLocked { + what = "pin '${name}'"; + locked = intersectAttrs fetchTreeAttrs node; + public = node.public or false; + }; + fetchPin = name: if !(lock ? ${name}) then throw "tack: pin '${name}' has no lock entry; run tack update" else - let + fetchNode { + dir = resolverDir; + inherit name; node = lock.${name}; - type = node.type or ""; - in - if type == "path" then - { - outPath = if substring 0 1 node.path == "/" then node.path else resolverDir + ("/" + node.path); - lastModified = node.lastModified or 0; - } - // (if node ? narHash then { inherit (node) narHash; } else { }) - # a cold fetcher cache makes fetchTree re-unpack a locked tarball into the - # git cache even when its store path exists, fetchTarball checks the store first - else if type == "tarball" && node ? narHash && node ? lastModified then - { - outPath = fetchTarball { - inherit (node) url; - sha256 = node.narHash; - }; - inherit (node) narHash lastModified; - lastModifiedDate = formatEpoch node.lastModified; - } - // ( - if node ? rev then - { - inherit (node) rev; - shortRev = substring 0 7 node.rev; - } - else - { } - ) - else if !(elem type knownTypes) then - throw "tack: unknown lock type '${type}' for pin '${name}'" - else - fetchTree (intersectAttrs fetchTreeAttrs node); + }; fetchFixed = { name, entry }: let + # tack update adds the file to the store under this name, see fetch_fixed_pin raw = derivation { inherit name; inherit (entry) url; @@ -241,14 +495,51 @@ let in if (entry.unpack or "file") == "tarball" then unpacked.outPath + "/" + name else raw.outPath; - # tack builds patched trees and adds them to the store, so eval only - # fetches a locked path and never builds - fetchPatched = + # lix's builtin:fetchurl requires outputHashAlgo + fetchArchive = + node: + let + raw = derivation { + name = "source-archive"; + url = + { + github = "https://codeload.github.com/${node.owner}/${node.repo}/tar.gz/${node.rev}"; + tarball = node.url; + } + .${node.type}; + builder = "builtin:fetchurl"; + system = "builtin"; + outputHash = node.archive.hash; + outputHashAlgo = "sha256"; + outputHashMode = "flat"; + preferLocalBuild = true; + impureEnvVars = [ + "http_proxy" + "https_proxy" + "ftp_proxy" + "all_proxy" + "no_proxy" + ]; + }; + unpacked = derivation { + name = "source"; + builder = "builtin:unpack-channel"; + system = "builtin"; + src = raw; + channelName = "source"; + outputHash = node.archive.outHash; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + preferLocalBuild = true; + }; + in + unpacked.outPath + "/source"; + + patchedTree = { name, pin }: let - node = lock.${name} or { }; tree = - node.patched + lock.${name}.patched or (throw "tack: pin '${name}' has patches but no patched tree, run tack update ${name}"); vendored = digest: @@ -262,32 +553,283 @@ let current = map (digest: digest.source) tree.patches == pin.patches && all (digest: hashFile "sha256" (vendored digest) == digest.sha256) tree.patches; + in + if current then + tree + else + throw "tack: patches for '${name}' changed since the lock was written, run tack update ${name}"; + + # tack builds patched trees and adds them to the store, so eval only + # fetches a locked path and never builds + fetchPatched = + { name, pin }: + let + node = lock.${name} or { }; + tree = patchedTree { inherit name pin; }; fetched = addErrorContext - "tack: could not read the patched tree of '${name}', run tack materialize ${name}, or tack update ${name} if the lock was edited by hand" - ( - fetchTree ( - { - type = "path"; - inherit (tree) path narHash; - } - // (if tree ? lastModified then { inherit (tree) lastModified; } else { }) - ) - ); + "tack: the patched tree of '${name}' is not in the store, run tack materialize or nix-build .tack -A _patched -o .tack/patched, or tack update ${name} if the lock was edited by hand" + (fetchLocked { + what = "the patched tree of '${name}'"; + locked = { + type = "path"; + inherit (tree) path narHash; + } + // (if tree ? lastModified then { inherit (tree) lastModified; } else { }); + }); in - if !current then - throw "tack: patches for '${name}' changed since the lock was written, run tack update ${name}" + fetched + // ( + if node ? rev then + { + dirtyRev = node.rev + "-dirty"; + dirtyShortRev = substring 0 7 node.rev + "-dirty"; + } + else + { } + ); + + patchTools = + if pkgs != null then + pkgs + else if !(lock ? nixpkgs) then + throw "tack: building patched trees needs a nixpkgs pin, or pass one with nix-build .tack -A _patched --arg pkgs 'import {}'" + else if system == null then + throw "tack: building patched trees needs a system argument in pure eval" else - fetched - // ( - if node ? rev then + import (fetchPin "nixpkgs") { + inherit system; + config = { }; + overlays = [ ]; + }; + + ownPatched = listToAttrs ( + map (name: { + inherit name; + value = buildPatched { + inherit name; + pin = declared.${name}; + }; + }) (filter (name: (declared.${name}.patches or [ ]) != [ ]) (attrNames declared)) + ); + + # pinned projects are read as data, never imported, since their resolvers + # are upstream code + plainName = name: isString name && match "[A-Za-z0-9_+-][A-Za-z0-9._+-]*" name != null; + plainDir = + dir: + isString dir + && match "[A-Za-z0-9_+-][A-Za-z0-9._+-]*(/[A-Za-z0-9_+-][A-Za-z0-9._+-]*)*" dir != null; + sriHash = hash: isString hash && match "sha256-[A-Za-z0-9+/]{43}=" hash != null; + fetchedNode = + node: + isAttrs node + && sriHash (node.narHash or null) + && elem (node.type or "") [ + "github" + "gitlab" + "git" + "tarball" + ]; + # readFileType throws below a symlink + isType = + type: root: relative: + (foldl' + ( + parent: part: + let + path = parent.path + "/${part}"; + in + { + inherit path; + type = if parent.type == "directory" && pathExists path then readFileType path else null; + } + ) + { + path = root; + type = "directory"; + } + (filter (part: isString part && part != "") (split "/" relative)) + ).type == type; + + tackProjectAt = + root: + let + dir = root + "/.tack"; + pinsFile = fromTOML (readFile (dir + "/pins.toml")); + lockFile = fromJSON (readFile (dir + "/pins.lock.json")); + inputs = if isAttrs (pinsFile.inputs or null) then pinsOf pinsFile else { }; + in + if !isType "regular" root ".tack/pins.toml" || !isType "regular" root ".tack/pins.lock.json" then + null + else + { + inherit dir inputs; + lock = if isAttrs lockFile then intersectAttrs inputs lockFile else { }; + }; + + lockedPatch = + project: name: + let + node = project.lock.${name}; + tree = node.patched; + diff = project.dir + "/diffs/${name}.diff"; + in + if !plainName name || !isAttrs (node.patched or null) then + { skip = null; } + else if !fetchedNode node || !sriHash (tree.narHash or null) then + { skip = "its lock entry isn't a locked fetch"; } + else if !isString (tree.diff or null) then + { skip = "its lock predates generated diffs"; } + else if + !isType "regular" project.dir "diffs/${name}.diff" || hashFile "sha256" diff != tree.diff + then + { skip = "diffs/${name}.diff is missing or doesn't match its lock"; } + else + { + inherit diff; + inherit (tree) narHash; + drv = patchDerivation { + upstream = fetchNode { + inherit (project) dir; + inherit name node; + }; + inherit diff; + inherit (tree) narHash; + }; + }; + + pinnedProjects = + project: + concatMap ( + name: + let + pin = project.inputs.${name}; + node = project.lock.${name} or null; + subdir = if pin ? dir then "/" + pin.dir else ""; + patch = lockedPatch project name; + tackHeader = "\ndiff --git \"?a/${ + replaceStrings [ "." "+" ] [ "\\." "\\+" ] (if pin ? dir then pin.dir + "/" else "") + }\\.tack/"; + patchesTack = patch ? drv && length (split tackHeader ("\n" + readFile patch.diff)) > 1; + source = + (fetchNode { + inherit (project) dir; + inherit name node; + }).outPath; + root = source + subdir; + in + if + !plainName name + || !isAttrs pin + || (pin.type or "") == "fixed" + || pin ? dir && !plainDir pin.dir + || !fetchedNode node + then + [ ] + else + [ { - dirtyRev = node.rev + "-dirty"; - dirtyShortRev = substring 0 7 node.rev + "-dirty"; + key = node.narHash + subdir + (if patchesTack then "#patched" else ""); + project = + if patchesTack then + trace "tack: not following the pins of '${name}' in ${project.dir}, its patch rewrites its .tack" null + else if isType "directory" source subdir then + tackProjectAt root + else + null; } + ] + ) (attrNames project.inputs); + + nestedProjects = genericClosure { + startSet = pinnedProjects { + dir = resolverDir; + inputs = declared; + inherit lock; + }; + operator = item: if item.project == null then [ ] else pinnedProjects item.project; + }; + + nestedPatched = listToAttrs ( + concatMap ( + item: + let + inherit (item) project; + build = + name: + let + patch = lockedPatch project name; + in + if patch ? drv then + [ + { + name = "${name}-${replaceStrings [ "/" ] [ "_" ] (substring 7 12 patch.narHash)}"; + value = patch.drv; + } + ] + else if patch.skip == null then + [ ] + else + trace "tack: skipping patched pin '${name}' of ${project.dir}, ${patch.skip}" [ ]; + in + if project == null then [ ] else concatMap build (attrNames project.lock) + ) nestedProjects + ); + + buildPatched = + { name, pin }: + let + tree = patchedTree { inherit name pin; }; + diff = resolverDir + "/diffs/${name}.diff"; + in + patchDerivation { + upstream = fetchPin name; + diff = + if !(tree ? diff) then + throw "tack: the lock has no generated diff for '${name}', run tack update ${name}" + else if !pathExists diff then + throw "tack: diffs/${name}.diff is missing, if this is a flake make sure it is tracked by git (git add .tack/diffs)" + else if hashFile "sha256" diff != tree.diff then + throw "tack: diffs/${name}.diff doesn't match the lock, run tack update ${name}" else - { } + diff; + inherit (tree) narHash; + }; + + # same name and hash as tack's tree, so the same store path + patchDerivation = + { + upstream, + diff, + narHash, + }: + derivation { + name = "source"; + inherit (patchTools.stdenv.buildPlatform) system; + builder = "${patchTools.bash}/bin/bash"; + args = [ + "-euc" + '' + cp -R "$upstream" "$out" + chmod -R u+w "$out" + cd "$out" + if [ -s "$diff" ]; then git apply "$diff"; fi + '' + ]; + PATH = concatStringsSep ":" ( + map (tool: "${tool}/bin") [ + patchTools.coreutils + patchTools.gitMinimal + ] ); + HOME = "/homeless-shelter"; + upstream = upstream.outPath; + inherit diff; + outputHash = narHash; + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + }; metaFields = { github = [ @@ -364,7 +906,13 @@ let ); fetched = if type == "indirect" then intersectAttrs lockedFields (fetchPin name) else { }; in - (metaDefaults.${type} or { }) // intersectAttrs fields entry // fetched // { inherit type; }; + (metaDefaults.${type} or { }) + // intersectAttrs fields entry + // fetched + // intersectAttrs { group = null; } (declared.${name} or { }) + // { + inherit type; + }; resolveFollowMeta = mapAttrs (_: target: selfMeta.${target} or { type = "upstream"; }); @@ -411,9 +959,17 @@ let let # a rule into this pin's own inputs would make that input follow itself prefix = name + "/"; - intoSelf = filter (k: substring 0 (stringLength prefix) all_follow.${k} == prefix) ( - attrNames all_follow - ); + intoSelf = filter ( + k: substring 0 (stringLength prefix) (flattenTarget [ ] all_follow.${k}) == prefix + ) (attrNames all_follow); + local = pin.follows or { }; + sameEdge = filter ( + k: + let + m = match "(flake|tack):(.*)" k; + in + flattenTarget [ ] local.${k} == prefix + (if m == null then k else elemAt m 1) + ) (if isAttrs local then attrNames local else [ ]); in { level = { @@ -426,7 +982,7 @@ let in if m == null then key else elemAt m 1 ) intoSelf; - local = pin.follows or { }; + local = if isAttrs local then removeAttrs local sameEdge else local; localLocation = "inputs.${name}.follows"; excluded = pin.exclude_follow or [ ]; inherited = inheritedFollows; @@ -501,18 +1057,33 @@ let omittedInput = { side, name }: - throw "tack: ${side} input '${name}' was omitted by omit_inputs"; + warn "tack: ${side} input '${name}' was omitted by omit_inputs, ${name} will be null" null; + + # follows paths walk these nodes rather than flake results, since reading a + # result's `inputs` forces its outputs, which may depend on the follower + inputNode = value: { + inherit value; + inputs = mapAttrs (_: inputNode) (value.inputs or { }); + }; # `pin/input/...` walks the inputs that pin was evaluated with, as a flake.nix follows does resolveFollows = mapAttrs ( _: target: let path = filter isString (split "/" target); - pin = self.${head path} or (throw "tack: follows target '${head path}' is not a pin"); + name = head path; + pin = + nodes.${name} or ( + if + any (alias: all_follow.${alias} == name && substring 0 5 alias != "tack:") (attrNames all_follow) + then + throw "tack: all_follow target '${name}' has no lock entry; run tack update" + else + throw "tack: follows target '${name}' is not a pin" + ); in foldl' ( - node: key: - (node.inputs or { }).${key} or (throw "tack: follows target '${target}' has no input '${key}'") + node: key: node.inputs.${key} or (throw "tack: follows target '${target}' has no input '${key}'") ) pin (tail path) ); @@ -593,14 +1164,16 @@ let location = "inherited follows"; }; - followOverridesForSide = + followNodesForSide = { side, policy }: followLayersForSide { inherit side policy; resolve = resolveFollows; - inherited = policy.inherited; + inherited = mapAttrs (_: inputNode) policy.inherited; }; + followOverridesForSide = args: mapAttrs (_: node: node.value) (followNodesForSide args); + followMetaForSide = { side, policy }: followLayersForSide { @@ -642,6 +1215,7 @@ let override = { __tack_policy = { inherit omit omitted meta; + fetchMode = forcedMode; follows = followValues; followMeta = scopedFollowValues "tack" (followMetaForSide { side = "tack"; @@ -712,7 +1286,7 @@ let value; }; - mkCallerInputs = + mkCallerNodes = { upLock, nodeName, @@ -734,10 +1308,10 @@ let name = n; } then - omittedInput { + inputNode (omittedInput { side = "flake"; name = n; - } + }) else if upLock != null then let ref = @@ -745,16 +1319,18 @@ let or (throw "tack: input '${n}' declared but not in flake.lock node '${nodeName}'"); # a lock follows path names the root's input, which may itself be followed or omitted followed = foldl' ( - value: key: - (value.inputs or { }).${key} - or (throw "tack: follows path dead-end: no input '${key}' along ${toString ref}") + node: key: + node.inputs.${key} or (throw "tack: follows path dead-end: no input '${key}' along ${toString ref}") ) rootInputs.${head ref} (tail ref); childName = resolveSpec { inherit upLock; spec = ref; }; childNode = upLock.nodes.${childName}; - childSrc = fetchTree childNode.locked; + childSrc = fetchLocked { + what = "flake.lock node '${childName}'"; + locked = removeAttrs childNode.locked [ "dir" ]; + }; in if isList ref && ref != [ ] then followed @@ -763,10 +1339,19 @@ let inherit upLock rootInputs omit; nodeName = childName; sourceInfo = childSrc; + dir = childNode.locked.dir or null; follows = deepFollows; } + else if childNode.locked ? dir then + inputNode ( + childSrc + // { + outPath = childSrc.outPath + "/" + childNode.locked.dir; + sourceInfo = childSrc; + } + ) else - childSrc + inputNode childSrc else throw "tack: no flake.lock; cannot resolve input '${n}'" ) @@ -808,13 +1393,13 @@ let dir = flakeDir; inherit omit levelFollows deepFollows; }; - flakeLevel = intersectAttrs (raw.inputs or { }) (followOverridesForSide { + flakeLevel = intersectAttrs (raw.inputs or { }) (followNodesForSide { side = "flake"; policy = levelFollows; }); # deep follows pass down raw, so each descendant re-projects per side - callerInputs = mkCallerInputs { + callerNodes = mkCallerNodes { inherit upLock nodeName @@ -824,13 +1409,14 @@ let rawInputs = raw.inputs or { }; levelOverrides = flakeLevel; selfFollowed = levelFollows.selfFollowed or [ ]; - rootInputs = if rootInputs == null then callerInputs else rootInputs; + rootInputs = if rootInputs == null then callerNodes else rootInputs; }; + callerInputs = mapAttrs (_: node: node.value) callerNodes; # upstream declares its outputs forward tackOverrides; a closed `{ self }:` # would throw on the extra kwarg, so forward only when declared extraArgs = - if tackCall.supportsOverrides && tackCall.needed then + if tackCall.supportsOverrides && (tackCall.needed || forcedMode != null) then { tackOverrides = tackCall.overrides; } else { }; @@ -846,13 +1432,17 @@ let ; }); in - result; + { + value = result; + inputs = callerNodes; + }; evalTransitive = { upLock, nodeName, sourceInfo, + dir, follows, omit, rootInputs, @@ -865,7 +1455,7 @@ let omit rootInputs ; - flakeDir = sourceInfo.outPath; + flakeDir = sourceInfo.outPath + (if dir == null then "" else "/" + dir); levelFollows = follows; deepFollows = follows; }; @@ -935,7 +1525,10 @@ let loadPin = { name, pin }: let - pinType = pin.type or (if pin.flake or true then "flake" else "fetch"); + pinType = + pin.type or ( + if pin ? flake then (if pin.flake then "flake" else "fetch") else (pins.tack or { }).type or "flake" + ); omit = omitsFor { inherit name pin; }; follows = checkFollowKeys { follows = pin.follows or { }; @@ -954,15 +1547,16 @@ let ] ( if pinType == "fixed" then - fetchFixed { + inputNode (fetchFixed { inherit name; entry = lock.${name}; - } + }) else let sourceInfo = if (pin.patches or [ ]) == [ ] then fetchPin name else fetchPatched { inherit name pin; }; subdir = if pin ? dir then "/" + pin.dir else ""; + node = lock.${name} or { }; in if pinType == "flake" then evalTopFlake { @@ -973,8 +1567,13 @@ let omit ; } + # archive is only locked for trees without .tack + else if + pinFetchMode pin == "build" && node.archive or null != null && (pin.patches or [ ]) == [ ] + then + inputNode (fetchArchive node + subdir) else - evalFetch { + inputNode (evalFetch { inherit sourceInfo name @@ -982,7 +1581,7 @@ let subdir omit ; - } + }) ); # undeclared lock entries are synthesised into toplevels by auto-dedup @@ -993,7 +1592,9 @@ let value = true; }) (attrValues all_follow) ); - autoNames = filter (n: !(declared ? ${n}) && autoTargets ? ${n}) (attrNames lock); + autoNames = filter (n: !(declared ? ${n}) && !(topFollows ? ${n}) && autoTargets ? ${n}) ( + attrNames lock + ); autoPin = name: let @@ -1011,9 +1612,9 @@ let ; } else - sourceInfo; + inputNode sourceInfo; - self = + baseNodes = (mapAttrs (name: pin: loadPin { inherit name pin; }) declared) // listToAttrs ( map (name: { @@ -1021,10 +1622,29 @@ let value = autoPin name; }) autoNames ) - // pinOverrides; + // resolveFollows topFollows; + + nodes = + baseNodes + // mapAttrs ( + name: cand: if isPlaceholder cand then baseNodes.${name} else inputNode cand + ) flakeCandidates + // mapAttrs (_: inputNode) pinOverrides; + + self = mapAttrs (_: node: node.value) nodes; + + baseMeta = + mapAttrs (name: _: pinMeta name) (removeAttrs self (attrNames pinOverrides ++ attrNames topFollows)) + // mapAttrs (_: target: { + type = "follows"; + follows = target; + }) (removeAttrs topFollows (attrNames pinOverrides)); selfMeta = removeAttrs ( - mapAttrs (name: _: pinMeta name) (removeAttrs self (attrNames pinOverrides)) + baseMeta + // mapAttrs ( + name: cand: if isPlaceholder cand then baseMeta.${name} else { type = "flake"; } + ) flakeCandidates // mapAttrs (name: _: inheritedOverrideMeta.${name} or { type = "upstream"; }) pinOverrides ) inheritedOmitted; in @@ -1038,7 +1658,12 @@ let self // { _meta = selfMeta; - __functor = _: args: call ({ inherit resolverDir; } // args); + _patched = ownPatched // { + _nested = nestedPatched // { + recurseForDerivations = true; + }; + }; + __functor = _: { ... }@args: call ({ inherit resolverDir; } // args); } ) ); diff --git a/.tack/pins.lock.json b/.tack/pins.lock.json index 5d44413..161d00d 100644 --- a/.tack/pins.lock.json +++ b/.tack/pins.lock.json @@ -7,15 +7,16 @@ "type": "github", "owner": "nix-community", "repo": "fenix", - "rev": "44ec3e059cf1631403a0faca34106be5fdb17631", - "narHash": "sha256-uLMpwLKdV5U1966bkbe5DzC+5Gp8O6g+wjydKmih7zQ=", - "lastModified": 1792926139 + "rev": "749fc5aba1d77d304ef39288b12a3d9a426babfc", + "narHash": "sha256-RX7aaHZDNa81QV50y6sYvbpiNeP55HtZX7n1IknnT64=", + "lastModified": 1796064572, + "public": true }, "nixpkgs": { "type": "tarball", - "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1093421.f20cd90e28fe/nixexprs.tar.xz?rev=f20cd90e28fe0403873f473b29e42662cd86e8c4&lastModified=1792116957", - "rev": "f20cd90e28fe0403873f473b29e42662cd86e8c4", - "narHash": "sha256-MTJCMrhDFb+GRbLxBPTp8kB4dDlO+egmQ5qsJgYuaWw=", - "lastModified": 1792116957 + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-27.05pre1132592.d9479961b0aa/nixexprs.tar.xz?lastModified=1795959198&rev=d9479961b0aad699cf4ab2f6b5b4d8751dabeaea", + "rev": "d9479961b0aad699cf4ab2f6b5b4d8751dabeaea", + "narHash": "sha256-5EFZaov0q2rc2+iyo6SZwY8qZcJ/TjB0v9i/UniJoZI=", + "lastModified": 1795959198 } }