From 39aef563bfe5d1ae5e8ef86983243034bd79e384 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 12 Dec 2024 13:28:13 -0700 Subject: [PATCH 01/17] wip: lock format parser --- atom-nix/core/importAtom.nix | 33 ++++++++++++++++++++++++++++++--- atom-nix/core/mod.nix | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index f86ed6f..83087db 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -57,11 +57,11 @@ let fetcher = nix.fetcher or "native"; # native doesn't exist yet conf = config.fetcher or { }; f = conf.${fetcher} or { }; - root = f.root or "npins"; + fetchRoot = f.root or "npins"; in if fetcher == "npins" then let - pins = import (dirOf path + "/${root}"); + pins = import (dirOf path + "/${fetchRoot}"); in mod.filterMap ( k: v: @@ -89,7 +89,34 @@ let ) config.fetch or { } # else if fetcher = "native", etc else - { }; + let + lockPath = "${root}/${src}.lock"; + lock = builtins.fromTOML (builtins.readFile lockPath); + in + if builtins.pathExists lockPath && lock.version == 1 then + builtins.listToAttrs ( + map (dep: { + inherit (dep) name; + value = + let + path = "${root}/${dep.path}@.toml"; + in + if dep ? version && dep ? path && builtins.pathExists path then + (import ./importAtom.nix) { } path + else if dep ? rev then + let + repo = builtins.fetchGit { + inherit (dep) url rev; + shallow = true; + }; + in + import repo + else + { }; + }) lock.deps + ) + else + { }; meta = atom.meta or { }; diff --git a/atom-nix/core/mod.nix b/atom-nix/core/mod.nix index 058ae54..bd9c430 100644 --- a/atom-nix/core/mod.nix +++ b/atom-nix/core/mod.nix @@ -32,6 +32,7 @@ rec { stdFilter stdToml coreToml + importAtom ; path = { From 5b2f8064e2467412eaae8d66ea48cc8790ca4b03 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 12 Dec 2024 14:26:10 -0700 Subject: [PATCH 02/17] feat(lock): import subpath of legacy expression --- atom-nix/core/importAtom.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index 83087db..0abcfc1 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -110,7 +110,7 @@ let shallow = true; }; in - import repo + if dep ? path then import "${repo}/${dep.path}" else import repo else { }; }) lock.deps From f56d90e0b80f4b717ded340b89267987cd83c59c Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 16 Dec 2024 20:16:48 -0700 Subject: [PATCH 03/17] feat(lock): import atoms from published refs The evaluation will prefer a local path, if it exists, to make interactive development in repos with more than one atom convenient. --- atom-nix/core/importAtom.nix | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index 0abcfc1..e2f5cfb 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -96,13 +96,25 @@ let if builtins.pathExists lockPath && lock.version == 1 then builtins.listToAttrs ( map (dep: { - inherit (dep) name; + name = dep.name or dep.id; value = let - path = "${root}/${dep.path}@.toml"; + path = "${root}/${dep.path or dep.id}@.toml"; in - if dep ? version && dep ? path && builtins.pathExists path then - (import ./importAtom.nix) { } path + if dep ? version && dep ? id then + if builtins.pathExists path then + (import ./importAtom.nix) { } path + else + let + spec = baseNameOf path; + in + (import ./importAtom.nix) { } + "${ + (builtins.fetchGit { + inherit (dep) url rev; + ref = "refs/atoms/${dep.id}/${dep.version}/atom"; + }) + }/${spec}" else if dep ? rev then let repo = builtins.fetchGit { From 8af1d42dd5afe02f6ae8dd0693d7bc3425b6d7fd Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 11:56:29 -0600 Subject: [PATCH 04/17] chore(lock): refactor lock code & remove npins --- atom-nix/core/importAtom.nix | 81 +----------------------------------- atom-nix/core/lock.nix | 41 ++++++++++++++++++ 2 files changed, 42 insertions(+), 80 deletions(-) create mode 100644 atom-nix/core/lock.nix diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index e2f5cfb..fe60eb8 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -41,9 +41,6 @@ let in mod.features.resolve featSet featIn; - backend = config.backend or { }; - nix = backend.nix or { }; - root = mod.prepDir (dirOf path); src = builtins.seq id ( let @@ -52,83 +49,7 @@ let in builtins.substring 0 (len - 1) file.name ); - extern = - let - fetcher = nix.fetcher or "native"; # native doesn't exist yet - conf = config.fetcher or { }; - f = conf.${fetcher} or { }; - fetchRoot = f.root or "npins"; - in - if fetcher == "npins" then - let - pins = import (dirOf path + "/${fetchRoot}"); - in - mod.filterMap ( - k: v: - let - src = "${pins.${v.name or k}}/${v.subdir or ""}"; - val = - if v.import or false then - if v.args or [ ] != [ ] then - builtins.foldl' ( - f: x: - let - intersect = x // (builtins.intersectAttrs x extern); - in - if builtins.isAttrs x then f intersect else f x - ) (import src) v.args - else - import src - else - src; - in - if (v.optional or false && builtins.elem k features') || (!v.optional or false) then - { "${k}" = val; } - else - null - ) config.fetch or { } - # else if fetcher = "native", etc - else - let - lockPath = "${root}/${src}.lock"; - lock = builtins.fromTOML (builtins.readFile lockPath); - in - if builtins.pathExists lockPath && lock.version == 1 then - builtins.listToAttrs ( - map (dep: { - name = dep.name or dep.id; - value = - let - path = "${root}/${dep.path or dep.id}@.toml"; - in - if dep ? version && dep ? id then - if builtins.pathExists path then - (import ./importAtom.nix) { } path - else - let - spec = baseNameOf path; - in - (import ./importAtom.nix) { } - "${ - (builtins.fetchGit { - inherit (dep) url rev; - ref = "refs/atoms/${dep.id}/${dep.version}/atom"; - }) - }/${spec}" - else if dep ? rev then - let - repo = builtins.fetchGit { - inherit (dep) url rev; - shallow = true; - }; - in - if dep ? path then import "${repo}/${dep.path}" else import repo - else - { }; - }) lock.deps - ) - else - { }; + extern = import ./lock.nix root src; meta = atom.meta or { }; diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix new file mode 100644 index 0000000..a7d9608 --- /dev/null +++ b/atom-nix/core/lock.nix @@ -0,0 +1,41 @@ +root: src: +let + lockPath = "${root}/${src}.lock"; + lock = builtins.fromTOML (builtins.readFile lockPath); +in +if builtins.pathExists lockPath && lock.version == 1 then + builtins.listToAttrs ( + map (dep: { + name = dep.name or dep.id; + value = + let + path = "${root}/${dep.path or dep.id}@.toml"; + in + if dep ? version && dep ? id then + if builtins.pathExists path then + (import ./importAtom.nix) { } path + else + let + spec = baseNameOf path; + in + (import ./importAtom.nix) { } + "${ + (builtins.fetchGit { + inherit (dep) url rev; + ref = "refs/atoms/${dep.id}/${dep.version}/atom"; + }) + }/${spec}" + else if dep ? rev then + let + repo = builtins.fetchGit { + inherit (dep) url rev; + shallow = true; + }; + in + if dep ? path then import "${repo}/${dep.path}" else import repo + else + { }; + }) lock.deps + ) +else + { } From 7dffe208510d79344cf79fe0fad0efc1ab7c270d Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 16:44:48 -0600 Subject: [PATCH 05/17] fix: align with latest atom crate api update lock parsing code for latest, evolving lock format --- atom-nix/core/importAtom.nix | 4 +++- atom-nix/core/lock.nix | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index fe60eb8..ce782b4 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -17,7 +17,9 @@ */ { features ? null, + remoteUrl ? null, __internal__test ? false, + }: path': let @@ -49,7 +51,7 @@ let in builtins.substring 0 (len - 1) file.name ); - extern = import ./lock.nix root src; + extern = import ./lock.nix root src remoteUrl; meta = atom.meta or { }; diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index a7d9608..716e297 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -1,4 +1,4 @@ -root: src: +root: src: url: let lockPath = "${root}/${src}.lock"; lock = builtins.fromTOML (builtins.readFile lockPath); @@ -11,7 +11,7 @@ if builtins.pathExists lockPath && lock.version == 1 then let path = "${root}/${dep.path or dep.id}@.toml"; in - if dep ? version && dep ? id then + if dep.type == "atom" then if builtins.pathExists path then (import ./importAtom.nix) { } path else @@ -22,17 +22,26 @@ if builtins.pathExists lockPath && lock.version == 1 then "${ (builtins.fetchGit { inherit (dep) url rev; - ref = "refs/atoms/${dep.id}/${dep.version}/atom"; + ref = "refs/eka/atoms/${dep.id}/${dep.version}"; }) }/${spec}" - else if dep ? rev then + else if dep.type == "pin+git" then let repo = builtins.fetchGit { - inherit (dep) url rev; + inherit (dep) rev; + inherit url; shallow = true; }; in - if dep ? path then import "${repo}/${dep.path}" else import repo + import (if dep ? path then "${repo}/${dep.path}" else repo) + else if dep.type == "pin" then + let + fetch = builtins.fetchurl { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + import (if dep ? path then "${fetch}/${dep.path}" else fetch) else { }; }) lock.deps From ed744531d007049256542e9c9243974132c6c760 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 16:48:33 -0600 Subject: [PATCH 06/17] fix: fetch only atoms by remote url variable --- atom-nix/core/lock.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 716e297..c003b2e 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -21,15 +21,15 @@ if builtins.pathExists lockPath && lock.version == 1 then (import ./importAtom.nix) { } "${ (builtins.fetchGit { - inherit (dep) url rev; + inherit (dep) rev; + inherit url; ref = "refs/eka/atoms/${dep.id}/${dep.version}"; }) }/${spec}" else if dep.type == "pin+git" then let repo = builtins.fetchGit { - inherit (dep) rev; - inherit url; + inherit (dep) rev url; shallow = true; }; in From 6a0c19bdb182327abef4d06fb1f5541e27cfe797 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 17:03:04 -0600 Subject: [PATCH 07/17] feat: include tar support for lock files --- atom-nix/core/lock.nix | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index c003b2e..567ed59 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -16,24 +16,32 @@ if builtins.pathExists lockPath && lock.version == 1 then (import ./importAtom.nix) { } path else let - spec = baseNameOf path; + manifest = baseNameOf path; in (import ./importAtom.nix) { } "${ - (builtins.fetchGit { + (fetchGit { inherit (dep) rev; inherit url; ref = "refs/eka/atoms/${dep.id}/${dep.version}"; }) - }/${spec}" + }/${manifest}" else if dep.type == "pin+git" then let - repo = builtins.fetchGit { + repo = fetchGit { inherit (dep) rev url; shallow = true; }; in import (if dep ? path then "${repo}/${dep.path}" else repo) + else if dep.type == "pin+tar" then + let + fetch = fetchTarball { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + import (if dep ? path then "${fetch}/${dep.path}" else fetch) else if dep.type == "pin" then let fetch = builtins.fetchurl { From 8322bf36e0dc2ee93f56a8534c98485246235d27 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 18:43:46 -0600 Subject: [PATCH 08/17] feat: add source time fetching --- atom-nix/core/lock.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 567ed59..061ac8e 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -50,6 +50,14 @@ if builtins.pathExists lockPath && lock.version == 1 then }; in import (if dep ? path then "${fetch}/${dep.path}" else fetch) + else if dep.type == "src" then + let + src = import { + inherit (dep) url; + hash = dep.checksum; + }; + in + src else { }; }) lock.deps From 4274beb6eea9b9f9a751aa43d9ca2e4a5bdf5ace Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 19:07:36 -0600 Subject: [PATCH 09/17] feat(lock): flesh out lock API Separate eval time sources (`from`) from build time sources (`get`) for intuitive and clear API surface. --- atom-nix/core/compose.nix | 3 +- atom-nix/core/lock.nix | 134 ++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 57 deletions(-) diff --git a/atom-nix/core/compose.nix b/atom-nix/core/compose.nix index 5b1b91e..0fc04c9 100644 --- a/atom-nix/core/compose.nix +++ b/atom-nix/core/compose.nix @@ -118,8 +118,7 @@ let __storePath = errors.storePath; __getEnv = errors.getEnv ""; __getFlake = errors.import; - get = extern; - }; + } // extern; scope'' = core.set.inject scope' [ preOpt diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 061ac8e..50ca570 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -4,63 +4,87 @@ let lock = builtins.fromTOML (builtins.readFile lockPath); in if builtins.pathExists lockPath && lock.version == 1 then - builtins.listToAttrs ( - map (dep: { - name = dep.name or dep.id; - value = - let - path = "${root}/${dep.path or dep.id}@.toml"; - in - if dep.type == "atom" then - if builtins.pathExists path then - (import ./importAtom.nix) { } path - else - let - manifest = baseNameOf path; - in - (import ./importAtom.nix) { } - "${ - (fetchGit { - inherit (dep) rev; - inherit url; - ref = "refs/eka/atoms/${dep.id}/${dep.version}"; - }) - }/${manifest}" - else if dep.type == "pin+git" then - let - repo = fetchGit { - inherit (dep) rev url; - shallow = true; - }; - in - import (if dep ? path then "${repo}/${dep.path}" else repo) - else if dep.type == "pin+tar" then - let - fetch = fetchTarball { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - import (if dep ? path then "${fetch}/${dep.path}" else fetch) - else if dep.type == "pin" then - let - fetch = builtins.fetchurl { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - import (if dep ? path then "${fetch}/${dep.path}" else fetch) - else if dep.type == "src" then + let + from = builtins.listToAttrs ( + map (dep: { + name = dep.name or dep.id; + value = let - src = import { - inherit (dep) url; - hash = dep.checksum; - }; + path = "${root}/${dep.path or dep.id}@.toml"; in + if dep.type == "atom" then + if builtins.pathExists path then + (import ./importAtom.nix) { } path + else + let + manifest = baseNameOf path; + in + (import ./importAtom.nix) { } + "${ + (fetchGit { + inherit (dep) rev; + inherit url; + ref = "refs/eka/atoms/${dep.id}/${dep.version}"; + }) + }/${manifest}" + else if dep.type == "pin+git" then + let + repo = fetchGit { + inherit (dep) rev url; + shallow = true; + }; + in + import (if dep ? path then "${repo}/${dep.path}" else repo) + else if dep.type == "pin+tar" then + let + fetch = fetchTarball { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + import (if dep ? path then "${fetch}/${dep.path}" else fetch) + else if dep.type == "pin" then + let + fetch = builtins.fetchurl { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + import (if dep ? path then "${fetch}/${dep.path}" else fetch) + else if dep.type == "src" then + let + src = import { + inherit (dep) url; + hash = dep.checksum; + }; + in src - else - { }; - }) lock.deps - ) + else + { }; + }) lock.deps or [ ] + ); + get = builtins.listToAttrs ( + map (src: { + inherit (src) name; + value = + (builtins.removeAttrs src [ "type" ]) + // ( + if src.type == "src" then + { + src = import { + inherit (src) url; + hash = src.checksum; + }; + } + else + { } + ); + }) lock.srcs or [ ] + ); + + in + { + inherit from get; + } else { } From 599a85a0e6b1da8eca9101fc0ed112d8c06955ff Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 19:13:50 -0600 Subject: [PATCH 10/17] fix!: clarify source type set initial source type to "build" to clarify it is primarily meant for build sources. --- atom-nix/core/lock.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 50ca570..5540c9c 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -65,11 +65,11 @@ if builtins.pathExists lockPath && lock.version == 1 then ); get = builtins.listToAttrs ( map (src: { - inherit (src) name; + name = src.pname or src.name; value = (builtins.removeAttrs src [ "type" ]) // ( - if src.type == "src" then + if src.type == "build" then { src = import { inherit (src) url; From 568552c52f0e209f3978c5af7d686b952117d6e1 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 19 Jul 2025 19:15:30 -0600 Subject: [PATCH 11/17] chore: nixfmt --- atom-nix/core/compose.nix | 31 +++++++++++++++++-------------- atom-nix/std/set/mergeUntil.nix | 10 ++++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/atom-nix/core/compose.nix b/atom-nix/core/compose.nix index 0fc04c9..c43233e 100644 --- a/atom-nix/core/compose.nix +++ b/atom-nix/core/compose.nix @@ -105,20 +105,23 @@ let scope = let - scope' = with core; { - inherit cfg; - mod = modScope; - builtins = std; - import = errors.import; - scopedImport = errors.import; - __fetchurl = errors.fetch; - __currentSystem = errors.system; - __currentTime = errors.time 0; - __nixPath = errors.nixPath [ ]; - __storePath = errors.storePath; - __getEnv = errors.getEnv ""; - __getFlake = errors.import; - } // extern; + scope' = + with core; + { + inherit cfg; + mod = modScope; + builtins = std; + import = errors.import; + scopedImport = errors.import; + __fetchurl = errors.fetch; + __currentSystem = errors.system; + __currentTime = errors.time 0; + __nixPath = errors.nixPath [ ]; + __storePath = errors.storePath; + __getEnv = errors.getEnv ""; + __getFlake = errors.import; + } + // extern; scope'' = core.set.inject scope' [ preOpt diff --git a/atom-nix/std/set/mergeUntil.nix b/atom-nix/std/set/mergeUntil.nix index 0c9b8da..be66e79 100644 --- a/atom-nix/std/set/mergeUntil.nix +++ b/atom-nix/std/set/mergeUntil.nix @@ -69,7 +69,9 @@ let f here values ); in -f [ ] [ - rhs - lhs -] +f + [ ] + [ + rhs + lhs + ] From b7f9f3e70e5fc4299c9ffcb48f75105f28767d75 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 20 Jul 2025 20:02:54 -0600 Subject: [PATCH 12/17] feat(lock): add pin pulling from other atoms Enable pins to source from another atom using a `from` key, avoiding duplicate specs and manual syncing. Support overriding the `path` key as well as using the `get` key to set a different `name` than the downstream pin. Otherwise, it will cook for a pin of the same `name`. --- atom-nix/core/lock.nix | 145 ++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 58 deletions(-) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 5540c9c..1be0ff0 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -2,67 +2,96 @@ root: src: url: let lockPath = "${root}/${src}.lock"; lock = builtins.fromTOML (builtins.readFile lockPath); -in -if builtins.pathExists lockPath && lock.version == 1 then - let - from = builtins.listToAttrs ( + importAtom = import ./importAtom.nix { }; + atomPath = + dep: + let + path = "${root}/${dep.path or dep.id}@.toml"; + in + if builtins.pathExists path then + path + else + let + manifest = baseNameOf path; + in + "${ + (fetchGit { + inherit (dep) rev; + inherit url; + ref = "refs/eka/atoms/${dep.id}/${dep.version}"; + }) + }/${manifest}"; + + depsToSet = + list: + builtins.listToAttrs ( map (dep: { name = dep.name or dep.id; - value = - let - path = "${root}/${dep.path or dep.id}@.toml"; - in - if dep.type == "atom" then - if builtins.pathExists path then - (import ./importAtom.nix) { } path - else - let - manifest = baseNameOf path; - in - (import ./importAtom.nix) { } - "${ - (fetchGit { - inherit (dep) rev; - inherit url; - ref = "refs/eka/atoms/${dep.id}/${dep.version}"; - }) - }/${manifest}" - else if dep.type == "pin+git" then - let - repo = fetchGit { - inherit (dep) rev url; - shallow = true; - }; - in - import (if dep ? path then "${repo}/${dep.path}" else repo) - else if dep.type == "pin+tar" then - let - fetch = fetchTarball { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - import (if dep ? path then "${fetch}/${dep.path}" else fetch) - else if dep.type == "pin" then - let - fetch = builtins.fetchurl { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - import (if dep ? path then "${fetch}/${dep.path}" else fetch) - else if dep.type == "src" then - let - src = import { - inherit (dep) url; - hash = dep.checksum; - }; - in - src - else - { }; - }) lock.deps or [ ] + value = dep; + }) list ); + + deps = depsToSet lock.deps or [ ]; + + importPin = + dep: fetch: + let + fromDeps = depsToSet fromLock.deps or [ ]; + fromAtom = deps.${dep.from}; + fromPath = atomPath fromAtom; + fromLockPath = "${(dirOf fromPath)}/${fromAtom.id}.lock"; + fromLock = builtins.fromTOML (builtins.readFile fromLockPath); + fromName = dep.get or dep.name or ""; + fromDep = fromDeps.${fromName}; + in + if + dep ? from + && fromAtom.type or "" == "atom" + && builtins.pathExists fromLockPath + && fromDeps ? ${fromName} + && builtins.match "^pin.*" fromDep.type != null + then + builtins.traceVerbose "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${src}`" ( + importDep (fromDep // { path = dep.path or fromDep.path or "."; }) + ) + else + import (if dep ? path then "${fetch}/${dep.path}" else fetch); + + importDep = + dep: + if dep.type == "atom" then + importAtom (atomPath dep) + else if dep.type == "pin+git" then + let + repo = fetchGit { + inherit (dep) rev url; + shallow = true; + }; + in + importPin dep repo + else if dep.type == "pin+tar" then + let + fetch = fetchTarball { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + importPin dep fetch + else if dep.type == "pin" then + let + fetch = builtins.fetchurl { + inherit (dep) url; + sha256 = dep.checksum; + }; + in + importPin dep fetch + else + { }; + +in +if builtins.pathExists lockPath && lock.version == 1 then + let + from = builtins.mapAttrs (_: dep: importDep dep) deps; get = builtins.listToAttrs ( map (src: { name = src.pname or src.name; From feb462ac6e43b174f31fd3ca28716357939e06b8 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 20 Jul 2025 20:41:42 -0600 Subject: [PATCH 13/17] fix(lock): minor refactors to clean up a bit --- atom-nix/core/lock.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index 1be0ff0..c69943d 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -13,20 +13,19 @@ let else let manifest = baseNameOf path; - in - "${ - (fetchGit { + fetched = fetchGit { inherit (dep) rev; inherit url; ref = "refs/eka/atoms/${dep.id}/${dep.version}"; - }) - }/${manifest}"; + }; + in + "${fetched}/${manifest}"; depsToSet = list: builtins.listToAttrs ( map (dep: { - name = dep.name or dep.id; + name = dep.name or dep.id or ""; value = dep; }) list ); @@ -51,9 +50,9 @@ let && fromDeps ? ${fromName} && builtins.match "^pin.*" fromDep.type != null then - builtins.traceVerbose "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${src}`" ( - importDep (fromDep // { path = dep.path or fromDep.path or "."; }) - ) + builtins.traceVerbose + "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${src}`" + (importDep (fromDep // { path = dep.path or fromDep.path or "."; })) else import (if dep ? path then "${fetch}/${dep.path}" else fetch); @@ -91,7 +90,7 @@ let in if builtins.pathExists lockPath && lock.version == 1 then let - from = builtins.mapAttrs (_: dep: importDep dep) deps; + from = builtins.mapAttrs (_: importDep) deps; get = builtins.listToAttrs ( map (src: { name = src.pname or src.name; From b5079ecffd59a4a37df456063e5cf22dfc00b750 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 9 Aug 2025 19:41:07 -0600 Subject: [PATCH 14/17] refactor!: change atom import semantics No longer do we import a toml in the same directory as the atom root. In keeping with the spirit of having atoms be truly self-contained, we now parse a generic `atom.toml` file and an `atom.lock` file inside the atom's root directory. --- atom-nix/{core@.toml => core/atom.toml} | 0 atom-nix/core/compose.nix | 5 ++--- atom-nix/core/importAtom.nix | 21 ++++++--------------- atom-nix/core/lock.nix | 15 +++++++-------- atom-nix/core/mod.nix | 4 ++-- atom-nix/{dev@.toml => dev/atom.toml} | 0 atom-nix/{std@.toml => std/atom.toml} | 0 shell.nix | 2 +- 8 files changed, 18 insertions(+), 29 deletions(-) rename atom-nix/{core@.toml => core/atom.toml} (100%) rename atom-nix/{dev@.toml => dev/atom.toml} (100%) rename atom-nix/{std@.toml => std/atom.toml} (100%) diff --git a/atom-nix/core@.toml b/atom-nix/core/atom.toml similarity index 100% rename from atom-nix/core@.toml rename to atom-nix/core/atom.toml diff --git a/atom-nix/core/compose.nix b/atom-nix/core/compose.nix index c43233e..9212920 100644 --- a/atom-nix/core/compose.nix +++ b/atom-nix/core/compose.nix @@ -58,7 +58,6 @@ let core = import ./mod.nix; in { - src, root, config, extern ? { }, @@ -71,12 +70,12 @@ in __isStd__ ? false, }: let - par = (root + "/${src}"); + par = core.prepDir root; std = core.importStd { features = stdFeatures; inherit __internal__test; - } (../. + "/std@.toml"); + } ../std; coreFeatures' = core.features.resolve core.coreToml.features coreFeatures; stdFeatures' = core.features.resolve core.stdToml.features stdFeatures; diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index ce782b4..ab9a881 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -21,17 +21,17 @@ __internal__test ? false, }: -path': +root': let mod = import ./mod.nix; - path = mod.prepDir path'; + root = mod.prepDir root'; - file = builtins.readFile path; + file = builtins.readFile (root + "/atom.toml"); config = builtins.fromTOML file; atom = config.atom or { }; - id = builtins.seq version (atom.id or (mod.errors.missingAtom path' "id")); - version = atom.version or (mod.errors.missingAtom path' "version"); + id = builtins.seq version (atom.id or (mod.errors.missingAtom root' "id")); + version = atom.version or (mod.errors.missingAtom root' "version"); core = config.core or { }; std = config.std or { }; @@ -43,15 +43,7 @@ let in mod.features.resolve featSet featIn; - root = mod.prepDir (dirOf path); - src = builtins.seq id ( - let - file = mod.parse (baseNameOf path); - len = builtins.stringLength file.name; - in - builtins.substring 0 (len - 1) file.name - ); - extern = import ./lock.nix root src remoteUrl; + extern = import ./lock.nix root' id remoteUrl; meta = atom.meta or { }; @@ -62,7 +54,6 @@ mod.compose { __internal__test config root - src ; features = features'; coreFeatures = diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix index c69943d..1537bca 100644 --- a/atom-nix/core/lock.nix +++ b/atom-nix/core/lock.nix @@ -1,25 +1,24 @@ -root: src: url: +root: id: url: let - lockPath = "${root}/${src}.lock"; + lockPath = root + "/atom.lock"; lock = builtins.fromTOML (builtins.readFile lockPath); importAtom = import ./importAtom.nix { }; atomPath = dep: let - path = "${root}/${dep.path or dep.id}@.toml"; + path = root + "/../${dep.path or dep.id}/atom.toml"; in if builtins.pathExists path then - path + dirOf path else let - manifest = baseNameOf path; fetched = fetchGit { inherit (dep) rev; inherit url; ref = "refs/eka/atoms/${dep.id}/${dep.version}"; }; in - "${fetched}/${manifest}"; + fetched; depsToSet = list: @@ -38,7 +37,7 @@ let fromDeps = depsToSet fromLock.deps or [ ]; fromAtom = deps.${dep.from}; fromPath = atomPath fromAtom; - fromLockPath = "${(dirOf fromPath)}/${fromAtom.id}.lock"; + fromLockPath = "${(fromPath)}/atom.lock"; fromLock = builtins.fromTOML (builtins.readFile fromLockPath); fromName = dep.get or dep.name or ""; fromDep = fromDeps.${fromName}; @@ -51,7 +50,7 @@ let && builtins.match "^pin.*" fromDep.type != null then builtins.traceVerbose - "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${src}`" + "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${id}`" (importDep (fromDep // { path = dep.path or fromDep.path or "."; })) else import (if dep ? path then "${fetch}/${dep.path}" else fetch); diff --git a/atom-nix/core/mod.nix b/atom-nix/core/mod.nix index bd9c430..69be4b2 100644 --- a/atom-nix/core/mod.nix +++ b/atom-nix/core/mod.nix @@ -21,8 +21,8 @@ let std = builtins; mod = scopedImport { inherit mod std; } ../std/string/mod.nix; } ../std/string/toLowerCase.nix; - stdToml = l.fromTOML (l.readFile (../. + "/std@.toml")); - coreToml = l.fromTOML (l.readFile (../. + "/core@.toml")); + stdToml = l.fromTOML (l.readFile (../std/atom.toml)); + coreToml = l.fromTOML (l.readFile (../core/atom.toml)); in rec { inherit diff --git a/atom-nix/dev@.toml b/atom-nix/dev/atom.toml similarity index 100% rename from atom-nix/dev@.toml rename to atom-nix/dev/atom.toml diff --git a/atom-nix/std@.toml b/atom-nix/std/atom.toml similarity index 100% rename from atom-nix/std@.toml rename to atom-nix/std/atom.toml diff --git a/shell.nix b/shell.nix index 06dc9c3..6a35171 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ let - dev = (import ./atom-nix/core/importAtom.nix) { } (./. + "/atom-nix/dev@.toml"); + dev = (import ./atom-nix/core/importAtom.nix) { } (./atom-nix/dev); in dev.shell From b27541554e5a3241f89534fff6df1d78f2d9cce1 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 9 Aug 2025 20:05:17 -0600 Subject: [PATCH 15/17] feat!: remove feature flags The config should be parsed and passed on the rust side eventually, so there is no reason to maintain complex parsing logic here. --- .github/workflows/test.yml | 14 -------- atom-nix/README.md | 9 +---- atom-nix/core/compose.nix | 25 +------------- atom-nix/core/features.nix | 65 ------------------------------------ atom-nix/core/importAtom.nix | 22 ------------ atom-nix/core/mod.nix | 4 +-- 6 files changed, 3 insertions(+), 136 deletions(-) delete mode 100644 atom-nix/core/features.nix diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63e8d0c..868e378 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,20 +19,6 @@ jobs: - uses: nixbuild/nix-quick-install-action@v28 - name: Code Format Check run: eval "$(nix print-dev-env -f shell.nix)" && treefmt --fail-on-change - std-config: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v28 - - name: Std Library Config Test - run: cd test/std-import && ./import.sh > /dev/null - features: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: nixbuild/nix-quick-install-action@v28 - - name: Feature Parsing Test - run: cd test/features && ./resolve.sh > /dev/null purity: runs-on: ubuntu-latest steps: diff --git a/atom-nix/README.md b/atom-nix/README.md index 921bddc..d3716c0 100644 --- a/atom-nix/README.md +++ b/atom-nix/README.md @@ -107,9 +107,6 @@ name = "dev" version = "0.1.0" description = "Development environment" -[features] -default = [] - [fetch.pkgs] name = "nixpkgs" import = true @@ -128,11 +125,7 @@ let atom = builtins.fetchGit "https://github.com/ekala-project/atom"; importAtom = import "${atom}/atom-nix/core/importAtom.nix"; in -importAtom { - features = [ - # enabled flags - ]; -} ./atom-nix/dev.toml +importAtom { } ./atom-nix/dev.toml ``` ## Future Directions: Ekala Platform diff --git a/atom-nix/core/compose.nix b/atom-nix/core/compose.nix index 9212920..32a932f 100644 --- a/atom-nix/core/compose.nix +++ b/atom-nix/core/compose.nix @@ -61,10 +61,6 @@ in root, config, extern ? { }, - features ? [ ], - # internal features of the composer function - stdFeatures ? core.stdToml.features.default or [ ], - coreFeatures ? core.coreToml.features.default, # enable testing code paths __internal__test ? false, __isStd__ ? false, @@ -73,22 +69,10 @@ let par = core.prepDir root; std = core.importStd { - features = stdFeatures; inherit __internal__test; } ../std; - coreFeatures' = core.features.resolve core.coreToml.features coreFeatures; - stdFeatures' = core.features.resolve core.stdToml.features stdFeatures; - - cfg = config // { - features = config.features or { } // { - resolved = { - atom = features; - core = coreFeatures'; - std = stdFeatures'; - }; - }; - }; + cfg = config; msg = core.errors.debugMsg config; @@ -128,9 +112,6 @@ let _if = !__isStd__; atom = atomScope; _else.std = atomScope; - } - { - _if = !__isStd__ && l.elem "std" coreFeatures'; inherit std; } { @@ -207,10 +188,6 @@ let in core.set.inject fixed [ ({ _if = __isStd__; } // core.pureBuiltinsForStd fixed) - { - _if = __isStd__ && l.elem "lib" cfg.features.resolved.atom; - inherit (extern) lib; - } { _if = __isStd__ && __internal__test; __internal = { diff --git a/atom-nix/core/features.nix b/atom-nix/core/features.nix deleted file mode 100644 index 7241094..0000000 --- a/atom-nix/core/features.nix +++ /dev/null @@ -1,65 +0,0 @@ -let - l = builtins; -in -{ - /** - Resolve feature dependencies for Atom's module composer. - - This function takes a set of features and their dependencies, and an initial list of features. - It returns a list of all required features, including dependencies, without duplicates. - - # Examples - - Given a TOML file with feature declarations: - - ```toml - [features] - default = ["foo", "bar"] - foo = ["baz"] - bar = ["qux"] - baz = [] - qux = ["baz"] - ``` - - Nix usage: - - ```nix - features.resolve featureSet ["foo", "bar"] => ["foo", "baz", "bar", "qux"] - ``` - - # Type - - ``` - features.resolve :: AttrSet -> [String] -> [String] - ``` - - # Parameters - - - `featureSet`: An attribute set where keys are feature names and values are lists of dependencies. - - `initials`: A list of initially requested features. - - # Return Value - - A list of strings representing all required features, including dependencies, without duplicates. - - # Notes - - - The function handles circular dependencies. - - The order of features in the output list is not guaranteed. - - Features not present in the `featureSet` are ignored. - */ - resolve = - featureSet: initials: - let - resolve = - features: acc: - let - features' = l.filter (f: !(acc ? ${f})) features; - acc' = l.foldl' (a: f: a // { ${f} = null; }) acc features'; - in - if features' == [ ] then acc' else resolve (l.concatMap (f: featureSet.${f} or [ ]) features') acc'; - - resolved = resolve initials { }; - in - l.attrNames resolved; -} diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index ab9a881..d0624f6 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -16,7 +16,6 @@ valid input (and the CLI should type check on it's end) */ { - features ? null, remoteUrl ? null, __internal__test ? false, @@ -33,16 +32,6 @@ let id = builtins.seq version (atom.id or (mod.errors.missingAtom root' "id")); version = atom.version or (mod.errors.missingAtom root' "version"); - core = config.core or { }; - std = config.std or { }; - - features' = - let - featSet = config.features or { }; - featIn = if features == null then featSet.default or [ ] else features; - in - mod.features.resolve featSet featIn; - extern = import ./lock.nix root' id remoteUrl; meta = atom.meta or { }; @@ -55,17 +44,6 @@ mod.compose { config root ; - features = features'; - coreFeatures = - let - feat = core.features or mod.coreToml.features.default; - in - mod.features.resolve mod.coreToml.features feat; - stdFeatures = - let - feat = std.features or mod.stdToml.features.default; - in - mod.features.resolve mod.stdToml.features feat; __isStd__ = meta.__is_std__ or false; } diff --git a/atom-nix/core/mod.nix b/atom-nix/core/mod.nix index 69be4b2..fc9c687 100644 --- a/atom-nix/core/mod.nix +++ b/atom-nix/core/mod.nix @@ -50,8 +50,6 @@ rec { errors = import ./errors.nix; - features = import ./features.nix; - lowerKeys = filterMap (k: v: { ${toLowerCase k} = v; }); collectPublic = filterMap ( @@ -79,7 +77,7 @@ rec { ); }; - importStd = opts: importAtom { inherit (opts) __internal__test features; }; + importStd = opts: importAtom { inherit (opts) __internal__test; }; modIsValid = mod: dir: From 8069028758c56d5f090ac48c70d22806c6910197 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 9 Aug 2025 20:19:47 -0600 Subject: [PATCH 16/17] test!: fix and remove unused test --- .envrc | 2 +- atom-nix/core/atom.toml | 4 -- atom-nix/dev/atom.lock | 7 ++ atom-nix/dev/atom.toml | 18 ----- atom-nix/dev/mod.nix | 5 +- atom-nix/dev/shell.nix | 3 +- atom-nix/npins/default.nix | 80 --------------------- atom-nix/npins/sources.json | 23 ------ atom-nix/std/atom.toml | 17 ----- test/features/recursive-features | 1 - test/features/recursive-features-loop | 1 - test/features/recursive-features-loop@.toml | 8 --- test/features/recursive-features@.toml | 8 --- test/features/resolve.nix | 7 -- test/features/resolve.sh | 9 --- test/features/resolve/mod.nix | 6 -- test/integrity/bld.nix | 2 +- test/integrity/{bld@.toml => bld/atom.toml} | 0 test/pre.nix | 2 +- test/{pre@.toml => pre/atom.toml} | 0 test/purity/purity.nix | 2 +- test/purity/{test@.toml => test/atom.toml} | 0 test/scope.toml | 18 ----- test/std-import/default | 1 - test/std-import/default@.toml | 3 - test/std-import/explicit | 1 - test/std-import/explicit@.toml | 8 --- test/std-import/import.nix | 9 --- test/std-import/import.sh | 37 ---------- test/std-import/import/mod.nix | 10 --- test/std-import/no-std | 1 - test/std-import/no-std@.toml | 6 -- test/std-import/with-lib | 1 - test/std-import/with-lib@.toml | 6 -- 34 files changed, 16 insertions(+), 290 deletions(-) create mode 100644 atom-nix/dev/atom.lock delete mode 100644 atom-nix/npins/default.nix delete mode 100644 atom-nix/npins/sources.json delete mode 120000 test/features/recursive-features delete mode 120000 test/features/recursive-features-loop delete mode 100644 test/features/recursive-features-loop@.toml delete mode 100644 test/features/recursive-features@.toml delete mode 100644 test/features/resolve.nix delete mode 100755 test/features/resolve.sh delete mode 100644 test/features/resolve/mod.nix rename test/integrity/{bld@.toml => bld/atom.toml} (100%) rename test/{pre@.toml => pre/atom.toml} (100%) rename test/purity/{test@.toml => test/atom.toml} (100%) delete mode 100644 test/scope.toml delete mode 120000 test/std-import/default delete mode 100644 test/std-import/default@.toml delete mode 120000 test/std-import/explicit delete mode 100644 test/std-import/explicit@.toml delete mode 100644 test/std-import/import.nix delete mode 100755 test/std-import/import.sh delete mode 100644 test/std-import/import/mod.nix delete mode 120000 test/std-import/no-std delete mode 100644 test/std-import/no-std@.toml delete mode 120000 test/std-import/with-lib delete mode 100644 test/std-import/with-lib@.toml diff --git a/.envrc b/.envrc index aaff7ae..12824a7 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,4 @@ -files=(shell.nix src/dev/shell.nix) +files=(shell.nix atom-nix/dev/shell.nix) watch_file "${files[@]}" diff --git a/atom-nix/core/atom.toml b/atom-nix/core/atom.toml index 2e91a0a..900f3c3 100644 --- a/atom-nix/core/atom.toml +++ b/atom-nix/core/atom.toml @@ -2,7 +2,3 @@ id = "core" version = "0.3.0" description = "A purpose built, unopinionated, and performant module system for Nix code." - -[features] -std = [] -default = ["std"] diff --git a/atom-nix/dev/atom.lock b/atom-nix/dev/atom.lock new file mode 100644 index 0000000..1245375 --- /dev/null +++ b/atom-nix/dev/atom.lock @@ -0,0 +1,7 @@ +version = 1 + +[[deps]] +name = "nixpkgs" +url = "https://github.com/NixOS/nixpkgs/archive/c2ae88e026f9525daf89587f3cbee584b92b6134.tar.gz" +type = "pin+tar" +checksum = "sha256:1fsnvjvg7z2nvs876ig43f8z6cbhhma72cbxczs30ld0cqgy5dks" diff --git a/atom-nix/dev/atom.toml b/atom-nix/dev/atom.toml index 54b2022..bfa91d3 100644 --- a/atom-nix/dev/atom.toml +++ b/atom-nix/dev/atom.toml @@ -1,21 +1,3 @@ [atom] id = "dev" version = "0.2.0" - -[fetch.pkgs] -name = "nixpkgs" -import = true -args = [{}] - -[core] -features = ["std"] -[std] -features = ["lib"] - -[backend.nix] -# default when `eka` cli is ready -# fetcher = "native" -fetcher = "npins" - -[fetcher.npins] -root = "npins" diff --git a/atom-nix/dev/mod.nix b/atom-nix/dev/mod.nix index a540a34..2522c42 100644 --- a/atom-nix/dev/mod.nix +++ b/atom-nix/dev/mod.nix @@ -1 +1,4 @@ -{ Shell = mod.shell; } +{ + pkgs = from.nixpkgs { }; + Shell = mod.shell; +} diff --git a/atom-nix/dev/shell.nix b/atom-nix/dev/shell.nix index cb99462..a053a7a 100644 --- a/atom-nix/dev/shell.nix +++ b/atom-nix/dev/shell.nix @@ -1,10 +1,9 @@ { - pkgs ? get.pkgs, + pkgs ? mod.pkgs, }: pkgs.mkShell { packages = with pkgs; [ treefmt - npins nixfmt-rfc-style shfmt taplo diff --git a/atom-nix/npins/default.nix b/atom-nix/npins/default.nix deleted file mode 100644 index 5e7d086..0000000 --- a/atom-nix/npins/default.nix +++ /dev/null @@ -1,80 +0,0 @@ -# Generated by npins. Do not modify; will be overwritten regularly -let - data = builtins.fromJSON (builtins.readFile ./sources.json); - version = data.version; - - mkSource = - spec: - assert spec ? type; - let - path = - if spec.type == "Git" then - mkGitSource spec - else if spec.type == "GitRelease" then - mkGitSource spec - else if spec.type == "PyPi" then - mkPyPiSource spec - else if spec.type == "Channel" then - mkChannelSource spec - else - builtins.throw "Unknown source type ${spec.type}"; - in - spec // { outPath = path; }; - - mkGitSource = - { - repository, - revision, - url ? null, - hash, - branch ? null, - ... - }: - assert repository ? type; - # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository - # In the latter case, there we will always be an url to the tarball - if url != null then - (builtins.fetchTarball { - inherit url; - sha256 = hash; # FIXME: check nix version & use SRI hashes - }) - else - assert repository.type == "Git"; - let - urlToName = - url: rev: - let - matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url; - - short = builtins.substring 0 7 rev; - - appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; - in - "${if matched == null then "source" else builtins.head matched}${appendShort}"; - name = urlToName repository.url revision; - in - builtins.fetchGit { - url = repository.url; - rev = revision; - inherit name; - # hash = hash; - }; - - mkPyPiSource = - { url, hash, ... }: - builtins.fetchurl { - inherit url; - sha256 = hash; - }; - - mkChannelSource = - { url, hash, ... }: - builtins.fetchTarball { - inherit url; - sha256 = hash; - }; -in -if version == 3 then - builtins.mapAttrs (_: mkSource) data.pins -else - throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" diff --git a/atom-nix/npins/sources.json b/atom-nix/npins/sources.json deleted file mode 100644 index a66a32d..0000000 --- a/atom-nix/npins/sources.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "pins": { - "nixpkgs": { - "type": "Channel", - "name": "nixpkgs-unstable", - "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre660607.c3392ad349a5/nixexprs.tar.xz", - "hash": "1g2p74w085252qbxjymrzzccd203bfwxh8sbcyvbzan6bgqfvwi1" - }, - "nixpkgs.lib": { - "type": "Git", - "repository": { - "type": "GitHub", - "owner": "nix-community", - "repo": "nixpkgs.lib" - }, - "branch": "master", - "revision": "8bebd4c74f368aacb047f0141db09ec6b339733c", - "url": "https://github.com/nix-community/nixpkgs.lib/archive/8bebd4c74f368aacb047f0141db09ec6b339733c.tar.gz", - "hash": "0vzy9hs0k8zi9h4lx1krq578j3wdc62d6g4hddxj9sfkdmz8r3bn" - } - }, - "version": 3 -} \ No newline at end of file diff --git a/atom-nix/std/atom.toml b/atom-nix/std/atom.toml index 77b5d27..a2eebb0 100644 --- a/atom-nix/std/atom.toml +++ b/atom-nix/std/atom.toml @@ -3,24 +3,7 @@ id = "std" version = "0.2.0" description = "Nix Standard Library" -[fetch.lib] # the name in `atom` scope -name = "nixpkgs.lib" # the name in npins -import = true -subdir = "lib" -optional = true -# TODO: fetched at eval time -type = "lib" -# TODO: fetched at buildtime -# type = "src" - -[backend.nix] -fetcher = "npins" - [atom.meta] # special attribute # for the Nix std library __is_std__ = true - -[features] -lib = [] -default = [] diff --git a/test/features/recursive-features b/test/features/recursive-features deleted file mode 120000 index 48879a0..0000000 --- a/test/features/recursive-features +++ /dev/null @@ -1 +0,0 @@ -resolve \ No newline at end of file diff --git a/test/features/recursive-features-loop b/test/features/recursive-features-loop deleted file mode 120000 index 48879a0..0000000 --- a/test/features/recursive-features-loop +++ /dev/null @@ -1 +0,0 @@ -resolve \ No newline at end of file diff --git a/test/features/recursive-features-loop@.toml b/test/features/recursive-features-loop@.toml deleted file mode 100644 index 7da0640..0000000 --- a/test/features/recursive-features-loop@.toml +++ /dev/null @@ -1,8 +0,0 @@ -[atom] -id = "features-loop" -version = "0.1.0" - -[features] -a = ["b", "c"] -c = ["b"] -default = ["a"] diff --git a/test/features/recursive-features@.toml b/test/features/recursive-features@.toml deleted file mode 100644 index 86b937a..0000000 --- a/test/features/recursive-features@.toml +++ /dev/null @@ -1,8 +0,0 @@ -[atom] -id = "features" -version = "0.1.0" - -[features] -a = ["b"] -b = ["c"] -default = ["a"] diff --git a/test/features/resolve.nix b/test/features/resolve.nix deleted file mode 100644 index 5d2f78e..0000000 --- a/test/features/resolve.nix +++ /dev/null @@ -1,7 +0,0 @@ -let - f = import ../../atom-nix/core/importAtom.nix { __internal__test = true; }; -in -{ - recursive-features = f (./. + "/recursive-features@.toml"); - recursive-features-loop = f (./. + "/recursive-features-loop@.toml"); -} diff --git a/test/features/resolve.sh b/test/features/resolve.sh deleted file mode 100755 index 763d75c..0000000 --- a/test/features/resolve.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -f="$(nix eval -f resolve.nix recursive-features.resolved)" -[[ "$f" == '[ "a" "b" "c" ]' ]] - -f="$(nix eval -f resolve.nix recursive-features-loop.resolved)" -[[ "$f" == '[ "a" "b" "c" ]' ]] diff --git a/test/features/resolve/mod.nix b/test/features/resolve/mod.nix deleted file mode 100644 index cd40ea6..0000000 --- a/test/features/resolve/mod.nix +++ /dev/null @@ -1,6 +0,0 @@ -let - inherit (__internal) scope; -in -{ - Resolved = cfg.features.resolved.atom; -} diff --git a/test/integrity/bld.nix b/test/integrity/bld.nix index 7ad6393..800cbaa 100644 --- a/test/integrity/bld.nix +++ b/test/integrity/bld.nix @@ -2,7 +2,7 @@ let f = import ../../atom-nix/core/importAtom.nix; atom = f { } ( # added to test implicit path conversion when path is a string - builtins.toPath (./. + "/bld@.toml") + builtins.toPath ./bld ); in builtins.deepSeq atom atom diff --git a/test/integrity/bld@.toml b/test/integrity/bld/atom.toml similarity index 100% rename from test/integrity/bld@.toml rename to test/integrity/bld/atom.toml diff --git a/test/pre.nix b/test/pre.nix index bd79030..e6b9829 100644 --- a/test/pre.nix +++ b/test/pre.nix @@ -1 +1 @@ -(import ../atom-nix/core/importAtom.nix { }) (./. + "/pre@.toml") +(import ../atom-nix/core/importAtom.nix { }) ./pre diff --git a/test/pre@.toml b/test/pre/atom.toml similarity index 100% rename from test/pre@.toml rename to test/pre/atom.toml diff --git a/test/purity/purity.nix b/test/purity/purity.nix index ffe10fa..107d11d 100644 --- a/test/purity/purity.nix +++ b/test/purity/purity.nix @@ -2,7 +2,7 @@ let f = import ../../atom-nix/core/importAtom.nix; atom = f { __internal__test = true; } ( # added to test implicit path conversion when path is a string - builtins.toPath (./. + "/test@.toml") + builtins.toPath ./test ); in atom diff --git a/test/purity/test@.toml b/test/purity/test/atom.toml similarity index 100% rename from test/purity/test@.toml rename to test/purity/test/atom.toml diff --git a/test/scope.toml b/test/scope.toml deleted file mode 100644 index 3215b58..0000000 --- a/test/scope.toml +++ /dev/null @@ -1,18 +0,0 @@ -[fetch.lib] -name = "nixpkgs.lib" -import = true -sub = "lib" -optional = true - -[features] -lib = [] -default = [] - -[backends.nix] -root = "std" -fetcher = "npins" - -[project.meta] -# special attribute -# for the Nix std library -__is_std__ = true diff --git a/test/std-import/default b/test/std-import/default deleted file mode 120000 index efca996..0000000 --- a/test/std-import/default +++ /dev/null @@ -1 +0,0 @@ -import \ No newline at end of file diff --git a/test/std-import/default@.toml b/test/std-import/default@.toml deleted file mode 100644 index 84239b5..0000000 --- a/test/std-import/default@.toml +++ /dev/null @@ -1,3 +0,0 @@ -[atom] -id = "std-test" -version = "0.1.0" diff --git a/test/std-import/explicit b/test/std-import/explicit deleted file mode 120000 index efca996..0000000 --- a/test/std-import/explicit +++ /dev/null @@ -1 +0,0 @@ -import \ No newline at end of file diff --git a/test/std-import/explicit@.toml b/test/std-import/explicit@.toml deleted file mode 100644 index 1127c58..0000000 --- a/test/std-import/explicit@.toml +++ /dev/null @@ -1,8 +0,0 @@ -[atom] -id = "explicit-test" -version = "0.1.0" - -[core] -features = ["std"] -[std] -features = [] diff --git a/test/std-import/import.nix b/test/std-import/import.nix deleted file mode 100644 index cd02e5c..0000000 --- a/test/std-import/import.nix +++ /dev/null @@ -1,9 +0,0 @@ -let - f = import ../../atom-nix/core/importAtom.nix { __internal__test = true; }; -in -{ - default = f (./. + "/default@.toml"); - noStd = f (./. + "/no-std@.toml"); - explicit = f (./. + "/explicit@.toml"); - withLib = f (./. + "/with-lib@.toml"); -} diff --git a/test/std-import/import.sh b/test/std-import/import.sh deleted file mode 100755 index 71034a3..0000000 --- a/test/std-import/import.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -# defaults -f="$(nix eval -f import.nix default.coreF)" -[[ "$f" == '[ "std" ]' ]] -f="$(nix eval -f import.nix default.std)" -[[ "$f" == true ]] -f="$(nix eval -f import.nix default.lib)" -[[ "$f" == false ]] -f="$(nix eval -f import.nix default.sanity)" -[[ "$f" == true ]] - -# explicit -f="$(nix eval -f import.nix explicit.coreF)" -[[ "$f" == '[ "std" ]' ]] -f="$(nix eval -f import.nix explicit.std)" -[[ "$f" == true ]] -f="$(nix eval -f import.nix explicit.lib)" -[[ "$f" == false ]] - -# no std set -f="$(nix eval -f import.nix noStd.coreF)" -[[ "$f" == '[ ]' ]] -f="$(nix eval -f import.nix noStd.std)" -[[ "$f" == false ]] -f="$(nix eval -f import.nix noStd.lib)" -[[ "$f" == false ]] - -# no std set -f="$(nix eval -f import.nix withLib.stdF)" -[[ "$f" == '[ "lib" ]' ]] -f="$(nix eval -f import.nix withLib.std)" -[[ "$f" == true ]] -f="$(nix eval -f import.nix withLib.lib)" -[[ "$f" == true ]] diff --git a/test/std-import/import/mod.nix b/test/std-import/import/mod.nix deleted file mode 100644 index 1a73bcb..0000000 --- a/test/std-import/import/mod.nix +++ /dev/null @@ -1,10 +0,0 @@ -let - inherit (__internal) scope; -in -{ - Std = scope ? std; - Lib = scope ? std && scope.std ? lib; - CoreF = cfg.features.resolved.core; - StdF = cfg.features.resolved.std; - Sanity = scope.std.__internal.__isStd__; -} diff --git a/test/std-import/no-std b/test/std-import/no-std deleted file mode 120000 index efca996..0000000 --- a/test/std-import/no-std +++ /dev/null @@ -1 +0,0 @@ -import \ No newline at end of file diff --git a/test/std-import/no-std@.toml b/test/std-import/no-std@.toml deleted file mode 100644 index bba4291..0000000 --- a/test/std-import/no-std@.toml +++ /dev/null @@ -1,6 +0,0 @@ -[atom] -id = "no-std-test" -version = "0.1.0" - -[core] -features = [] # default is ["std"] diff --git a/test/std-import/with-lib b/test/std-import/with-lib deleted file mode 120000 index efca996..0000000 --- a/test/std-import/with-lib +++ /dev/null @@ -1 +0,0 @@ -import \ No newline at end of file diff --git a/test/std-import/with-lib@.toml b/test/std-import/with-lib@.toml deleted file mode 100644 index 8902549..0000000 --- a/test/std-import/with-lib@.toml +++ /dev/null @@ -1,6 +0,0 @@ -[atom] -id = "with-lib-test" -version = "0.1.0" - -[std] -features = ["lib"] From 6334a98912d217a4bf239563ffd3861dac8569c7 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 2 Nov 2025 11:58:12 -0700 Subject: [PATCH 17/17] feat!: remove proto-type lock file eka's first iteration lock format is now available for testing and we will no longer maintain the locking expression in this repo, as it is coupled to a specific version of eka. --- atom-nix/core/compose.nix | 4 +- atom-nix/core/importAtom.nix | 8 +-- atom-nix/core/lock.nix | 117 ----------------------------------- atom-nix/core/mod.nix | 7 ++- 4 files changed, 9 insertions(+), 127 deletions(-) delete mode 100644 atom-nix/core/lock.nix diff --git a/atom-nix/core/compose.nix b/atom-nix/core/compose.nix index 32a932f..0049dca 100644 --- a/atom-nix/core/compose.nix +++ b/atom-nix/core/compose.nix @@ -57,8 +57,8 @@ let l = builtins; core = import ./mod.nix; in +root: { - root, config, extern ? { }, # enable testing code paths @@ -70,7 +70,7 @@ let std = core.importStd { inherit __internal__test; - } ../std; + }; cfg = config; diff --git a/atom-nix/core/importAtom.nix b/atom-nix/core/importAtom.nix index d0624f6..2ec4e2e 100644 --- a/atom-nix/core/importAtom.nix +++ b/atom-nix/core/importAtom.nix @@ -29,20 +29,14 @@ let file = builtins.readFile (root + "/atom.toml"); config = builtins.fromTOML file; atom = config.atom or { }; - id = builtins.seq version (atom.id or (mod.errors.missingAtom root' "id")); - version = atom.version or (mod.errors.missingAtom root' "version"); - - extern = import ./lock.nix root' id remoteUrl; meta = atom.meta or { }; in -mod.compose { +mod.compose root { inherit - extern __internal__test config - root ; __isStd__ = meta.__is_std__ or false; diff --git a/atom-nix/core/lock.nix b/atom-nix/core/lock.nix deleted file mode 100644 index 1537bca..0000000 --- a/atom-nix/core/lock.nix +++ /dev/null @@ -1,117 +0,0 @@ -root: id: url: -let - lockPath = root + "/atom.lock"; - lock = builtins.fromTOML (builtins.readFile lockPath); - importAtom = import ./importAtom.nix { }; - atomPath = - dep: - let - path = root + "/../${dep.path or dep.id}/atom.toml"; - in - if builtins.pathExists path then - dirOf path - else - let - fetched = fetchGit { - inherit (dep) rev; - inherit url; - ref = "refs/eka/atoms/${dep.id}/${dep.version}"; - }; - in - fetched; - - depsToSet = - list: - builtins.listToAttrs ( - map (dep: { - name = dep.name or dep.id or ""; - value = dep; - }) list - ); - - deps = depsToSet lock.deps or [ ]; - - importPin = - dep: fetch: - let - fromDeps = depsToSet fromLock.deps or [ ]; - fromAtom = deps.${dep.from}; - fromPath = atomPath fromAtom; - fromLockPath = "${(fromPath)}/atom.lock"; - fromLock = builtins.fromTOML (builtins.readFile fromLockPath); - fromName = dep.get or dep.name or ""; - fromDep = fromDeps.${fromName}; - in - if - dep ? from - && fromAtom.type or "" == "atom" - && builtins.pathExists fromLockPath - && fromDeps ? ${fromName} - && builtins.match "^pin.*" fromDep.type != null - then - builtins.traceVerbose - "using a pin `${fromName}` as `${dep.name}` from atom `${dep.from}` in `${id}`" - (importDep (fromDep // { path = dep.path or fromDep.path or "."; })) - else - import (if dep ? path then "${fetch}/${dep.path}" else fetch); - - importDep = - dep: - if dep.type == "atom" then - importAtom (atomPath dep) - else if dep.type == "pin+git" then - let - repo = fetchGit { - inherit (dep) rev url; - shallow = true; - }; - in - importPin dep repo - else if dep.type == "pin+tar" then - let - fetch = fetchTarball { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - importPin dep fetch - else if dep.type == "pin" then - let - fetch = builtins.fetchurl { - inherit (dep) url; - sha256 = dep.checksum; - }; - in - importPin dep fetch - else - { }; - -in -if builtins.pathExists lockPath && lock.version == 1 then - let - from = builtins.mapAttrs (_: importDep) deps; - get = builtins.listToAttrs ( - map (src: { - name = src.pname or src.name; - value = - (builtins.removeAttrs src [ "type" ]) - // ( - if src.type == "build" then - { - src = import { - inherit (src) url; - hash = src.checksum; - }; - } - else - { } - ); - }) lock.srcs or [ ] - ); - - in - { - inherit from get; - } -else - { } diff --git a/atom-nix/core/mod.nix b/atom-nix/core/mod.nix index fc9c687..b5f9004 100644 --- a/atom-nix/core/mod.nix +++ b/atom-nix/core/mod.nix @@ -77,7 +77,12 @@ rec { ); }; - importStd = opts: importAtom { inherit (opts) __internal__test; }; + importStd = + opts: + compose ../std { + inherit (opts) __internal__test; + __isStd__ = true; + }; modIsValid = mod: dir: