@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.
- package/LICENSE +21 -0
- package/README.md +291 -0
- package/dist/backends/nix/index.d.ts +18 -0
- package/dist/backends/nix/index.js +442 -0
- package/dist/cli/activation.d.ts +6 -0
- package/dist/cli/activation.js +19 -0
- package/dist/cli/analysis.d.ts +30 -0
- package/dist/cli/analysis.js +170 -0
- package/dist/cli/commands/apply.d.ts +14 -0
- package/dist/cli/commands/apply.js +180 -0
- package/dist/cli/commands/check.d.ts +6 -0
- package/dist/cli/commands/check.js +46 -0
- package/dist/cli/commands/init.d.ts +5 -0
- package/dist/cli/commands/init.js +69 -0
- package/dist/cli/commands/inspect.d.ts +1 -0
- package/dist/cli/commands/inspect.js +24 -0
- package/dist/cli/commands/switch.d.ts +7 -0
- package/dist/cli/commands/switch.js +40 -0
- package/dist/cli/commands/update.d.ts +6 -0
- package/dist/cli/commands/update.js +33 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +122 -0
- package/dist/cli/loader.d.ts +11 -0
- package/dist/cli/loader.js +49 -0
- package/dist/cli/run.d.ts +4 -0
- package/dist/cli/run.js +26 -0
- package/dist/cli/types-gen/parser.d.ts +14 -0
- package/dist/cli/types-gen/parser.js +275 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/types.d.ts +106 -0
- package/dist/core/types.js +2 -0
- package/dist/evaluator/index.d.ts +20 -0
- package/dist/evaluator/index.js +184 -0
- package/dist/helpers/account.d.ts +46 -0
- package/dist/helpers/account.js +165 -0
- package/dist/helpers/darwin.d.ts +36 -0
- package/dist/helpers/darwin.js +38 -0
- package/dist/helpers/home.d.ts +40 -0
- package/dist/helpers/home.js +63 -0
- package/dist/helpers/index.d.ts +14 -0
- package/dist/helpers/index.js +7 -0
- package/dist/helpers/nix.d.ts +36 -0
- package/dist/helpers/nix.js +157 -0
- package/dist/helpers/nixos.d.ts +53 -0
- package/dist/helpers/nixos.js +86 -0
- package/dist/helpers/options.d.ts +10 -0
- package/dist/helpers/options.js +1 -0
- package/dist/helpers/overlay.d.ts +13 -0
- package/dist/helpers/overlay.js +29 -0
- package/dist/helpers/platforms.d.ts +21 -0
- package/dist/helpers/platforms.js +62 -0
- package/dist/helpers/utils.d.ts +6 -0
- package/dist/helpers/utils.js +8 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/sdk/index.d.ts +26 -0
- package/dist/sdk/index.js +183 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/common.js +1 -0
- package/dist/types/darwin.d.ts +86 -0
- package/dist/types/darwin.js +1 -0
- package/dist/types/home.d.ts +45 -0
- package/dist/types/home.js +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -0
- package/dist/types/nixos.d.ts +225 -0
- package/dist/types/nixos.js +1 -0
- package/dist/types/programs.d.ts +67 -0
- package/dist/types/programs.js +1 -0
- package/index.d.ts +5 -0
- package/package.json +69 -0
- package/types/bundled/darwin.d.ts +476 -0
- package/types/bundled/home-manager.d.ts +4674 -0
- package/types/bundled/nixos.d.ts +19991 -0
- package/types/index.d.ts +8 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { feature, getEvalContext } from "../sdk/index.js";
|
|
2
|
+
import { nix } from "./nix.js";
|
|
3
|
+
export const account = {
|
|
4
|
+
user: (name, factory) => {
|
|
5
|
+
const fn = feature(`account:user:${name}`, (...args) => accountFragment(name, factory(...args)));
|
|
6
|
+
defineMetadata(fn, "name", name);
|
|
7
|
+
defineMetadata(fn, "kind", "account.user");
|
|
8
|
+
return fn;
|
|
9
|
+
},
|
|
10
|
+
group: (name, factory = (() => ({}))) => {
|
|
11
|
+
const fn = feature(`account:group:${name}`, (...args) => groupFragment(name, factory(...args)));
|
|
12
|
+
defineMetadata(fn, "name", name);
|
|
13
|
+
defineMetadata(fn, "kind", "account.group");
|
|
14
|
+
return fn;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
function accountFragment(username, opts) {
|
|
18
|
+
const ctx = getEvalContext();
|
|
19
|
+
const isDarwin = ctx.platform === "darwin";
|
|
20
|
+
const isNixos = ctx.platform === "nixos" || ctx.platform === "linux";
|
|
21
|
+
const isWsl = ctx.activeIds.has("wsl");
|
|
22
|
+
const usesHomebrew = ctx.activeIds.has("homebrew");
|
|
23
|
+
const homeDirectory = opts.homeDirectory ?? opts.home ?? (isDarwin ? `/Users/${username}` : `/home/${username}`);
|
|
24
|
+
const shell = normalizeShell(opts.shell);
|
|
25
|
+
const nixosShellProgram = nixosShellProgramFor(opts.shell);
|
|
26
|
+
const groups = unique([
|
|
27
|
+
...(opts.admin && isNixos ? ["wheel"] : []),
|
|
28
|
+
...(opts.groups ?? []),
|
|
29
|
+
...(opts.extraGroups ?? []),
|
|
30
|
+
]);
|
|
31
|
+
const homeManager = opts.homeManager?.homeManager ?? opts.homeManager;
|
|
32
|
+
return {
|
|
33
|
+
homeManager: {
|
|
34
|
+
home: {
|
|
35
|
+
username,
|
|
36
|
+
homeDirectory,
|
|
37
|
+
...(opts.stateVersion && { stateVersion: opts.stateVersion }),
|
|
38
|
+
...(opts.sessionVariables && { sessionVariables: opts.sessionVariables }),
|
|
39
|
+
},
|
|
40
|
+
programs: {
|
|
41
|
+
homeManager: { enable: true },
|
|
42
|
+
},
|
|
43
|
+
...(isPlainObject(homeManager) && homeManager),
|
|
44
|
+
},
|
|
45
|
+
...(isNixos && {
|
|
46
|
+
nixos: {
|
|
47
|
+
users: {
|
|
48
|
+
users: {
|
|
49
|
+
[username]: {
|
|
50
|
+
isNormalUser: opts.isNormalUser ?? !opts.isSystemUser,
|
|
51
|
+
...(opts.isSystemUser !== undefined && { isSystemUser: opts.isSystemUser }),
|
|
52
|
+
...(opts.description && { description: opts.description }),
|
|
53
|
+
...(groups.length > 0 && { extraGroups: groups }),
|
|
54
|
+
...(opts.uid !== undefined && { uid: opts.uid }),
|
|
55
|
+
...(opts.group && { group: opts.group }),
|
|
56
|
+
...(opts.packages && { packages: opts.packages }),
|
|
57
|
+
...(shell && { shell }),
|
|
58
|
+
...(opts.openssh && { openssh: normalizeOpenSsh(opts.openssh) }),
|
|
59
|
+
...(opts.hashedPasswordFile && { hashedPasswordFile: opts.hashedPasswordFile }),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
...(shell && { defaultUserShell: shell }),
|
|
63
|
+
},
|
|
64
|
+
...(nixosShellProgram && {
|
|
65
|
+
programs: {
|
|
66
|
+
[nixosShellProgram]: { enable: true },
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
...(opts.wslDefault &&
|
|
70
|
+
isWsl && {
|
|
71
|
+
wsl: {
|
|
72
|
+
defaultUser: nix.lib.mkDefault(username),
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
...(isDarwin && {
|
|
78
|
+
darwin: {
|
|
79
|
+
system: { primaryUser: username },
|
|
80
|
+
users: {
|
|
81
|
+
users: {
|
|
82
|
+
[username]: {
|
|
83
|
+
home: homeDirectory,
|
|
84
|
+
...(opts.description && { description: opts.description }),
|
|
85
|
+
...(opts.uid !== undefined && { uid: opts.uid }),
|
|
86
|
+
...(opts.gid !== undefined && { gid: opts.gid }),
|
|
87
|
+
...(shell && { shell }),
|
|
88
|
+
...(opts.openssh && { openssh: normalizeOpenSsh(opts.openssh) }),
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
...(shell && {
|
|
93
|
+
environment: { shells: [shell] },
|
|
94
|
+
programs: {
|
|
95
|
+
...(nixosShellProgram && { [nixosShellProgram]: { enable: true } }),
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
...(usesHomebrew && { "nix-homebrew": { user: username } }),
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function groupFragment(name, opts) {
|
|
104
|
+
const ctx = getEvalContext();
|
|
105
|
+
const isDarwin = ctx.platform === "darwin";
|
|
106
|
+
const isNixos = ctx.platform === "nixos" || ctx.platform === "linux";
|
|
107
|
+
const members = opts.members?.map(memberName);
|
|
108
|
+
const group = {
|
|
109
|
+
...omit(opts, ["members"]),
|
|
110
|
+
...(members && { members }),
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
...(isNixos && { nixos: { users: { groups: { [name]: group } } } }),
|
|
114
|
+
...(isDarwin && { darwin: { users: { groups: { [name]: group } } } }),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function normalizeShell(shell) {
|
|
118
|
+
if (!shell)
|
|
119
|
+
return undefined;
|
|
120
|
+
return typeof shell === "string" ? nix.pkg(shell) : shell;
|
|
121
|
+
}
|
|
122
|
+
function nixosShellProgramFor(shell) {
|
|
123
|
+
const name = shellName(shell);
|
|
124
|
+
return name === "zsh" || name === "fish" ? name : undefined;
|
|
125
|
+
}
|
|
126
|
+
function shellName(shell) {
|
|
127
|
+
if (typeof shell === "string")
|
|
128
|
+
return shell;
|
|
129
|
+
if (isNixExpr(shell))
|
|
130
|
+
return shell.expr.match(/^pkgs\.([A-Za-z0-9_-]+)$/)?.[1];
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
function isNixExpr(value) {
|
|
134
|
+
return (typeof value === "object" &&
|
|
135
|
+
value !== null &&
|
|
136
|
+
value.__winixNixExpr === true &&
|
|
137
|
+
typeof value.expr === "string");
|
|
138
|
+
}
|
|
139
|
+
function isPlainObject(value) {
|
|
140
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
141
|
+
}
|
|
142
|
+
function normalizeOpenSsh(openssh) {
|
|
143
|
+
return {
|
|
144
|
+
authorizedKeys: {
|
|
145
|
+
...(openssh.authorizedKeys && { keys: openssh.authorizedKeys }),
|
|
146
|
+
...(openssh.authorizedKeyFiles && { keyFiles: openssh.authorizedKeyFiles }),
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function memberName(member) {
|
|
151
|
+
return typeof member === "string" ? member : member.name;
|
|
152
|
+
}
|
|
153
|
+
function defineMetadata(target, key, value) {
|
|
154
|
+
Object.defineProperty(target, key, { value, configurable: true, enumerable: false });
|
|
155
|
+
}
|
|
156
|
+
function omit(value, keys) {
|
|
157
|
+
const result = { ...value };
|
|
158
|
+
for (const key of keys) {
|
|
159
|
+
delete result[key];
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
function unique(values) {
|
|
164
|
+
return [...new Set(values)];
|
|
165
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProgramOptions, ServiceOptions } from "./options.js";
|
|
2
|
+
import type { Fragment } from "../core/types.js";
|
|
3
|
+
import type { DarwinDefaults, DarwinOptions, DarwinSecurity, HomebrewOptions, LaunchdAgentOptions, LaunchdOptions, NixOptions, PackageRef } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Map of nix-darwin program names to their option types.
|
|
6
|
+
* Starts empty; augmented by generated types.
|
|
7
|
+
*/
|
|
8
|
+
export interface DarwinProgramOptions {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Map of nix-darwin service names to their option types.
|
|
12
|
+
* Starts empty; augmented by generated types.
|
|
13
|
+
*/
|
|
14
|
+
export interface DarwinServiceOptions {
|
|
15
|
+
}
|
|
16
|
+
export interface LaunchdHelper {
|
|
17
|
+
(config: LaunchdOptions): Fragment;
|
|
18
|
+
agent(name: string, config: LaunchdAgentOptions): Fragment;
|
|
19
|
+
daemon(name: string, config: LaunchdAgentOptions): Fragment;
|
|
20
|
+
}
|
|
21
|
+
export interface DarwinHelper {
|
|
22
|
+
(config: DarwinOptions): Fragment;
|
|
23
|
+
imports(imports: string[]): Fragment;
|
|
24
|
+
imports(...imports: string[]): Fragment;
|
|
25
|
+
program<const K extends string>(name: K, opts?: ProgramOptions<DarwinProgramOptions, K>): Fragment;
|
|
26
|
+
service<const K extends string>(name: K, opts?: ServiceOptions<DarwinServiceOptions, K>): Fragment;
|
|
27
|
+
packages(packages: PackageRef[]): Fragment;
|
|
28
|
+
packages(...packages: PackageRef[]): Fragment;
|
|
29
|
+
nix(config: NixOptions): Fragment;
|
|
30
|
+
security(config: DarwinSecurity): Fragment;
|
|
31
|
+
homebrew(config: HomebrewOptions): Fragment;
|
|
32
|
+
launchd: LaunchdHelper;
|
|
33
|
+
defaults(config: DarwinDefaults): Fragment;
|
|
34
|
+
raw(config: string): Fragment;
|
|
35
|
+
}
|
|
36
|
+
export declare const darwin: DarwinHelper;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { normalizeArgs } from "./utils.js";
|
|
2
|
+
export const darwin = Object.assign((config) => ({ darwin: config }), {
|
|
3
|
+
program: (name, opts = {}) => ({
|
|
4
|
+
darwin: { programs: { [name]: { enable: true, ...opts } } },
|
|
5
|
+
}),
|
|
6
|
+
imports: (...args) => ({
|
|
7
|
+
darwin: { imports: normalizeArgs(args) },
|
|
8
|
+
}),
|
|
9
|
+
service: (name, opts = {}) => ({
|
|
10
|
+
darwin: { services: { [name]: { enable: true, ...opts } } },
|
|
11
|
+
}),
|
|
12
|
+
packages: (...args) => ({
|
|
13
|
+
darwin: { packages: normalizeArgs(args) },
|
|
14
|
+
}),
|
|
15
|
+
nix: (config) => ({
|
|
16
|
+
darwin: { nix: config },
|
|
17
|
+
}),
|
|
18
|
+
security: (config) => ({
|
|
19
|
+
darwin: { security: config },
|
|
20
|
+
}),
|
|
21
|
+
homebrew: (config) => ({
|
|
22
|
+
darwin: { homebrew: config },
|
|
23
|
+
}),
|
|
24
|
+
launchd: Object.assign((config) => ({
|
|
25
|
+
darwin: { launchd: config },
|
|
26
|
+
}), {
|
|
27
|
+
agent: (name, config) => ({
|
|
28
|
+
darwin: { launchd: { user: { agents: { [name]: config } } } },
|
|
29
|
+
}),
|
|
30
|
+
daemon: (name, config) => ({
|
|
31
|
+
darwin: { launchd: { daemons: { [name]: config } } },
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
defaults: (config) => ({
|
|
35
|
+
darwin: { system: { defaults: config } },
|
|
36
|
+
}),
|
|
37
|
+
raw: (config) => ({ darwin: { __raw: [config] } }),
|
|
38
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ProgramOptions, ServiceOptions } from "./options.js";
|
|
2
|
+
import type { Fragment } from "../core/types.js";
|
|
3
|
+
import type { HomeFile, HomeOptions, PackageRef } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Map of Home Manager program names to their option types.
|
|
6
|
+
* Starts empty; augmented by generated types.
|
|
7
|
+
*/
|
|
8
|
+
export interface HomeProgramOptions {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Map of Home Manager service names to their option types.
|
|
12
|
+
* Starts empty; augmented by generated types.
|
|
13
|
+
*/
|
|
14
|
+
export interface HomeServiceOptions {
|
|
15
|
+
}
|
|
16
|
+
export interface HomeHelper {
|
|
17
|
+
(config: HomeOptions): Fragment;
|
|
18
|
+
imports(imports: string[]): Fragment;
|
|
19
|
+
imports(...imports: string[]): Fragment;
|
|
20
|
+
program<const K extends string>(name: K, opts?: ProgramOptions<HomeProgramOptions, K>): Fragment;
|
|
21
|
+
service<const K extends string>(name: K, opts?: ServiceOptions<HomeServiceOptions, K>): Fragment;
|
|
22
|
+
env(vars: Record<string, string>): Fragment;
|
|
23
|
+
path(paths: string[]): Fragment;
|
|
24
|
+
path(...paths: string[]): Fragment;
|
|
25
|
+
packages(packages: PackageRef[]): Fragment;
|
|
26
|
+
packages(...packages: PackageRef[]): Fragment;
|
|
27
|
+
files(files: Record<string, HomeFile>): Fragment;
|
|
28
|
+
configFile(name: string, opts: HomeFile): Fragment;
|
|
29
|
+
configFiles(files: Record<string, HomeFile>): Fragment;
|
|
30
|
+
symlink(path: string, opts?: Omit<HomeFile, "source" | "text">): HomeFile;
|
|
31
|
+
raw(config: string): Fragment;
|
|
32
|
+
activation(name: string, opts: ActivationOpts): Fragment;
|
|
33
|
+
}
|
|
34
|
+
export interface ActivationOpts {
|
|
35
|
+
/** DAG dependencies. Defaults to ["writeBoundary"]. */
|
|
36
|
+
after?: string[];
|
|
37
|
+
/** Shell script body. Nix interpolations such as ${config.home.homeDirectory} are passed through. */
|
|
38
|
+
script: string;
|
|
39
|
+
}
|
|
40
|
+
export declare const home: HomeHelper;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { normalizeArgs } from "./utils.js";
|
|
2
|
+
export const home = Object.assign((config) => ({ homeManager: config }), {
|
|
3
|
+
program: (name, opts = {}) => ({
|
|
4
|
+
homeManager: { programs: { [name]: { enable: true, ...opts } } },
|
|
5
|
+
}),
|
|
6
|
+
imports: (...args) => ({
|
|
7
|
+
homeManager: { imports: normalizeArgs(args) },
|
|
8
|
+
}),
|
|
9
|
+
service: (name, opts = {}) => ({
|
|
10
|
+
homeManager: { services: { [name]: { enable: true, ...opts } } },
|
|
11
|
+
}),
|
|
12
|
+
env: (vars) => ({
|
|
13
|
+
homeManager: { home: { sessionVariables: vars } },
|
|
14
|
+
}),
|
|
15
|
+
path: (...args) => ({
|
|
16
|
+
homeManager: { home: { sessionPath: normalizeArgs(args) } },
|
|
17
|
+
}),
|
|
18
|
+
packages: (...args) => ({
|
|
19
|
+
homeManager: { home: { packages: normalizeArgs(args) } },
|
|
20
|
+
}),
|
|
21
|
+
files: (files) => ({
|
|
22
|
+
homeManager: { home: { file: files } },
|
|
23
|
+
}),
|
|
24
|
+
configFile: (name, opts) => ({
|
|
25
|
+
homeManager: { xdg: { configFile: { [name]: opts } } },
|
|
26
|
+
}),
|
|
27
|
+
configFiles: (files) => ({
|
|
28
|
+
homeManager: { xdg: { configFile: files } },
|
|
29
|
+
}),
|
|
30
|
+
symlink: (path, opts = {}) => ({
|
|
31
|
+
...opts,
|
|
32
|
+
source: {
|
|
33
|
+
__winixNixExpr: true,
|
|
34
|
+
expr: `config.lib.file.mkOutOfStoreSymlink ${homePathToNixString(path)}`,
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
raw: (config) => ({ homeManager: { __raw: [config] } }),
|
|
38
|
+
activation: (name, opts) => {
|
|
39
|
+
const after = opts.after ?? ["writeBoundary"];
|
|
40
|
+
const afterList = after.map((s) => JSON.stringify(s)).join(" ");
|
|
41
|
+
return {
|
|
42
|
+
homeManager: {
|
|
43
|
+
home: {
|
|
44
|
+
activation: {
|
|
45
|
+
[name]: {
|
|
46
|
+
__winixNixExpr: true,
|
|
47
|
+
expr: `lib.hm.dag.entryAfter [ ${afterList} ] ''\n${opts.script}\n''`,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
function homePathToNixString(path) {
|
|
56
|
+
if (path.startsWith("~/")) {
|
|
57
|
+
return `"${escapeNixString(`\${config.home.homeDirectory}/${path.slice(2)}`)}"`;
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify(path);
|
|
60
|
+
}
|
|
61
|
+
function escapeNixString(value) {
|
|
62
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
63
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { account } from "./account.js";
|
|
2
|
+
export type { AccountGroupFactory, AccountGroupMember, AccountGroupOpts, AccountNamespace, AccountOpts, AccountUserFactory, AccountUserRef, } from "./account.js";
|
|
3
|
+
export { platforms } from "./platforms.js";
|
|
4
|
+
export type { DarwinPlatformOpts, NixosPlatformOpts, PlatformsHelper } from "./platforms.js";
|
|
5
|
+
export { nix } from "./nix.js";
|
|
6
|
+
export type { NixNamespace, PkgHelper, ScriptHelper } from "./nix.js";
|
|
7
|
+
export { overlay } from "./overlay.js";
|
|
8
|
+
export type { OverlayHelper } from "./overlay.js";
|
|
9
|
+
export { home } from "./home.js";
|
|
10
|
+
export type { ActivationOpts, HomeHelper, HomeProgramOptions, HomeServiceOptions } from "./home.js";
|
|
11
|
+
export { nixos } from "./nixos.js";
|
|
12
|
+
export type { NixosHelper, NixosProgramOptions, NixosServiceOptions, SysctlSettings, SystemdHelper, VirtualisationHelper } from "./nixos.js";
|
|
13
|
+
export { darwin } from "./darwin.js";
|
|
14
|
+
export type { DarwinHelper, DarwinProgramOptions, DarwinServiceOptions, LaunchdHelper } from "./darwin.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { account } from "./account.js";
|
|
2
|
+
export { platforms } from "./platforms.js";
|
|
3
|
+
export { nix } from "./nix.js";
|
|
4
|
+
export { overlay } from "./overlay.js";
|
|
5
|
+
export { home } from "./home.js";
|
|
6
|
+
export { nixos } from "./nixos.js";
|
|
7
|
+
export { darwin } from "./darwin.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { NixExpr } from "../core/types.js";
|
|
2
|
+
type NixValue = unknown;
|
|
3
|
+
type NixCondition = boolean | string | NixExpr;
|
|
4
|
+
type NixStringPart = string | NixExpr;
|
|
5
|
+
export interface NixNamespace {
|
|
6
|
+
expr(expr: string): NixExpr;
|
|
7
|
+
pkg: PkgHelper;
|
|
8
|
+
bin(packageName: string, executable: string): NixExpr;
|
|
9
|
+
str(strings: TemplateStringsArray, ...values: NixStringPart[]): NixExpr;
|
|
10
|
+
script: ScriptHelper;
|
|
11
|
+
concat(...parts: NixStringPart[]): NixExpr;
|
|
12
|
+
withPkgs(packages: string[]): NixExpr;
|
|
13
|
+
optionalAttrs(condition: NixCondition, attrs: Record<string, unknown>): NixExpr;
|
|
14
|
+
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
15
|
+
isDarwin: NixExpr;
|
|
16
|
+
isLinux: NixExpr;
|
|
17
|
+
lib: {
|
|
18
|
+
mkDefault(value: NixValue): NixExpr;
|
|
19
|
+
mkForce(value: NixValue): NixExpr;
|
|
20
|
+
mkBefore(value: NixValue): NixExpr;
|
|
21
|
+
mkAfter(value: NixValue): NixExpr;
|
|
22
|
+
optionalAttrs(condition: NixCondition, attrs: Record<string, unknown>): NixExpr;
|
|
23
|
+
optionalString(condition: NixCondition, value: NixStringPart): NixExpr;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface PkgHelper {
|
|
27
|
+
(name: string): NixExpr;
|
|
28
|
+
stable(name: string): NixExpr;
|
|
29
|
+
}
|
|
30
|
+
export interface ScriptHelper {
|
|
31
|
+
(body: string): NixExpr;
|
|
32
|
+
(strings: TemplateStringsArray, ...values: NixStringPart[]): NixExpr;
|
|
33
|
+
raw(strings: TemplateStringsArray, ...values: NixStringPart[]): NixExpr;
|
|
34
|
+
}
|
|
35
|
+
export declare const nix: NixNamespace;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const expr = (value) => ({ __winixNixExpr: true, expr: value });
|
|
2
|
+
const pkg = Object.assign((name) => expr(`pkgs.${name}`), {
|
|
3
|
+
stable: (name) => expr(`pkgs.stable.${name}`),
|
|
4
|
+
});
|
|
5
|
+
const script = Object.assign((first, ...values) => {
|
|
6
|
+
const body = typeof first === "string"
|
|
7
|
+
? first
|
|
8
|
+
: joinTemplate(first, values, (value) => isNixExpr(value) ? `\${${value.expr}}` : String(value));
|
|
9
|
+
return expr(`''\n${trimScript(body)}\n''`);
|
|
10
|
+
}, {
|
|
11
|
+
raw: (strings, ...values) => {
|
|
12
|
+
const body = joinRawTemplate(strings, values, (value) => isNixExpr(value) ? `\${${value.expr}}` : String(value));
|
|
13
|
+
return expr(`''\n${trimScript(body)}\n''`);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
function optionalAttrs(condition, attrs) {
|
|
17
|
+
return expr(`(lib.optionalAttrs ${conditionToNix(condition)} { ${formatAttrs(attrs)} })`);
|
|
18
|
+
}
|
|
19
|
+
function optionalString(condition, value) {
|
|
20
|
+
return expr(`(lib.optionalString ${conditionToNix(condition)} ${stringPartToNix(value)})`);
|
|
21
|
+
}
|
|
22
|
+
export const nix = {
|
|
23
|
+
expr,
|
|
24
|
+
pkg,
|
|
25
|
+
bin: (packageName, executable) => nix.str `${pkg(packageName)}/bin/${executable}`,
|
|
26
|
+
str: (strings, ...values) => {
|
|
27
|
+
const parts = [];
|
|
28
|
+
const rawStrings = strings.raw;
|
|
29
|
+
for (let index = 0; index < rawStrings.length; index += 1) {
|
|
30
|
+
parts.push(escapeNixDoubleQuoted(rawStrings[index]));
|
|
31
|
+
if (index < values.length) {
|
|
32
|
+
const value = values[index];
|
|
33
|
+
if (isNixExpr(value)) {
|
|
34
|
+
parts.push(`\${${value.expr}}`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
parts.push(escapeNixDoubleQuoted(String(value)));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return expr(`"${parts.join("")}"`);
|
|
42
|
+
},
|
|
43
|
+
script,
|
|
44
|
+
concat: (...parts) => expr(parts.map((part) => stringPartToNix(part)).join(" + ")),
|
|
45
|
+
withPkgs: (packages) => expr(`with pkgs; [ ${packages.join(" ")} ]`),
|
|
46
|
+
optionalAttrs,
|
|
47
|
+
optionalString,
|
|
48
|
+
isDarwin: expr("pkgs.stdenv.isDarwin"),
|
|
49
|
+
isLinux: expr("pkgs.stdenv.isLinux"),
|
|
50
|
+
lib: {
|
|
51
|
+
mkDefault: (value) => nixLibCall("mkDefault", value),
|
|
52
|
+
mkForce: (value) => nixLibCall("mkForce", value),
|
|
53
|
+
mkBefore: (value) => nixLibCall("mkBefore", value),
|
|
54
|
+
mkAfter: (value) => nixLibCall("mkAfter", value),
|
|
55
|
+
optionalAttrs,
|
|
56
|
+
optionalString,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
function nixLibCall(name, value) {
|
|
60
|
+
return expr(`lib.${name} ${nixLiteral(value)}`);
|
|
61
|
+
}
|
|
62
|
+
function stringPartToNix(value) {
|
|
63
|
+
return isNixExpr(value) ? value.expr : JSON.stringify(value);
|
|
64
|
+
}
|
|
65
|
+
function conditionToNix(condition) {
|
|
66
|
+
if (isNixExpr(condition))
|
|
67
|
+
return condition.expr;
|
|
68
|
+
if (typeof condition === "boolean")
|
|
69
|
+
return condition ? "true" : "false";
|
|
70
|
+
return condition;
|
|
71
|
+
}
|
|
72
|
+
function nixLiteral(value) {
|
|
73
|
+
if (isNixExpr(value))
|
|
74
|
+
return value.expr;
|
|
75
|
+
if (typeof value === "string")
|
|
76
|
+
return JSON.stringify(value);
|
|
77
|
+
if (typeof value === "number")
|
|
78
|
+
return String(value);
|
|
79
|
+
if (typeof value === "boolean")
|
|
80
|
+
return value ? "true" : "false";
|
|
81
|
+
if (value === null)
|
|
82
|
+
return "null";
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return `[ ${value.map((item) => nixLiteral(item)).join(" ")} ]`;
|
|
85
|
+
}
|
|
86
|
+
if (isPlainObject(value)) {
|
|
87
|
+
return `{ ${formatAttrs(value)} }`;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Cannot convert ${typeof value} to a Nix literal`);
|
|
90
|
+
}
|
|
91
|
+
function formatAttrs(attrs) {
|
|
92
|
+
return Object.entries(attrs)
|
|
93
|
+
.filter(([, value]) => value !== undefined)
|
|
94
|
+
.map(([key, value]) => `${formatAttrKey(key)} = ${nixLiteral(value)};`)
|
|
95
|
+
.join(" ");
|
|
96
|
+
}
|
|
97
|
+
function formatAttrKey(key) {
|
|
98
|
+
return needsQuoting(key) ? JSON.stringify(key) : key;
|
|
99
|
+
}
|
|
100
|
+
function needsQuoting(key) {
|
|
101
|
+
if (NIX_KEYWORDS.has(key))
|
|
102
|
+
return true;
|
|
103
|
+
return !/^[a-zA-Z_][a-zA-Z0-9_'-]*$/.test(key);
|
|
104
|
+
}
|
|
105
|
+
function joinTemplate(strings, values, formatValue) {
|
|
106
|
+
const parts = [];
|
|
107
|
+
for (let index = 0; index < strings.length; index += 1) {
|
|
108
|
+
parts.push(strings[index]);
|
|
109
|
+
if (index < values.length) {
|
|
110
|
+
parts.push(formatValue(values[index]));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return parts.join("");
|
|
114
|
+
}
|
|
115
|
+
function joinRawTemplate(strings, values, formatValue) {
|
|
116
|
+
const parts = [];
|
|
117
|
+
for (let index = 0; index < strings.raw.length; index += 1) {
|
|
118
|
+
parts.push(strings.raw[index]);
|
|
119
|
+
if (index < values.length) {
|
|
120
|
+
parts.push(formatValue(values[index]));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return parts.join("");
|
|
124
|
+
}
|
|
125
|
+
function trimScript(body) {
|
|
126
|
+
return body.replace(/^\n/, "").replace(/\n\s*$/, "");
|
|
127
|
+
}
|
|
128
|
+
function escapeNixDoubleQuoted(value) {
|
|
129
|
+
return value
|
|
130
|
+
.replace(/\\/g, "\\\\")
|
|
131
|
+
.replace(/"/g, '\\"')
|
|
132
|
+
.replace(/\$\{/g, "\\${");
|
|
133
|
+
}
|
|
134
|
+
function isNixExpr(value) {
|
|
135
|
+
return (typeof value === "object" &&
|
|
136
|
+
value !== null &&
|
|
137
|
+
value.__winixNixExpr === true &&
|
|
138
|
+
typeof value.expr === "string");
|
|
139
|
+
}
|
|
140
|
+
function isPlainObject(value) {
|
|
141
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
142
|
+
}
|
|
143
|
+
const NIX_KEYWORDS = new Set([
|
|
144
|
+
"assert",
|
|
145
|
+
"else",
|
|
146
|
+
"false",
|
|
147
|
+
"if",
|
|
148
|
+
"in",
|
|
149
|
+
"inherit",
|
|
150
|
+
"let",
|
|
151
|
+
"null",
|
|
152
|
+
"or",
|
|
153
|
+
"rec",
|
|
154
|
+
"then",
|
|
155
|
+
"true",
|
|
156
|
+
"with",
|
|
157
|
+
]);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ProgramOptions, ServiceOptions } from "./options.js";
|
|
2
|
+
import type { Fragment } from "../core/types.js";
|
|
3
|
+
import type { BootOptions, EnvironmentOptions, FontsOptions, I18nOptions, NetworkingOptions, NixOptions, NixosOptions, NixosSecurityOptions, NixosSystemOptions, OciContainerOptions, PackageRef, SystemdOptions, SystemdService, SystemdTimer, TimeOptions, UsersOptions, VirtualisationOptions } from "../types/index.js";
|
|
4
|
+
export type SysctlSettings = Record<string, number | string | boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Map of NixOS program names to their option types.
|
|
7
|
+
* Starts empty; augmented by generated types (`winix types generate`).
|
|
8
|
+
* Allows typed autocomplete for `nixos.program("name", { ... })`.
|
|
9
|
+
*/
|
|
10
|
+
export interface NixosProgramOptions {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Map of NixOS service names to their option types.
|
|
14
|
+
* Starts empty; augmented by generated types (`winix types generate`).
|
|
15
|
+
* Allows typed autocomplete for `nixos.service("name", { ... })`.
|
|
16
|
+
*/
|
|
17
|
+
export interface NixosServiceOptions {
|
|
18
|
+
}
|
|
19
|
+
export interface VirtualisationHelper {
|
|
20
|
+
(config: VirtualisationOptions): Fragment;
|
|
21
|
+
ociContainer(name: string, config: OciContainerOptions): Fragment;
|
|
22
|
+
}
|
|
23
|
+
export interface SystemdHelper {
|
|
24
|
+
(config: SystemdOptions): Fragment;
|
|
25
|
+
service(name: string, config: SystemdService): Fragment;
|
|
26
|
+
userService(name: string, config: SystemdService): Fragment;
|
|
27
|
+
timer(name: string, config: SystemdTimer): Fragment;
|
|
28
|
+
tmpfiles(rules: string[]): Fragment;
|
|
29
|
+
}
|
|
30
|
+
export interface NixosHelper {
|
|
31
|
+
(config: NixosOptions): Fragment;
|
|
32
|
+
imports(imports: string[]): Fragment;
|
|
33
|
+
imports(...imports: string[]): Fragment;
|
|
34
|
+
program<const K extends string>(name: K, opts?: ProgramOptions<NixosProgramOptions, K>): Fragment;
|
|
35
|
+
service<const K extends string>(name: K, opts?: ServiceOptions<NixosServiceOptions, K>): Fragment;
|
|
36
|
+
packages(packages: PackageRef[]): Fragment;
|
|
37
|
+
packages(...packages: PackageRef[]): Fragment;
|
|
38
|
+
nix(config: NixOptions): Fragment;
|
|
39
|
+
boot(config: BootOptions): Fragment;
|
|
40
|
+
networking(config: NetworkingOptions): Fragment;
|
|
41
|
+
environment(config: EnvironmentOptions): Fragment;
|
|
42
|
+
users(config: UsersOptions): Fragment;
|
|
43
|
+
system(config: NixosSystemOptions): Fragment;
|
|
44
|
+
fonts(config: FontsOptions): Fragment;
|
|
45
|
+
security(config: NixosSecurityOptions): Fragment;
|
|
46
|
+
i18n(config: I18nOptions): Fragment;
|
|
47
|
+
time(config: TimeOptions): Fragment;
|
|
48
|
+
virtualisation: VirtualisationHelper;
|
|
49
|
+
sysctl(settings: SysctlSettings): Fragment;
|
|
50
|
+
systemd: SystemdHelper;
|
|
51
|
+
raw(config: string): Fragment;
|
|
52
|
+
}
|
|
53
|
+
export declare const nixos: NixosHelper;
|