@adrifer/winix 0.1.1-preview.1 → 0.1.2-preview.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/README.md +41 -14
- package/dist/cli/commands/apply.js +6 -9
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.js +44 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,10 +39,10 @@ const shell = feature("shell", () =>
|
|
|
39
39
|
shellAliases: {
|
|
40
40
|
g: "lazygit",
|
|
41
41
|
...(platforms.nixos.isActive && {
|
|
42
|
-
i: "
|
|
42
|
+
i: "cd ~/dotfiles/winix && npx @adrifer/winix switch",
|
|
43
43
|
}),
|
|
44
44
|
...(platforms.darwin.isActive && {
|
|
45
|
-
i: "
|
|
45
|
+
i: "cd ~/dotfiles/winix && npx @adrifer/winix switch --host macbook",
|
|
46
46
|
}),
|
|
47
47
|
},
|
|
48
48
|
})
|
|
@@ -76,31 +76,56 @@ export default workspace({
|
|
|
76
76
|
|
|
77
77
|
> Winix is early software. The core pipeline works end-to-end, but the public API is still evolving.
|
|
78
78
|
|
|
79
|
-
## Install
|
|
79
|
+
## Install and create a config
|
|
80
80
|
|
|
81
81
|
```bash
|
|
82
|
-
|
|
82
|
+
mkdir my-winix-config
|
|
83
|
+
cd my-winix-config
|
|
84
|
+
npx @adrifer/winix@latest init
|
|
85
|
+
npm install
|
|
83
86
|
```
|
|
84
87
|
|
|
85
88
|
Winix expects Node.js with native TypeScript stripping support for `winix.config.ts` files. Node 22+ is recommended.
|
|
86
89
|
|
|
87
|
-
|
|
90
|
+
If you prefer to set up files yourself instead of using `init`, add the package to your own `package.json`:
|
|
88
91
|
|
|
89
92
|
```bash
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
npm install @adrifer/winix
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The `init` command creates a starter `winix.config.ts`, `tsconfig.json`, `.gitignore`, and package scripts. After `npm install`, the `winix` binary comes from your local `node_modules`, so commands are reproducible through `package-lock.json`.
|
|
97
|
+
|
|
98
|
+
You can also install it globally, but local project installs are recommended:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install -g @adrifer/winix
|
|
92
102
|
```
|
|
93
103
|
|
|
94
104
|
## CLI
|
|
95
105
|
|
|
106
|
+
From a Winix project:
|
|
107
|
+
|
|
96
108
|
```bash
|
|
97
|
-
winix check # validate winix.config.ts
|
|
98
|
-
winix apply # generate .winix/out/
|
|
99
|
-
winix apply --dry # print generated Nix without writing files
|
|
100
|
-
winix apply --diff # show changes against current .winix/out/
|
|
101
|
-
winix switch --host my-host # generate and run nixos-rebuild/darwin-rebuild
|
|
102
|
-
winix update # update generated flake.lock and copy it back
|
|
103
|
-
winix inspect # inspect host composition and fragments
|
|
109
|
+
npx @adrifer/winix check # validate winix.config.ts
|
|
110
|
+
npx @adrifer/winix apply # generate .winix/out/
|
|
111
|
+
npx @adrifer/winix apply --dry # print generated Nix without writing files
|
|
112
|
+
npx @adrifer/winix apply --diff # show changes against current .winix/out/
|
|
113
|
+
npx @adrifer/winix switch --host my-host # generate and run nixos-rebuild/darwin-rebuild
|
|
114
|
+
npx @adrifer/winix update # update generated flake.lock and copy it back
|
|
115
|
+
npx @adrifer/winix inspect # inspect host composition and fragments
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If you add scripts to your `package.json`, you can use shorter commands:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"scripts": {
|
|
123
|
+
"check": "winix check",
|
|
124
|
+
"apply": "winix apply",
|
|
125
|
+
"dry": "winix apply --dry",
|
|
126
|
+
"switch": "winix switch"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
104
129
|
```
|
|
105
130
|
|
|
106
131
|
Generated output lives under:
|
|
@@ -277,6 +302,8 @@ Winix is currently best suited for personal configurations and experimentation.
|
|
|
277
302
|
|
|
278
303
|
## Development
|
|
279
304
|
|
|
305
|
+
Only clone this repository if you want to work on Winix itself. For normal configuration usage, install `@adrifer/winix` from npm as shown above.
|
|
306
|
+
|
|
280
307
|
```bash
|
|
281
308
|
git clone https://github.com/adrifer/winix.git
|
|
282
309
|
cd winix
|
|
@@ -5,7 +5,7 @@ import { existsSync } from "node:fs";
|
|
|
5
5
|
import { loadWorkspace } from "../loader.js";
|
|
6
6
|
import { evaluate } from "../../evaluator/index.js";
|
|
7
7
|
import { generateNix } from "../../backends/nix/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { platformForEvaluatedHost } from "../activation.js";
|
|
9
9
|
export async function applyWorkspace(cwd, opts) {
|
|
10
10
|
const { workspace, configDir } = await loadWorkspace(cwd);
|
|
11
11
|
let evaluated = evaluate(workspace);
|
|
@@ -64,17 +64,14 @@ function resultFor(configDir, outDir, evaluated) {
|
|
|
64
64
|
hostPlatforms: new Map(evaluated.map((host) => [host.name, platformForEvaluatedHost(host)])),
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
function printNextSteps(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const commands = evaluated.map((host) => activationCommand(platformForEvaluatedHost(host), `${flakeBase}#${host.name}`, false).join(" "));
|
|
71
|
-
if (commands.length === 1) {
|
|
72
|
-
console.log(`\nNext: ${commands[0]}`);
|
|
67
|
+
function printNextSteps(_cwd, _outDir, evaluated) {
|
|
68
|
+
if (evaluated.length === 1) {
|
|
69
|
+
console.log(`\nNext: winix switch`);
|
|
73
70
|
return;
|
|
74
71
|
}
|
|
75
72
|
console.log("\nNext:");
|
|
76
|
-
for (const
|
|
77
|
-
console.log(` ${
|
|
73
|
+
for (const host of evaluated) {
|
|
74
|
+
console.log(` winix switch --host ${host.name}`);
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
function printWarnings(warnings) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
export async function init(cwd, opts) {
|
|
5
6
|
await mkdir(cwd, { recursive: true });
|
|
7
|
+
const versionRange = await resolveWinixVersionRange();
|
|
8
|
+
const packageJson = renderPackageJson(versionRange);
|
|
6
9
|
await writeIfAllowed(join(cwd, "winix.config.ts"), CONFIG, opts.force);
|
|
7
10
|
await writeIfAllowed(join(cwd, "tsconfig.json"), TSCONFIG, opts.force);
|
|
8
|
-
await writeIfAllowed(join(cwd, "package.json"),
|
|
11
|
+
await writeIfAllowed(join(cwd, "package.json"), packageJson, opts.force);
|
|
9
12
|
await writeIfAllowed(join(cwd, ".gitignore"), GITIGNORE, opts.force);
|
|
10
13
|
console.log("✓ Initialized Winix project");
|
|
11
14
|
console.log("");
|
|
@@ -18,6 +21,45 @@ async function writeIfAllowed(path, content, force) {
|
|
|
18
21
|
}
|
|
19
22
|
await writeFile(path, content);
|
|
20
23
|
}
|
|
24
|
+
const FALLBACK_VERSION_RANGE = "^0.1.0";
|
|
25
|
+
export async function resolveWinixVersionRange() {
|
|
26
|
+
try {
|
|
27
|
+
const here = currentDir();
|
|
28
|
+
// Compiled layout: dist/cli/commands/init.js → ../../../package.json
|
|
29
|
+
// Source layout: src/cli/commands/init.ts → ../../../package.json
|
|
30
|
+
const pkgPath = join(here, "..", "..", "..", "package.json");
|
|
31
|
+
const raw = await readFile(pkgPath, "utf-8");
|
|
32
|
+
const parsed = JSON.parse(raw);
|
|
33
|
+
if (typeof parsed.version === "string" && /^\d+\.\d+\.\d+/.test(parsed.version)) {
|
|
34
|
+
return `^${parsed.version}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// fall through to default
|
|
39
|
+
}
|
|
40
|
+
return FALLBACK_VERSION_RANGE;
|
|
41
|
+
}
|
|
42
|
+
function currentDir() {
|
|
43
|
+
const filePath = fileURLToPath(import.meta.url);
|
|
44
|
+
const idx = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
|
|
45
|
+
return idx === -1 ? "." : filePath.slice(0, idx);
|
|
46
|
+
}
|
|
47
|
+
function renderPackageJson(versionRange) {
|
|
48
|
+
const escaped = JSON.stringify(versionRange);
|
|
49
|
+
return `{
|
|
50
|
+
"type": "module",
|
|
51
|
+
"private": true,
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@adrifer/winix": ${escaped}
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"check": "winix check",
|
|
57
|
+
"apply": "winix apply",
|
|
58
|
+
"switch": "winix switch"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
21
63
|
const CONFIG = `import { account, host, nixos, platforms, workspace } from "@adrifer/winix";
|
|
22
64
|
|
|
23
65
|
export default workspace({
|
|
@@ -36,19 +78,6 @@ export default workspace({
|
|
|
36
78
|
],
|
|
37
79
|
});
|
|
38
80
|
`;
|
|
39
|
-
const PACKAGE_JSON = `{
|
|
40
|
-
"type": "module",
|
|
41
|
-
"private": true,
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"@adrifer/winix": "^0.1.0"
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"check": "winix check",
|
|
47
|
-
"apply": "winix apply",
|
|
48
|
-
"switch": "winix switch"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
81
|
const GITIGNORE = `.winix/
|
|
53
82
|
node_modules/
|
|
54
83
|
`;
|
package/package.json
CHANGED