@adrifer/winix 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +291 -0
  3. package/dist/backends/nix/index.d.ts +18 -0
  4. package/dist/backends/nix/index.js +442 -0
  5. package/dist/cli/activation.d.ts +6 -0
  6. package/dist/cli/activation.js +19 -0
  7. package/dist/cli/analysis.d.ts +30 -0
  8. package/dist/cli/analysis.js +170 -0
  9. package/dist/cli/commands/apply.d.ts +14 -0
  10. package/dist/cli/commands/apply.js +180 -0
  11. package/dist/cli/commands/check.d.ts +6 -0
  12. package/dist/cli/commands/check.js +46 -0
  13. package/dist/cli/commands/init.d.ts +5 -0
  14. package/dist/cli/commands/init.js +69 -0
  15. package/dist/cli/commands/inspect.d.ts +1 -0
  16. package/dist/cli/commands/inspect.js +24 -0
  17. package/dist/cli/commands/switch.d.ts +7 -0
  18. package/dist/cli/commands/switch.js +40 -0
  19. package/dist/cli/commands/update.d.ts +6 -0
  20. package/dist/cli/commands/update.js +33 -0
  21. package/dist/cli/index.d.ts +2 -0
  22. package/dist/cli/index.js +122 -0
  23. package/dist/cli/loader.d.ts +11 -0
  24. package/dist/cli/loader.js +49 -0
  25. package/dist/cli/run.d.ts +4 -0
  26. package/dist/cli/run.js +26 -0
  27. package/dist/cli/types-gen/parser.d.ts +14 -0
  28. package/dist/cli/types-gen/parser.js +275 -0
  29. package/dist/core/index.d.ts +1 -0
  30. package/dist/core/index.js +1 -0
  31. package/dist/core/types.d.ts +106 -0
  32. package/dist/core/types.js +2 -0
  33. package/dist/evaluator/index.d.ts +20 -0
  34. package/dist/evaluator/index.js +184 -0
  35. package/dist/helpers/account.d.ts +46 -0
  36. package/dist/helpers/account.js +165 -0
  37. package/dist/helpers/darwin.d.ts +36 -0
  38. package/dist/helpers/darwin.js +38 -0
  39. package/dist/helpers/home.d.ts +40 -0
  40. package/dist/helpers/home.js +63 -0
  41. package/dist/helpers/index.d.ts +14 -0
  42. package/dist/helpers/index.js +7 -0
  43. package/dist/helpers/nix.d.ts +36 -0
  44. package/dist/helpers/nix.js +157 -0
  45. package/dist/helpers/nixos.d.ts +53 -0
  46. package/dist/helpers/nixos.js +86 -0
  47. package/dist/helpers/options.d.ts +10 -0
  48. package/dist/helpers/options.js +1 -0
  49. package/dist/helpers/overlay.d.ts +13 -0
  50. package/dist/helpers/overlay.js +29 -0
  51. package/dist/helpers/platforms.d.ts +21 -0
  52. package/dist/helpers/platforms.js +62 -0
  53. package/dist/helpers/utils.d.ts +6 -0
  54. package/dist/helpers/utils.js +8 -0
  55. package/dist/index.d.ts +9 -0
  56. package/dist/index.js +5 -0
  57. package/dist/sdk/index.d.ts +26 -0
  58. package/dist/sdk/index.js +183 -0
  59. package/dist/types/common.d.ts +10 -0
  60. package/dist/types/common.js +1 -0
  61. package/dist/types/darwin.d.ts +86 -0
  62. package/dist/types/darwin.js +1 -0
  63. package/dist/types/home.d.ts +45 -0
  64. package/dist/types/home.js +1 -0
  65. package/dist/types/index.d.ts +5 -0
  66. package/dist/types/index.js +5 -0
  67. package/dist/types/nixos.d.ts +225 -0
  68. package/dist/types/nixos.js +1 -0
  69. package/dist/types/programs.d.ts +67 -0
  70. package/dist/types/programs.js +1 -0
  71. package/index.d.ts +5 -0
  72. package/package.json +69 -0
  73. package/types/bundled/darwin.d.ts +476 -0
  74. package/types/bundled/home-manager.d.ts +4674 -0
  75. package/types/bundled/nixos.d.ts +19991 -0
  76. package/types/index.d.ts +8 -0
@@ -0,0 +1,86 @@
1
+ import { normalizeArgs } from "./utils.js";
2
+ export const nixos = Object.assign((config) => ({ nixos: config }), {
3
+ program: (name, opts = {}) => ({
4
+ nixos: { programs: { [name]: { enable: true, ...opts } } },
5
+ }),
6
+ imports: (...args) => ({
7
+ nixos: { imports: normalizeArgs(args) },
8
+ }),
9
+ service: (name, opts = {}) => ({
10
+ nixos: { services: { [name]: { enable: true, ...opts } } },
11
+ }),
12
+ packages: (...args) => ({
13
+ nixos: { packages: normalizeArgs(args) },
14
+ }),
15
+ nix: (config) => ({
16
+ nixos: { nix: config },
17
+ }),
18
+ boot: (config) => ({
19
+ nixos: { boot: config },
20
+ }),
21
+ networking: (config) => ({
22
+ nixos: { networking: config },
23
+ }),
24
+ environment: (config) => ({
25
+ nixos: { environment: config },
26
+ }),
27
+ users: (config) => ({
28
+ nixos: { users: config },
29
+ }),
30
+ system: (config) => ({
31
+ nixos: { system: config },
32
+ }),
33
+ fonts: (config) => ({
34
+ nixos: { fonts: config },
35
+ }),
36
+ security: (config) => ({
37
+ nixos: { security: config },
38
+ }),
39
+ i18n: (config) => ({
40
+ nixos: { i18n: config },
41
+ }),
42
+ time: (config) => ({
43
+ nixos: { time: config },
44
+ }),
45
+ virtualisation: Object.assign((config) => ({
46
+ nixos: { virtualisation: config },
47
+ }), {
48
+ ociContainer: (name, config) => ({
49
+ nixos: {
50
+ virtualisation: {
51
+ ociContainers: {
52
+ containers: {
53
+ [name]: config,
54
+ },
55
+ },
56
+ },
57
+ },
58
+ }),
59
+ }),
60
+ sysctl: (settings) => ({
61
+ nixos: {
62
+ boot: {
63
+ kernel: {
64
+ sysctl: settings,
65
+ },
66
+ },
67
+ },
68
+ }),
69
+ systemd: Object.assign((opts) => ({
70
+ nixos: { systemd: opts },
71
+ }), {
72
+ service: (name, config) => ({
73
+ nixos: { systemd: { services: { [name]: config } } },
74
+ }),
75
+ userService: (name, config) => ({
76
+ nixos: { systemd: { user: { services: { [name]: config } } } },
77
+ }),
78
+ timer: (name, config) => ({
79
+ nixos: { systemd: { timers: { [name]: config } } },
80
+ }),
81
+ tmpfiles: (rules) => ({
82
+ nixos: { systemd: { tmpfiles: { rules } } },
83
+ }),
84
+ }),
85
+ raw: (config) => ({ nixos: { __raw: [config] } }),
86
+ });
@@ -0,0 +1,10 @@
1
+ type AnyOptions = Record<string, unknown>;
2
+ declare const knownOptionsBrand: unique symbol;
3
+ type KnownOptionsBrand = {
4
+ readonly [knownOptionsBrand]?: never;
5
+ };
6
+ export type ProgramOptions<Options, K extends string> = string extends K ? AnyOptions : K extends keyof Options ? KnownProgramOptions<Options, K> : AnyOptions;
7
+ export type ServiceOptions<Options, K extends string> = string extends K ? AnyOptions : K extends keyof Options ? KnownServiceOptions<Options, K> : AnyOptions;
8
+ export type KnownProgramOptions<Options, K extends keyof Options> = Omit<Options[K], "enable"> & KnownOptionsBrand;
9
+ export type KnownServiceOptions<Options, K extends keyof Options> = Omit<Options[K], "enable"> & KnownOptionsBrand;
10
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { Fragment } from "../core/types.js";
2
+ /**
3
+ * Add a nixpkgs overlay.
4
+ */
5
+ export interface OverlayHelper {
6
+ stable(inputName: string): Fragment;
7
+ custom(expr: string): Fragment;
8
+ darwin: {
9
+ stable(inputName: string): Fragment;
10
+ custom(expr: string): Fragment;
11
+ };
12
+ }
13
+ export declare const overlay: OverlayHelper;
@@ -0,0 +1,29 @@
1
+ export const overlay = {
2
+ stable: (inputName) => overlayForScopes(stableOverlayExpr(inputName)),
3
+ custom: (expr) => overlayForScopes(expr),
4
+ darwin: {
5
+ stable: (inputName) => overlayForScope("darwin", stableOverlayExpr(inputName)),
6
+ custom: (expr) => overlayForScope("darwin", expr),
7
+ },
8
+ };
9
+ function overlayForScopes(expr) {
10
+ return {
11
+ ...overlayForScope("nixos", expr),
12
+ ...overlayForScope("darwin", expr),
13
+ };
14
+ }
15
+ function overlayForScope(scope, expr) {
16
+ return {
17
+ [scope]: {
18
+ nixpkgs: {
19
+ overlays: [overlayExpr(expr)],
20
+ },
21
+ },
22
+ };
23
+ }
24
+ function stableOverlayExpr(inputName) {
25
+ return `(final: prev: { stable = import inputs.${inputName} { inherit (final.stdenv.hostPlatform) system; config = final.config.nixpkgs.config or {}; }; })`;
26
+ }
27
+ function overlayExpr(expr) {
28
+ return { __winixNixExpr: true, expr };
29
+ }
@@ -0,0 +1,21 @@
1
+ import type { PlatformFactory } from "../core/types.js";
2
+ export interface NixosPlatformOpts {
3
+ system?: string;
4
+ stateVersion?: string;
5
+ allowUnfree?: boolean;
6
+ homeManager?: boolean;
7
+ hostname?: string | false;
8
+ }
9
+ export interface DarwinPlatformOpts {
10
+ system?: string;
11
+ stateVersion?: number | string;
12
+ allowUnfree?: boolean;
13
+ homeManager?: boolean;
14
+ homebrew?: boolean;
15
+ hostname?: string | false;
16
+ }
17
+ export interface PlatformsHelper {
18
+ nixos: PlatformFactory<[opts?: NixosPlatformOpts]>;
19
+ darwin: PlatformFactory<[opts?: DarwinPlatformOpts]>;
20
+ }
21
+ export declare const platforms: PlatformsHelper;
@@ -0,0 +1,62 @@
1
+ import { platform, getOptionalEvalContext } from "../sdk/index.js";
2
+ export const platforms = {
3
+ nixos: platform("nixos", (opts = {}) => {
4
+ const ctx = getOptionalEvalContext();
5
+ const hostname = opts.hostname === false ? undefined : opts.hostname ?? ctx?.hostname;
6
+ const useHomeManager = opts.homeManager ?? true;
7
+ return {
8
+ nixos: {
9
+ ...(useHomeManager && { imports: ["home-manager"] }),
10
+ nixpkgs: {
11
+ hostPlatform: opts.system ?? "x86_64-linux",
12
+ config: { allowUnfree: opts.allowUnfree ?? true },
13
+ },
14
+ nix: { settings: { experimentalFeatures: ["nix-command", "flakes"] } },
15
+ ...(hostname && { networking: { hostName: hostname } }),
16
+ ...(opts.stateVersion && { system: { stateVersion: opts.stateVersion } }),
17
+ ...(useHomeManager && {
18
+ homeManager: {
19
+ useGlobalPkgs: true,
20
+ useUserPackages: true,
21
+ },
22
+ }),
23
+ },
24
+ };
25
+ }),
26
+ darwin: platform("darwin", (opts = {}) => {
27
+ const ctx = getOptionalEvalContext();
28
+ const hostname = opts.hostname === false ? undefined : opts.hostname ?? ctx?.hostname;
29
+ const useHomeManager = opts.homeManager ?? true;
30
+ const useHomebrew = opts.homebrew ?? false;
31
+ return {
32
+ darwin: {
33
+ imports: [
34
+ ...(useHomeManager ? ["inputs.home-manager.darwinModules.home-manager"] : []),
35
+ ...(useHomebrew ? ["inputs.nix-homebrew.darwinModules.nix-homebrew"] : []),
36
+ ],
37
+ nixpkgs: {
38
+ hostPlatform: opts.system ?? "aarch64-darwin",
39
+ config: { allowUnfree: opts.allowUnfree ?? true },
40
+ },
41
+ nix: {
42
+ enable: false,
43
+ settings: { experimentalFeatures: ["nix-command", "flakes"] },
44
+ },
45
+ ...(hostname && { networking: { hostName: hostname } }),
46
+ ...(opts.stateVersion !== undefined && { system: { stateVersion: opts.stateVersion } }),
47
+ ...(useHomeManager && {
48
+ "home-manager": {
49
+ useGlobalPkgs: true,
50
+ useUserPackages: true,
51
+ },
52
+ }),
53
+ ...(useHomebrew && {
54
+ "nix-homebrew": {
55
+ enable: true,
56
+ autoMigrate: true,
57
+ },
58
+ }),
59
+ },
60
+ };
61
+ }),
62
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Normalize variadic args: accepts either spread args or a single array.
3
+ * normalizeArgs(["a", "b"]) → ["a", "b"]
4
+ * normalizeArgs([["a", "b"]]) → ["a", "b"]
5
+ */
6
+ export declare function normalizeArgs<T>(args: T[] | [T[]]): T[];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Normalize variadic args: accepts either spread args or a single array.
3
+ * normalizeArgs(["a", "b"]) → ["a", "b"]
4
+ * normalizeArgs([["a", "b"]]) → ["a", "b"]
5
+ */
6
+ export function normalizeArgs(args) {
7
+ return Array.isArray(args[0]) ? args[0] : args;
8
+ }
@@ -0,0 +1,9 @@
1
+ export type { Fragment, FragmentFactory, PlatformFactory, ProfileFactory, LazyFragment, PlatformLazyFragment, FragmentEntry, FragmentResult, NixExpr, RawModuleRef, ImportRef, InputDef, InputWithOptions, WorkspaceDef, HostDef, EvalContext } from "./core/types.js";
2
+ export type { Attrs, BootOptions, DarwinNetworking, DarwinOptions, DarwinSecurity, DarwinDefaults, DarwinSystem, EnvironmentOptions, FirewallOptions, FontsOptions, FzfOptions, GitInclude, GitOptions, HomeActivation, HomebrewOptions, HomeConfig, HomeFile, HomeOptions, I18nOptions, LaunchdAgentOptions, LaunchdOptions, NeovimOptions, NetworkingOptions, NixConfig, NixGcOptions, NixHomebrewOptions, NixOptions, NixpkgsOptions, NixosSecurityOptions, NixosSystemOptions, NixPrimitive, NixSettings, NixValue, NixosOptions, OciContainerOptions, PackageRef, Script, ServicesOptions, StarshipOptions, SystemdOptions, SystemdService, SystemdTimer, TimeOptions, TmuxOptions, UserOptions, UsersOptions, VirtualisationOptions, WslOptions, XdgFile, XdgOptions, ZoxideOptions, ZshOptions, } from "./types/index.js";
3
+ export { platform, feature, profile, host, workspace, input, defineInputs, rawModule, withContext } from "./sdk/index.js";
4
+ export { evaluate } from "./evaluator/index.js";
5
+ export type { EvaluatedHost } from "./evaluator/index.js";
6
+ export { generateNix } from "./backends/nix/index.js";
7
+ export type { NixOutput } from "./backends/nix/index.js";
8
+ export { account, darwin, home, nix, nixos, overlay, platforms } from "./helpers/index.js";
9
+ export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, ActivationOpts, DarwinHelper, DarwinPlatformOpts, DarwinProgramOptions, DarwinServiceOptions, HomeHelper, HomeProgramOptions, HomeServiceOptions, LaunchdHelper, NixNamespace, NixosHelper, NixosPlatformOpts, NixosProgramOptions, NixosServiceOptions, OverlayHelper, PkgHelper, PlatformsHelper, ScriptHelper, SysctlSettings, SystemdHelper, VirtualisationHelper } from "./helpers/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Public API: what users import from "@adrifer/winix"
2
+ export { platform, feature, profile, host, workspace, input, defineInputs, rawModule, withContext } from "./sdk/index.js";
3
+ export { evaluate } from "./evaluator/index.js";
4
+ export { generateNix } from "./backends/nix/index.js";
5
+ export { account, darwin, home, nix, nixos, overlay, platforms } from "./helpers/index.js";
@@ -0,0 +1,26 @@
1
+ import type { Fragment, FragmentFactory, PlatformFactory, ProfileFactory, PlatformLazyFragment, FragmentEntry, FragmentResult, InputDef, InputWithOptions, WorkspaceDef, HostDef, EvalContext, NixExpr } from "../core/types.js";
2
+ export declare function setEvalContext(ctx: EvalContext): EvalContext | null;
3
+ export declare function restoreEvalContext(ctx: EvalContext | null): void;
4
+ export declare function clearEvalContext(): void;
5
+ export declare function getEvalContext(): EvalContext;
6
+ export declare function getOptionalEvalContext(): EvalContext | null;
7
+ export declare function platform<T extends unknown[]>(id: string, factory: (...args: T) => Fragment): PlatformFactory<T>;
8
+ export declare function feature<T extends unknown[]>(id: string, factory: (...args: T) => FragmentResult): FragmentFactory<T>;
9
+ export declare function profile<T extends unknown[]>(id: string, factory: (...args: T) => FragmentResult): ProfileFactory<T>;
10
+ export declare function profile(id: string, entries: FragmentEntry | readonly FragmentEntry[]): ProfileFactory<[]>;
11
+ export declare function host(name: string, platform: PlatformLazyFragment, fragments: readonly FragmentEntry[]): HostDef;
12
+ export declare function workspace(def: WorkspaceDef): WorkspaceDef;
13
+ export declare function input(url: string, opts?: Omit<InputWithOptions, "url">): InputWithOptions;
14
+ export declare function defineInputs<T extends Record<string, InputDef>>(inputs: T): T;
15
+ export interface RawModuleHelper {
16
+ (path: string): Fragment;
17
+ homeManager(path: string): Fragment;
18
+ darwin(path: string): Fragment;
19
+ }
20
+ export declare const rawModule: RawModuleHelper;
21
+ export declare function escape(expr: string): NixExpr;
22
+ export declare function withContext<R>(ctx: {
23
+ platform: string;
24
+ hostname?: string;
25
+ features?: string[];
26
+ }, fn: () => R): R;
@@ -0,0 +1,183 @@
1
+ // SDK: helpers exposed to user configs (platform, feature, host, workspace, etc.)
2
+ import { posix as pathPosix } from "node:path";
3
+ // --- Evaluation context (implicit, set by evaluator) ---
4
+ const G = globalThis;
5
+ export function setEvalContext(ctx) {
6
+ const prev = G.__winixEvalContext ?? null;
7
+ G.__winixEvalContext = ctx;
8
+ return prev;
9
+ }
10
+ export function restoreEvalContext(ctx) {
11
+ G.__winixEvalContext = ctx;
12
+ }
13
+ export function clearEvalContext() {
14
+ G.__winixEvalContext = null;
15
+ }
16
+ function getCtx() {
17
+ const ctx = G.__winixEvalContext ?? null;
18
+ if (!ctx) {
19
+ throw new Error("Fragment evaluated outside of Winix context. " +
20
+ "Use withContext() for testing or ensure the evaluator is running.");
21
+ }
22
+ return ctx;
23
+ }
24
+ export function getEvalContext() {
25
+ return getCtx();
26
+ }
27
+ export function getOptionalEvalContext() {
28
+ return G.__winixEvalContext ?? null;
29
+ }
30
+ // --- platform() ---
31
+ export function platform(id, factory) {
32
+ const fn = ((...args) => {
33
+ return {
34
+ __lazy: true,
35
+ __id: id,
36
+ __platform: true,
37
+ __resolve: () => {
38
+ const result = factory(...args);
39
+ return { ...result, __id: id, __platform: true };
40
+ },
41
+ };
42
+ });
43
+ Object.defineProperty(fn, "isActive", {
44
+ get: () => getCtx().platform === id,
45
+ configurable: true,
46
+ enumerable: false,
47
+ });
48
+ Object.defineProperty(fn, "id", { value: id, configurable: true, enumerable: false });
49
+ return fn;
50
+ }
51
+ // --- feature() ---
52
+ export function feature(id, factory) {
53
+ const fn = ((...args) => {
54
+ return {
55
+ __lazy: true,
56
+ __id: id,
57
+ __resolve: () => {
58
+ const result = factory(...args);
59
+ return annotateResult(result, id);
60
+ },
61
+ };
62
+ });
63
+ Object.defineProperty(fn, "isActive", {
64
+ get: () => getCtx().activeIds.has(id),
65
+ configurable: true,
66
+ enumerable: false,
67
+ });
68
+ Object.defineProperty(fn, "id", { value: id, configurable: true, enumerable: false });
69
+ return fn;
70
+ }
71
+ export function profile(id, entriesOrFactory) {
72
+ const factory = typeof entriesOrFactory === "function"
73
+ ? entriesOrFactory
74
+ : (() => entriesOrFactory);
75
+ return feature(id, factory);
76
+ }
77
+ // --- host() ---
78
+ export function host(name, platform, fragments) {
79
+ return { name, platform, fragments };
80
+ }
81
+ // --- workspace() ---
82
+ export function workspace(def) {
83
+ return def;
84
+ }
85
+ // --- input() ---
86
+ export function input(url, opts) {
87
+ return { url, ...opts };
88
+ }
89
+ // --- defineInputs() ---
90
+ export function defineInputs(inputs) {
91
+ return inputs;
92
+ }
93
+ export const rawModule = Object.assign((path) => ({
94
+ nixos: { imports: [createRawModuleRef(path)] },
95
+ }), {
96
+ homeManager: (path) => ({
97
+ homeManager: { imports: [createRawModuleRef(path)] },
98
+ }),
99
+ darwin: (path) => ({
100
+ darwin: { imports: [createRawModuleRef(path)] },
101
+ }),
102
+ });
103
+ export function escape(expr) {
104
+ return {
105
+ __winixNixExpr: true,
106
+ expr,
107
+ };
108
+ }
109
+ function annotateResult(result, id) {
110
+ if (Array.isArray(result)) {
111
+ return result.map((entry) => annotateEntry(entry, id));
112
+ }
113
+ if (isLazy(result)) {
114
+ return result;
115
+ }
116
+ return annotateFragment(result, id);
117
+ }
118
+ function annotateEntry(entry, id) {
119
+ if (Array.isArray(entry)) {
120
+ return entry.map((item) => annotateEntry(item, id));
121
+ }
122
+ if (isLazy(entry)) {
123
+ return entry;
124
+ }
125
+ return annotateFragment(entry, id);
126
+ }
127
+ function annotateFragment(fragment, id) {
128
+ return { ...fragment, __id: fragment.__id ?? id };
129
+ }
130
+ function isLazy(entry) {
131
+ return (typeof entry === "object" &&
132
+ entry !== null &&
133
+ entry.__lazy === true);
134
+ }
135
+ function createRawModuleRef(path) {
136
+ return {
137
+ __winixRawModule: true,
138
+ path: normalizeRawModulePath(path),
139
+ };
140
+ }
141
+ function normalizeRawModulePath(path) {
142
+ if (path.length === 0) {
143
+ throw new Error("rawModule() path must not be empty");
144
+ }
145
+ if (path.includes("\0")) {
146
+ throw new Error("rawModule() path must not contain null bytes");
147
+ }
148
+ if (path.includes("\\") || path.includes(":")) {
149
+ throw new Error("rawModule() path must be a workspace-relative POSIX path");
150
+ }
151
+ if (pathPosix.isAbsolute(path)) {
152
+ throw new Error("rawModule() path must be workspace-relative, not absolute");
153
+ }
154
+ // Allow a leading "./" convenience prefix, but reject "." or ".." elsewhere.
155
+ if (path
156
+ .split("/")
157
+ .some((segment, index) => segment === "" || segment === ".." || (segment === "." && index !== 0))) {
158
+ throw new Error("rawModule() path must not escape the workspace");
159
+ }
160
+ const normalized = pathPosix.normalize(path);
161
+ if (normalized === "." || normalized === ".." || normalized.startsWith("../")) {
162
+ throw new Error("rawModule() path must not escape the workspace");
163
+ }
164
+ if (!normalized.endsWith(".nix")) {
165
+ throw new Error("rawModule() path must point to a .nix file");
166
+ }
167
+ return normalized;
168
+ }
169
+ // --- Testing helper ---
170
+ export function withContext(ctx, fn) {
171
+ const prev = G.__winixEvalContext ?? null;
172
+ G.__winixEvalContext = {
173
+ platform: ctx.platform,
174
+ hostname: ctx.hostname ?? "test",
175
+ activeIds: new Set(ctx.features ?? []),
176
+ };
177
+ try {
178
+ return fn();
179
+ }
180
+ finally {
181
+ G.__winixEvalContext = prev;
182
+ }
183
+ }
@@ -0,0 +1,10 @@
1
+ import type { NixExpr } from "../core/types.js";
2
+ export type NixPrimitive = string | number | boolean | null;
3
+ export type NixValue = NixPrimitive | NixValue[] | {
4
+ [key: string]: NixValue;
5
+ };
6
+ export type PackageRef = string | NixExpr;
7
+ export type Attrs<T = unknown> = Record<string, T>;
8
+ export type Script = string | NixExpr;
9
+ export interface FreeformOptions extends Record<string, unknown> {
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,86 @@
1
+ import type { PackageRef } from "./common.js";
2
+ import type { ImportRef } from "../core/types.js";
3
+ import type { NixOptions, NixpkgsOptions } from "./nixos.js";
4
+ export interface DarwinSystem extends Record<string, unknown> {
5
+ stateVersion?: number | string;
6
+ primaryUser?: string;
7
+ defaults?: DarwinDefaults;
8
+ keyboard?: Record<string, unknown>;
9
+ }
10
+ export interface DarwinDefaults extends Record<string, unknown> {
11
+ NSGlobalDomain?: Record<string, unknown>;
12
+ CustomUserPreferences?: Record<string, unknown>;
13
+ dock?: Record<string, unknown>;
14
+ finder?: Record<string, unknown>;
15
+ trackpad?: Record<string, unknown>;
16
+ loginwindow?: Record<string, unknown>;
17
+ screencapture?: Record<string, unknown>;
18
+ screensaver?: Record<string, unknown>;
19
+ }
20
+ export interface HomebrewOptions extends Record<string, unknown> {
21
+ enable?: boolean;
22
+ casks?: string[];
23
+ brews?: string[];
24
+ taps?: string[];
25
+ masApps?: Record<string, number>;
26
+ onActivation?: {
27
+ cleanup?: "none" | "uninstall" | "zap";
28
+ autoUpdate?: boolean;
29
+ upgrade?: boolean;
30
+ } & Record<string, unknown>;
31
+ }
32
+ export interface NixHomebrewOptions extends Record<string, unknown> {
33
+ enable?: boolean;
34
+ user?: string;
35
+ autoMigrate?: boolean;
36
+ }
37
+ export interface DarwinSecurity extends Record<string, unknown> {
38
+ pam?: {
39
+ services?: Record<string, Record<string, unknown>>;
40
+ } & Record<string, unknown>;
41
+ }
42
+ export interface DarwinNetworking extends Record<string, unknown> {
43
+ hostName?: string;
44
+ }
45
+ export interface LaunchdAgentOptions extends Record<string, unknown> {
46
+ path?: string[];
47
+ serviceConfig: {
48
+ KeepAlive?: boolean;
49
+ ProgramArguments: string[];
50
+ RunAtLoad?: boolean;
51
+ StandardErrorPath?: string;
52
+ StandardOutPath?: string;
53
+ WorkingDirectory?: string;
54
+ EnvironmentVariables?: Record<string, string>;
55
+ } & Record<string, unknown>;
56
+ }
57
+ export interface LaunchdOptions extends Record<string, unknown> {
58
+ user?: {
59
+ agents?: Record<string, LaunchdAgentOptions>;
60
+ } & Record<string, unknown>;
61
+ daemons?: Record<string, LaunchdAgentOptions>;
62
+ }
63
+ export interface DarwinOptions extends Record<string, unknown> {
64
+ imports?: ImportRef[];
65
+ system?: DarwinSystem;
66
+ homebrew?: HomebrewOptions;
67
+ "nix-homebrew"?: NixHomebrewOptions;
68
+ security?: DarwinSecurity;
69
+ networking?: DarwinNetworking;
70
+ launchd?: LaunchdOptions;
71
+ environment?: {
72
+ systemPackages?: PackageRef[];
73
+ shells?: PackageRef[];
74
+ variables?: Record<string, string>;
75
+ } & Record<string, unknown>;
76
+ users?: {
77
+ users?: Record<string, {
78
+ home?: string;
79
+ shell?: PackageRef;
80
+ } & Record<string, unknown>>;
81
+ } & Record<string, unknown>;
82
+ programs?: Record<string, unknown>;
83
+ nix?: NixOptions;
84
+ nixpkgs?: NixpkgsOptions;
85
+ "home-manager"?: Record<string, unknown>;
86
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { Attrs, PackageRef, Script } from "./common.js";
2
+ import type { ImportRef, NixExpr } from "../core/types.js";
3
+ export interface HomeActivation extends Record<string, unknown> {
4
+ }
5
+ export interface HomeConfig extends Record<string, unknown> {
6
+ username?: string;
7
+ homeDirectory?: string;
8
+ stateVersion?: string;
9
+ packages?: PackageRef[];
10
+ file?: Record<string, HomeFile> | NixExpr;
11
+ sessionVariables?: Record<string, string>;
12
+ sessionPath?: string[];
13
+ activation?: Record<string, HomeActivation | Script>;
14
+ }
15
+ export interface HomeFile extends Record<string, unknown> {
16
+ source?: string | NixExpr;
17
+ text?: Script;
18
+ recursive?: boolean;
19
+ executable?: boolean;
20
+ force?: boolean;
21
+ enable?: boolean;
22
+ }
23
+ export interface XdgFile extends HomeFile {
24
+ }
25
+ export interface XdgOptions extends Record<string, unknown> {
26
+ configFile?: Record<string, HomeFile> | NixExpr;
27
+ dataFile?: Record<string, HomeFile> | NixExpr;
28
+ }
29
+ export interface HomeOptions extends Record<string, unknown> {
30
+ imports?: ImportRef[];
31
+ username?: string;
32
+ home?: HomeConfig;
33
+ programs?: Record<string, unknown>;
34
+ services?: Attrs;
35
+ xdg?: XdgOptions;
36
+ packages?: PackageRef[];
37
+ sessionVariables?: Record<string, string>;
38
+ sessionPath?: string[];
39
+ activation?: Record<string, HomeActivation | Script>;
40
+ manual?: {
41
+ manpages?: {
42
+ enable?: boolean;
43
+ } & Record<string, unknown>;
44
+ } & Record<string, unknown>;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from "./common.js";
2
+ export * from "./programs.js";
3
+ export * from "./nixos.js";
4
+ export * from "./home.js";
5
+ export * from "./darwin.js";
@@ -0,0 +1,5 @@
1
+ export * from "./common.js";
2
+ export * from "./programs.js";
3
+ export * from "./nixos.js";
4
+ export * from "./home.js";
5
+ export * from "./darwin.js";