Skip to content

Commit

Permalink
style: reorganize src into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Aug 7, 2024
1 parent 6f772ff commit 9f84d5b
Show file tree
Hide file tree
Showing 34 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let
dev = (import ./.) { } ./dev.toml;
dev = (import ./src/atom/fromManifest.nix) { } ./src/dev.toml;
in
dev.shell
4 changes: 2 additions & 2 deletions compose.toml → src/atom.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[atom]
name = "modules"
version = "0.2.0"
name = "atom"
version = "0.3.0"
description = "A purpose built, unopinionated, and performant module system for Nix code."

[features]
Expand Down
8 changes: 4 additions & 4 deletions compose.nix → src/atom/compose.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let
l = builtins;
src = import ./src;
src = import ./mod.nix;
in
{
config,
extern ? { },
features ? [ ],
# internal features of the composer function
stdFeatures ? src.stdToml.features.default or [ ],
composeFeatures ? src.composeToml.features.default,
composeFeatures ? src.atomToml.features.default,
# enable testing code paths
__internal__test ? false,
__isStd__ ? false,
Expand All @@ -20,9 +20,9 @@ let
std = src.readStd {
features = stdFeatures;
inherit __internal__test;
} ./std.toml;
} ../std.toml;

composeFeatures' = src.features.parse src.composeToml.features composeFeatures;
composeFeatures' = src.features.parse src.atomToml.features composeFeatures;
stdFeatures' = src.features.parse src.stdToml.features stdFeatures;

__atom = config // {
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions default.nix → src/atom/fromManifest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
}:
path':
let
src = import ./src;
mod = import ./mod.nix;

path = src.prepDir path';
path = mod.prepDir path';

file = builtins.readFile path;
config = builtins.fromTOML file;
atom = config.atom or { };
name = atom.name or (src.errors.missingName path);
name = atom.name or (mod.errors.missingName path);

features' =
let
featSet = config.features or { };
featIn = if features == null then featSet.default or [ ] else features;
in
src.features.parse featSet featIn;
mod.features.parse featSet featIn;

backend = config.backend or { };
nix = backend.nix or { };
Expand All @@ -36,7 +36,7 @@ let
let
pins = import (dirOf path + "/${root}");
in
src.filterMap (
mod.filterMap (
k: v:
let
src = "${pins.${v.name or k}}/${v.subdir or ""}";
Expand All @@ -59,19 +59,19 @@ let

composeFeatures = compose.features or { };
in
(import ./compose.nix) {
(mod.compose) {
inherit extern __internal__test config;
features = features';
composeFeatures =
let
feat = composeFeatures.atom or src.composeToml.features.default;
feat = composeFeatures.atom or mod.atomToml.features.default;
in
src.features.parse src.composeToml.features feat;
mod.features.parse mod.atomToml.features feat;
stdFeatures =
let
feat = composeFeatures.std or src.stdToml.features.default;
feat = composeFeatures.std or mod.stdToml.features.default;
in
src.features.parse src.stdToml.features feat;
mod.features.parse mod.stdToml.features feat;

__isStd__ = meta.__is_std__ or false;
} (dirOf path + "/${root}")
13 changes: 5 additions & 8 deletions src/default.nix → src/atom/mod.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# to keep the core impelementation clean
let
l = builtins;
fromManifest = import ../.;
fromManifest = import ./fromManifest.nix;
fix = import ../std/fix.nix;
when = scopedImport { std = builtins; } ../std/set/when.nix;
filterMap = scopedImport { std = builtins; } ../std/set/filterMap.nix;
Expand All @@ -16,7 +16,7 @@ let
mod = scopedImport { inherit std mod; } ../std/string/mod.nix;
} ../std/string/toLowerCase.nix;
stdToml = l.fromTOML (l.readFile ../std.toml);
composeToml = l.fromTOML (l.readFile ../compose.toml);
atomToml = l.fromTOML (l.readFile ../atom.toml);
in
rec {
inherit
Expand All @@ -25,7 +25,7 @@ rec {
strToPath
stdFilter
stdToml
composeToml
atomToml
;

file = {
Expand All @@ -35,6 +35,8 @@ rec {
inherit when;
};

compose = import ./compose.nix;

errors = import ./errors.nix;

lowerKeys = filterMap (k: v: { ${toLowerCase k} = v; });
Expand All @@ -57,11 +59,6 @@ rec {
);

readStd = opts: fromManifest { inherit (opts) __internal__test features; };
# compose {
# inherit (opts) __internal__test;
# features = features.parse stdToml.features opts.features;
# __isStd__ = true;
# } path;

modIsValid =
mod: dir:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/integrity/bld.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let
f = import ../../.;
f = import ../../src/atom/fromManifest.nix;
atom = f { } (
# added to test implicit path conversion when path is a string
builtins.toPath ./bld.toml
Expand Down
2 changes: 1 addition & 1 deletion test/integrity/bld.res.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
bar = 5;
};
};
f = scopedImport { std = builtins; } "${../../std/set/filterMap.nix}";
f = scopedImport { std = builtins; } "${../../src/std/set/filterMap.nix}";
file = builtins.readFile ./bld/bum;
foo = 1;
next = /nix/store/next;
Expand Down
2 changes: 1 addition & 1 deletion test/pre.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(import ../. { }) ./pre.toml
(import ../src/atom/fromManifest.nix { }) ./pre.toml
2 changes: 1 addition & 1 deletion test/purity/purity.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let
f = import ../../.;
f = import ../../src/atom/fromManifest.nix;
atom = f { __internal__test = true; } (
# added to test implicit path conversion when path is a string
builtins.toPath ./test.toml
Expand Down
2 changes: 1 addition & 1 deletion test/std-import/import.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let
f = import ../../. { __internal__test = true; };
f = import ../../src/atom/fromManifest.nix { __internal__test = true; };
in
{
default = f ./default.toml;
Expand Down

0 comments on commit 9f84d5b

Please sign in to comment.