Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a474366708 | |||
| 1803d0211a | |||
| 5f11b96c1b | |||
| 526dc45652 | |||
| 4d4228670a | |||
| 999d616271 | |||
| 2a6922c6a5 | |||
| 7ace8b67c6 | |||
| 4a562136e6 | |||
| b89da14ed6 | |||
| a0000cd639 | |||
| 9793b3bc29 | |||
| 3489e2d8c3 | |||
| e4760a7aa0 | |||
| 2f3746ebff | |||
| 780ad73c03 | |||
| affd83b251 | |||
| 7e20c99dbd | |||
| 88762f81a9 | |||
| 7b9fe29d91 | |||
| 4795fa54eb | |||
| bec3e50af8 | |||
| 138c4e748c | |||
| 7b2eab0f02 | |||
| 7ee09f94c3 | |||
| dfa057fae0 | |||
| a79af99b14 | |||
| 65f0526420 | |||
| b00ad13101 | |||
| 5f843f60e2 | |||
| 01d7370b1d | |||
| 7c49e2a674 |
@@ -1,74 +0,0 @@
|
||||
{
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"typescript": {}
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"i18n-text/no-en": "off",
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "no-public"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-base-to-string": "error",
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "error",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error",
|
||||
{
|
||||
"allowExpressions": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-floating-promises": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- check-dist-up-to-date
|
||||
- install-nix
|
||||
@@ -24,17 +24,19 @@ jobs:
|
||||
|
||||
check-dist-up-to-date:
|
||||
name: Check the dist/ folder is up to date
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
- uses: DeterminateSystems/flakehub-cache-action@main
|
||||
- name: pnpm install
|
||||
run: nix develop --command pnpm install
|
||||
- name: prettier format
|
||||
- name: Check formatting
|
||||
run: nix develop --command pnpm run check-fmt
|
||||
- name: ESLint
|
||||
- name: Link
|
||||
run: nix develop --command pnpm run lint
|
||||
- name: Test
|
||||
run: nix develop --command pnpm run test
|
||||
- name: tsup build
|
||||
run: nix develop --command pnpm run build
|
||||
- name: ncc package
|
||||
@@ -146,7 +148,7 @@ jobs:
|
||||
|
||||
install-with-non-default-source-inputs:
|
||||
name: Install Nix using non-default source-${{ matrix.inputs.key }}
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
inputs:
|
||||
@@ -171,7 +173,7 @@ jobs:
|
||||
|
||||
install-no-id-token:
|
||||
name: Install Nix without an ID token
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
|
||||
@@ -53,9 +53,6 @@ typings/
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
@@ -1 +0,0 @@
|
||||
{}
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
|
||||
### With FlakeHub
|
||||
|
||||
To fetch private flakes from FlakeHub and Nix builds from FlakeHub Cache, update the `permissions` block and pass `determinate: true`:
|
||||
To fetch private flakes from FlakeHub and Nix builds from FlakeHub Cache, update the `permissions` block and use [`determinate-nix-action`][determinate-nix-action]:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
@@ -51,14 +51,25 @@ jobs:
|
||||
contents: "read"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: DeterminateSystems/nix-installer-action@main
|
||||
with:
|
||||
determinate: true
|
||||
- uses: DeterminateSystems/determinate-nix-action@v3
|
||||
- run: nix build .
|
||||
```
|
||||
|
||||
See [`.github/workflows/ci.yml`](.github/workflows/ci.yml) for a full example.
|
||||
|
||||
### Pinning the version
|
||||
|
||||
This GitHub Action uses the most recent version of the Determinate Nix Installer, even when the Action itself is pinned.
|
||||
If you wish to pin your CI workflows to a specific version, use the [`determinate-nix-action`][determinate-nix-action].
|
||||
That Action is updated and tagged for every Determinate release.
|
||||
|
||||
The `DeterminateSystems/determinate-nix-action@v3.5.2` reference, for example, always installs Determinate Nix v3.5.2.
|
||||
|
||||
Additionally, an extra tag on the major version is kept up to date with the current release.
|
||||
The `DeterminateSystems/determinate-nix-action@v3` reference, for example, installs the most recent release in the `v3.x.y` series.
|
||||
|
||||
If you do tag to a specific version, please [use Dependabot to update your actions][dependabot-actions].
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
- If KVM is available, the installer sets up KVM so that Nix can use it ,and exports the `DETERMINATE_NIX_KVM` environment variable set to 1.
|
||||
@@ -89,7 +100,7 @@ Differing from the upstream [Nix](https://github.com/NixOS/nix) installer script
|
||||
| `extra-args` | Extra arguments to pass to the planner (prefer using structured `with:` arguments unless using a custom [planner]!) | string | |
|
||||
| `extra-conf` | Extra configuration lines for `/etc/nix/nix.conf` (includes `access-tokens` with `secrets.GITHUB_TOKEN` automatically if `github-token` is set) | string | |
|
||||
| `flakehub` | Deprecated. Implies `determinate`. | Boolean | `false` |
|
||||
| `force-docker-shim` | Force the use of Docker as a process supervisor. This setting is automatically enabled when necessary. | Boolean | `false` |
|
||||
| `force-no-systemd` | Force using other methods than systemd to launch the daemon. This setting is automatically enabled when necessary. | Boolean | `false` |
|
||||
| `github-token` | A [GitHub token] for making authenticated requests (which have a higher rate-limit quota than unauthenticated requests) | string | `${{ github.token }}` |
|
||||
| `github-server-url` | The URL for the GitHub server, to use with the `github-token` token. Defaults to the current GitHub server, supporting GitHub Enterprise Server automatically. Only change this value if the provided `github-token` is for a different GitHub server than the current server. | string | `${{ github.server }}` |
|
||||
| `init` | The init system to configure (requires `planner: linux-multi`) | enum (`none` or `systemd`) | |
|
||||
@@ -123,6 +134,8 @@ Differing from the upstream [Nix](https://github.com/NixOS/nix) installer script
|
||||
|
||||
[apfs]: https://en.wikipedia.org/wiki/Apple_File_System
|
||||
[backtrace]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables
|
||||
[dependabot-actions]: https://github.com/DeterminateSystems/determinate-nix-action?tab=readme-ov-file#-automate-updates-with-dependabot
|
||||
[determinate-nix-action]: https://github.com/DeterminateSystems/determinate-nix-action
|
||||
[github token]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
|
||||
[planner]: https://github.com/determinateSystems/nix-installer#usage
|
||||
[profile]: https://nixos.org/manual/nix/stable/package-management/profiles
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ inputs:
|
||||
description: Deprecated. Implies `determinate`.
|
||||
required: false
|
||||
default: false
|
||||
force-docker-shim:
|
||||
description: Force the use of Docker as a process supervisor. This setting is automatically enabled when necessary.
|
||||
force-no-systemd:
|
||||
description: Force using other methods than systemd to launch the daemon. This setting is automatically enabled when necessary.
|
||||
required: false
|
||||
default: false
|
||||
github-token:
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
||||
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
|
||||
"files": {
|
||||
"ignoreUnknown": false,
|
||||
"ignore": ["dist"]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"useEditorconfig": true,
|
||||
"formatWithErrors": false,
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2,
|
||||
"lineEnding": "lf",
|
||||
"lineWidth": 80,
|
||||
"attributePosition": "auto",
|
||||
"bracketSpacing": true
|
||||
},
|
||||
"organizeImports": { "enabled": true },
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": false,
|
||||
"complexity": {
|
||||
"noExtraBooleanCast": "error",
|
||||
"noMultipleSpacesInRegularExpressionLiterals": "error",
|
||||
"noStaticOnlyClass": "error",
|
||||
"noUselessConstructor": "error",
|
||||
"noUselessStringConcat": "error",
|
||||
"noUselessTypeConstraint": "error"
|
||||
},
|
||||
"correctness": {
|
||||
"noConstAssign": "error",
|
||||
"noConstantCondition": "error",
|
||||
"noEmptyCharacterClassInRegex": "error",
|
||||
"noEmptyPattern": "error",
|
||||
"noGlobalObjectCalls": "error",
|
||||
"noInnerDeclarations": "error",
|
||||
"noInvalidConstructorSuper": "error",
|
||||
"noNewSymbol": "error",
|
||||
"noSelfAssign": "error",
|
||||
"noSwitchDeclarations": "error",
|
||||
"noUndeclaredVariables": "error",
|
||||
"noUnreachable": "error",
|
||||
"noUnreachableSuper": "error",
|
||||
"noUnsafeFinally": "error",
|
||||
"noUnusedLabels": "error",
|
||||
"noUnusedVariables": "error",
|
||||
"useArrayLiterals": "off",
|
||||
"useIsNan": "error",
|
||||
"useYield": "error"
|
||||
},
|
||||
"style": {
|
||||
"noArguments": "error",
|
||||
"noCommaOperator": "error",
|
||||
"noInferrableTypes": "error",
|
||||
"noNamespace": "error",
|
||||
"noNonNullAssertion": "warn",
|
||||
"noVar": "error",
|
||||
"useAsConstAssertion": "error",
|
||||
"useConsistentArrayType": "error",
|
||||
"useConst": "error",
|
||||
"useForOf": "warn",
|
||||
"useShorthandFunctionType": "warn",
|
||||
"useSingleVarDeclarator": "error",
|
||||
"useTemplate": "error"
|
||||
},
|
||||
"suspicious": {
|
||||
"noCatchAssign": "error",
|
||||
"noClassAssign": "error",
|
||||
"noCompareNegZero": "error",
|
||||
"noConsole": "error",
|
||||
"noControlCharactersInRegex": "error",
|
||||
"noDebugger": "error",
|
||||
"noDoubleEquals": "error",
|
||||
"noDuplicateCase": "error",
|
||||
"noDuplicateClassMembers": "error",
|
||||
"noDuplicateObjectKeys": "error",
|
||||
"noDuplicateParameters": "error",
|
||||
"noEmptyBlockStatements": "error",
|
||||
"noExplicitAny": "error",
|
||||
"noExtraNonNullAssertion": "error",
|
||||
"noFallthroughSwitchClause": "error",
|
||||
"noFunctionAssign": "error",
|
||||
"noGlobalAssign": "error",
|
||||
"noMisleadingInstantiator": "error",
|
||||
"noRedeclare": "error",
|
||||
"noSparseArray": "error",
|
||||
"noUnsafeDeclarationMerging": "error",
|
||||
"noUnsafeNegation": "error",
|
||||
"useNamespaceKeyword": "error",
|
||||
"useValidTypeof": "error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"jsxQuoteStyle": "double",
|
||||
"quoteProperties": "asNeeded",
|
||||
"trailingCommas": "all",
|
||||
"semicolons": "always",
|
||||
"arrowParentheses": "always",
|
||||
"bracketSameLine": false,
|
||||
"quoteStyle": "double",
|
||||
"attributePosition": "auto",
|
||||
"bracketSpacing": true
|
||||
},
|
||||
"globals": ["exports"]
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"include": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
|
||||
"linter": {
|
||||
"rules": {
|
||||
"complexity": { "noWith": "off" },
|
||||
"correctness": {
|
||||
"noConstAssign": "off",
|
||||
"noGlobalObjectCalls": "off",
|
||||
"noInvalidBuiltinInstantiation": "off",
|
||||
"noInvalidConstructorSuper": "off",
|
||||
"noNewSymbol": "off",
|
||||
"noSetterReturn": "off",
|
||||
"noUndeclaredVariables": "off",
|
||||
"noUnreachable": "off",
|
||||
"noUnreachableSuper": "off"
|
||||
},
|
||||
"style": {
|
||||
"noArguments": "error",
|
||||
"noVar": "error",
|
||||
"useConst": "error",
|
||||
"useNamingConvention": "error"
|
||||
},
|
||||
"suspicious": {
|
||||
"noClassAssign": "off",
|
||||
"noDuplicateClassMembers": "off",
|
||||
"noDuplicateObjectKeys": "off",
|
||||
"noDuplicateParameters": "off",
|
||||
"noFunctionAssign": "off",
|
||||
"noImportAssign": "off",
|
||||
"noRedeclare": "off",
|
||||
"noUnsafeNegation": "off",
|
||||
"useGetterReturn": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+5539
-3405
File diff suppressed because one or more lines are too long
@@ -1,19 +0,0 @@
|
||||
# Determinate Nix Installer: Docker Shim
|
||||
#
|
||||
# This empty image exists to lean on Docker as a process supervisor when
|
||||
# systemd isn't available. Specifically intended for self-hosted GitHub
|
||||
# Actions runners using Docker-in-Docker.
|
||||
#
|
||||
# See: https://github.com/DeterminateSystems/nix-installer-action
|
||||
|
||||
FROM scratch
|
||||
|
||||
ENTRYPOINT [ "/nix/var/nix/profiles/default/bin/nix-daemon"]
|
||||
CMD []
|
||||
|
||||
HEALTHCHECK \
|
||||
--interval=5m \
|
||||
--timeout=3s \
|
||||
CMD ["/nix/var/nix/profiles/default/bin/nix", "store", "ping", "--store", "daemon"]
|
||||
|
||||
COPY ./Dockerfile /README.md
|
||||
@@ -1,52 +0,0 @@
|
||||
# Determinate Nix Installer Action: Docker Shim
|
||||
|
||||
The image in this repository is a product of the contained Dockerfile.
|
||||
It is an otherwise empty image with a configuration layer.
|
||||
|
||||
This image is to be used in GitHub Actions runners which don't have systemd available, like self-hosted ARC runners.
|
||||
|
||||
The image would have no layers / content at all, however Docker has a bug and refuses to export those images.
|
||||
This isn't a technical limitation preventing us from creating and distributing that image, but an ease-of-use limitation.
|
||||
Since some of Docker's inspection tools break on an empty image, the image contains a single layer containing a README.
|
||||
|
||||
To build:
|
||||
|
||||
```shell
|
||||
docker build . --tag determinate-nix-shim:latest
|
||||
docker image save determinate-nix-shim:latest | gzip --best > amd64.tar
|
||||
```
|
||||
|
||||
Then, extract the tarball:
|
||||
|
||||
```
|
||||
mkdir extract
|
||||
cd extract
|
||||
tar -xf ../amd64.tar
|
||||
```
|
||||
|
||||
It'll look like this, though the hashes will be different.
|
||||
|
||||
```
|
||||
.
|
||||
├── 771204abb853cdde06bbbc680001a02642050a1db1a7b0a48cf5f20efa8bdc5d.json
|
||||
├── c4088111818e553e834adfc81bda8fe6da281afa9a40012eaa82796fb5476e98
|
||||
│ ├── VERSION
|
||||
│ ├── json
|
||||
│ └── layer.tar
|
||||
├── manifest.json
|
||||
└── repositories
|
||||
```
|
||||
|
||||
Ignore `manifest.json`, and edit the other two JSON documents to replace `amd64` with `arm64`, both in a key named "architecture:
|
||||
|
||||
```
|
||||
"architecture":"amd64"
|
||||
```
|
||||
|
||||
Then re-create the tar, from within the `extract` directory:
|
||||
|
||||
```
|
||||
tar --options gzip:compression-level=9 -zcf ../arm64.tar.gz .
|
||||
```
|
||||
|
||||
Then `git add` the two .tar.gz's and you're done.
|
||||
Binary file not shown.
Binary file not shown.
Generated
+12
-12
@@ -2,30 +2,30 @@
|
||||
"nodes": {
|
||||
"flake-schemas": {
|
||||
"locked": {
|
||||
"lastModified": 1693491534,
|
||||
"narHash": "sha256-ifw8Td8kD08J8DxFbYjeIx5naHcDLz7s2IFP3X42I/U=",
|
||||
"rev": "c702cbb663d6d70bbb716584a2ee3aeb35017279",
|
||||
"revCount": 21,
|
||||
"lastModified": 1721999734,
|
||||
"narHash": "sha256-G5CxYeJVm4lcEtaO87LKzOsVnWeTcHGKbKxNamNWgOw=",
|
||||
"rev": "0a5c42297d870156d9c57d8f99e476b738dcd982",
|
||||
"revCount": 75,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.1/018a4c59-80e1-708a-bb4d-854930c20f72/source.tar.gz"
|
||||
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.5/0190ef2f-61e0-794b-ba14-e82f225e55e6/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz"
|
||||
"url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/0.1"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1696879762,
|
||||
"narHash": "sha256-Ud6bH4DMcYHUDKavNMxAhcIpDGgHMyL/yaDEAVSImQY=",
|
||||
"rev": "f99e5f03cc0aa231ab5950a15ed02afec45ed51a",
|
||||
"revCount": 534224,
|
||||
"lastModified": 1748460289,
|
||||
"narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=",
|
||||
"rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102",
|
||||
"revCount": 807377,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.534224%2Brev-f99e5f03cc0aa231ab5950a15ed02afec45ed51a/018b1d3c-12f0-76a5-b796-7668d7633f08/source.tar.gz"
|
||||
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.807377%2Brev-96ec055edbe5ee227f28cdbc3f1ddf1df5965102/01972133-94d2-786e-bfeb-34136c7f0b07/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"
|
||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
description = "Development environment for the Nix Installer action for GitHub.";
|
||||
|
||||
inputs = {
|
||||
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz";
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz";
|
||||
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/0.1";
|
||||
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
|
||||
};
|
||||
|
||||
outputs = { self, flake-schemas, nixpkgs }:
|
||||
@@ -21,9 +21,9 @@
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
nodejs_latest
|
||||
nixpkgs-fmt
|
||||
nodePackages_latest.pnpm
|
||||
nodePackages_latest.typescript-language-server
|
||||
biome
|
||||
nixpkgs-fmt
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
+8
-16
@@ -7,12 +7,12 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"format": "prettier --write .",
|
||||
"check-fmt": "prettier --check .",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "biome format --write",
|
||||
"check-fmt": "biome format",
|
||||
"lint": "biome lint",
|
||||
"package": "ncc build",
|
||||
"test": "vitest --watch false",
|
||||
"all": "pnpm run test && pnpm run format && pnpm run lint && pnpm run build && pnpm run package"
|
||||
"all": "pnpm run test && pnpm run format && pnpm run lint && pnpm run test && pnpm run build && pnpm run package"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -28,25 +28,17 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/github": "^6.0.1",
|
||||
"detsys-ts": "github:DeterminateSystems/detsys-ts",
|
||||
"got": "^14.4.7",
|
||||
"string-argv": "^0.3.2",
|
||||
"vitest": "^3.1.1"
|
||||
"vitest": "^3.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@types/node": "^20.17.30",
|
||||
"@types/node": "^20.17.57",
|
||||
"@types/uuid": "^9.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-import-resolver-typescript": "^3.10.0",
|
||||
"eslint-plugin-github": "^4.10.2",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-prettier": "^5.2.6",
|
||||
"prettier": "^3.5.3",
|
||||
"tsup": "^8.4.0",
|
||||
"tsup": "^8.5.0",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+2046
-5709
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -1,8 +1,8 @@
|
||||
import { parseEvents, getRecentEvents } from "./events.js";
|
||||
import { expect, test } from "vitest";
|
||||
import { getRecentEvents, parseEvents } from "./events.js";
|
||||
|
||||
// Handy test for locally making sure you can fetch recent events:
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
// biome-ignore lint/correctness/noConstantCondition: testing
|
||||
if (false) {
|
||||
test("Parsing existing events", async () => {
|
||||
expect(await getRecentEvents(new Date(Date.now() - 1000000))).toStrictEqual(
|
||||
@@ -12,7 +12,7 @@ if (false) {
|
||||
}
|
||||
|
||||
test("Parsing existing events", () => {
|
||||
const events = parseEvents([
|
||||
const { events } = parseEvents([
|
||||
{
|
||||
v: "1",
|
||||
c: "BuiltPathResponseEventV1",
|
||||
|
||||
+23
-5
@@ -1,6 +1,6 @@
|
||||
import got from "got";
|
||||
|
||||
export interface DEvent {
|
||||
export interface Event {
|
||||
v: string;
|
||||
c: string;
|
||||
drv: string;
|
||||
@@ -10,12 +10,26 @@ export interface DEvent {
|
||||
};
|
||||
}
|
||||
|
||||
export function parseEvents(data: unknown): DEvent[] {
|
||||
export interface ParsedEventsResult {
|
||||
readonly events: Event[];
|
||||
readonly hasMismatches: boolean;
|
||||
}
|
||||
|
||||
export function parseEvents(data: unknown): ParsedEventsResult {
|
||||
let hasMismatches = false;
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
return [];
|
||||
return { events: [], hasMismatches };
|
||||
}
|
||||
|
||||
return data.flatMap((event) => {
|
||||
const events = data.flatMap((event) => {
|
||||
// If this was a hash mismatch event, note it and move on
|
||||
if (event.v === "1" && event.c === "HashMismatchResponseEventV1") {
|
||||
hasMismatches = true;
|
||||
return [];
|
||||
}
|
||||
|
||||
// Otherwise, determine if it's an event we're interested in
|
||||
if (
|
||||
event.v === "1" &&
|
||||
(event.c === "BuildFailureResponseEventV1" ||
|
||||
@@ -53,9 +67,13 @@ export function parseEvents(data: unknown): DEvent[] {
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
return { events, hasMismatches };
|
||||
}
|
||||
|
||||
export async function getRecentEvents(since: Date): Promise<DEvent[]> {
|
||||
export async function getRecentEvents(
|
||||
since: Date,
|
||||
): Promise<ParsedEventsResult> {
|
||||
const queryParam = encodeURIComponent(since.toISOString());
|
||||
|
||||
const resp = await got
|
||||
|
||||
+16
-11
@@ -5,8 +5,6 @@ import {
|
||||
summarizeFailures,
|
||||
} from "./failuresummary.js";
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
test("Select for failure events", () => {
|
||||
const events = [
|
||||
{
|
||||
@@ -99,10 +97,12 @@ test("Summarize Failures", async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const summary: FailureSummary = (await summarizeFailures(events, logMaker))!;
|
||||
|
||||
expect(summary.markdownLines.join("\n"))
|
||||
.toStrictEqual(`### Build error review :boom:
|
||||
expect(
|
||||
summary.markdownLines.join("\n"),
|
||||
).toStrictEqual(`### Build error review :boom:
|
||||
> [!NOTE]
|
||||
> 2 builds failed
|
||||
<details><summary>Failure log: <code>/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-<strong>dep-1</strong>.drv</code></summary>
|
||||
@@ -150,8 +150,9 @@ test("Summarize Failures", async () => {
|
||||
</details>
|
||||
`);
|
||||
|
||||
expect(summary.logLines.join("\n"))
|
||||
.toStrictEqual(`\u001b[38;2;255;0;0mBuild logs from 2 failures
|
||||
expect(
|
||||
summary.logLines.join("\n"),
|
||||
).toStrictEqual(`\u001b[38;2;255;0;0mBuild logs from 2 failures
|
||||
The following build logs are also available in the Markdown summary:
|
||||
::group::Failed build: /nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-1.drv
|
||||
/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-1.drv
|
||||
@@ -228,14 +229,16 @@ test("Omit some logs if there are too many", async () => {
|
||||
return `${drv}\n`.repeat(5).trimEnd();
|
||||
};
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const summary: FailureSummary = (await summarizeFailures(
|
||||
events,
|
||||
logMaker,
|
||||
500,
|
||||
))!;
|
||||
|
||||
expect(summary.markdownLines.join("\n"))
|
||||
.toStrictEqual(`### Build error review :boom:
|
||||
expect(
|
||||
summary.markdownLines.join("\n"),
|
||||
).toStrictEqual(`### Build error review :boom:
|
||||
> [!NOTE]
|
||||
> 2 builds failed
|
||||
<details><summary>Failure log: <code>/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-<strong>dep-1</strong>.drv</code></summary>
|
||||
@@ -248,13 +251,15 @@ test("Omit some logs if there are too many", async () => {
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> The following failure has been ommitted due to GitHub Actions summary length limitations.
|
||||
> The following failure has been omitted due to GitHub Actions' summary length limitations.
|
||||
> The full logs are available in the post-run phase of the Nix Installer Action.
|
||||
> * \`/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-3.drv\``);
|
||||
|
||||
expect(summary.logLines.join("\n"))
|
||||
.toStrictEqual(`\u001b[38;2;255;0;0mBuild logs from 2 failures
|
||||
expect(
|
||||
summary.logLines.join("\n"),
|
||||
).toStrictEqual(`\u001b[38;2;255;0;0mBuild logs from 2 failures
|
||||
The following build logs are also available in the Markdown summary:
|
||||
::group::Failed build: /nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-1.drv
|
||||
/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-1.drv
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { getExecOutput } from "@actions/exec";
|
||||
import { DEvent } from "./events.js";
|
||||
import { stripVTControlCharacters } from "node:util";
|
||||
import { getExecOutput } from "@actions/exec";
|
||||
import { Event } from "./events.js";
|
||||
|
||||
// CI summaries have a max length of "1024k" which I assume to be 1048576 bytes.
|
||||
// Generously, the mermaid doc is about 50,000 bytes.
|
||||
// Rounding it all down a bit further for wiggle room, that leaves lots of log space.
|
||||
const defaultMaxSummaryLength = 995_000;
|
||||
|
||||
export function getBuildFailures(events: DEvent[]): DEvent[] {
|
||||
return events.filter((event: DEvent): Boolean => {
|
||||
export function getBuildFailures(events: Event[]): Event[] {
|
||||
return events.filter((event: Event): Boolean => {
|
||||
return event.c === "BuildFailureResponseEventV1";
|
||||
});
|
||||
}
|
||||
@@ -19,7 +19,7 @@ export interface FailureSummary {
|
||||
}
|
||||
|
||||
export async function summarizeFailures(
|
||||
events: DEvent[],
|
||||
events: Event[],
|
||||
getLog: (drv: string) => Promise<string | undefined> = getLogFromNix,
|
||||
maxLength: number = defaultMaxSummaryLength,
|
||||
): Promise<FailureSummary | undefined> {
|
||||
@@ -97,8 +97,9 @@ export async function summarizeFailures(
|
||||
|
||||
if (skippedChunks.length > 0) {
|
||||
markdownLines.push(
|
||||
"",
|
||||
"> [!NOTE]",
|
||||
`> The following ${skippedChunks.length === 1 ? "failure has" : "failures have"} been ommitted due to GitHub Actions summary length limitations.`,
|
||||
`> The following ${skippedChunks.length === 1 ? "failure has" : "failures have"} been omitted due to GitHub Actions' summary length limitations.`,
|
||||
"> The full logs are available in the post-run phase of the Nix Installer Action.",
|
||||
);
|
||||
|
||||
|
||||
+194
-426
@@ -1,21 +1,21 @@
|
||||
import { SpawnOptions, spawn } from "node:child_process";
|
||||
import fs, { mkdirSync, openSync } from "node:fs";
|
||||
import { access, readFile, stat, writeFile } from "node:fs/promises";
|
||||
import { userInfo } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { setTimeout } from "node:timers/promises";
|
||||
import * as path from "path";
|
||||
import * as actionsCore from "@actions/core";
|
||||
import * as actionsExec from "@actions/exec";
|
||||
import * as github from "@actions/github";
|
||||
import { access, readFile, stat } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import fs from "node:fs";
|
||||
import { userInfo } from "node:os";
|
||||
import stringArgv from "string-argv";
|
||||
import * as path from "path";
|
||||
import { DetSysAction, inputs, platform, stringifyError } from "detsys-ts";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import got from "got";
|
||||
import { setTimeout } from "node:timers/promises";
|
||||
import { getFixHashes } from "./fixHashes.js";
|
||||
import stringArgv from "string-argv";
|
||||
import { annotateMismatches } from "./annotate.js";
|
||||
import { getRecentEvents } from "./events.js";
|
||||
import { makeMermaidReport } from "./mermaid.js";
|
||||
import { summarizeFailures } from "./failuresummary.js";
|
||||
import { getFixHashes } from "./fixHashes.js";
|
||||
import { makeMermaidReport } from "./mermaid.js";
|
||||
|
||||
// Nix installation events
|
||||
const EVENT_INSTALL_NIX_FAILURE = "install_nix_failure";
|
||||
@@ -24,35 +24,34 @@ const EVENT_INSTALL_NIX_SUCCESS = "install_nix_start";
|
||||
const EVENT_SETUP_KVM = "setup_kvm";
|
||||
const EVENT_UNINSTALL_NIX = "uninstall";
|
||||
|
||||
// Docker events
|
||||
const EVENT_CLEAN_UP_DOCKER_SHIM = "clean_up_docker_shim";
|
||||
const EVENT_START_DOCKER_SHIM = "start_docker_shim";
|
||||
|
||||
// FlakeHub events
|
||||
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
|
||||
|
||||
// Other events
|
||||
const EVENT_CONCLUDE_JOB = "conclude_job";
|
||||
const EVENT_FOD_ANNOTATE = "fod_annotate";
|
||||
const EVENT_NO_SYSTEMD_SHIM_FAILED = "no-systemd-shim-failed";
|
||||
|
||||
// Feature flag names
|
||||
const FEAT_ANNOTATIONS = "hash-mismatch-annotations";
|
||||
|
||||
// Facts
|
||||
const FACT_DETERMINATE_NIX = "determinate_nix";
|
||||
const FACT_HAS_DOCKER = "has_docker";
|
||||
const FACT_HAS_SYSTEMD = "has_systemd";
|
||||
const FACT_IN_ACT = "in_act";
|
||||
const FACT_IN_NAMESPACE_SO = "in_namespace_so";
|
||||
const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
|
||||
const FACT_SENT_SIGTERM = "sent_sigterm";
|
||||
|
||||
// Flags
|
||||
const FLAG_DETERMINATE = "--determinate";
|
||||
|
||||
// Pre/post state keys
|
||||
const STATE_DAEMONDIR = "DNI_DAEMONDIR";
|
||||
const STATE_START_DATETIME = "DETERMINATE_NIXD_START_DATETIME";
|
||||
|
||||
class NixInstallerAction extends DetSysAction {
|
||||
private daemonDir: string;
|
||||
determinate: boolean;
|
||||
platform: string;
|
||||
nixPackageUrl: string | null;
|
||||
@@ -62,7 +61,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
kvm: boolean;
|
||||
githubServerUrl: string | null;
|
||||
githubToken: string | null;
|
||||
forceDockerShim: boolean;
|
||||
forceNoSystemd: boolean;
|
||||
init: string | null;
|
||||
jobConclusion: string | null;
|
||||
localRoot: string | null;
|
||||
@@ -95,6 +94,14 @@ class NixInstallerAction extends DetSysAction {
|
||||
diagnosticsSuffix: "diagnostic",
|
||||
});
|
||||
|
||||
if (actionsCore.getState(STATE_DAEMONDIR) !== "") {
|
||||
this.daemonDir = actionsCore.getState(STATE_DAEMONDIR);
|
||||
} else {
|
||||
this.daemonDir = this.getTemporaryName();
|
||||
mkdirSync(this.daemonDir);
|
||||
actionsCore.saveState(STATE_DAEMONDIR, this.daemonDir);
|
||||
}
|
||||
|
||||
this.determinate =
|
||||
inputs.getBool("determinate") || inputs.getBool("flakehub");
|
||||
this.platform = platform.getNixPlatform(platform.getArchOs());
|
||||
@@ -103,7 +110,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
this.extraArgs = inputs.getStringOrNull("extra-args");
|
||||
this.extraConf = inputs.getMultilineStringOrNull("extra-conf");
|
||||
this.kvm = inputs.getBool("kvm");
|
||||
this.forceDockerShim = inputs.getBool("force-docker-shim");
|
||||
this.forceNoSystemd = inputs.getBool("force-no-systemd");
|
||||
this.githubToken = inputs.getStringOrNull("github-token");
|
||||
this.githubServerUrl = inputs.getStringOrNull("github-server-url");
|
||||
this.init = inputs.getStringOrNull("init");
|
||||
@@ -132,7 +139,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
|
||||
async main(): Promise<void> {
|
||||
await this.scienceDebugFly();
|
||||
await this.detectAndForceDockerShim();
|
||||
await this.detectAndForceNoSystemd();
|
||||
await this.install();
|
||||
actionsCore.saveState(STATE_START_DATETIME, new Date().toISOString());
|
||||
}
|
||||
@@ -146,11 +153,11 @@ class NixInstallerAction extends DetSysAction {
|
||||
exception: stringifyError(err),
|
||||
});
|
||||
}
|
||||
await this.cleanupDockerShim();
|
||||
await this.cleanupNoSystemd();
|
||||
await this.reportOverall();
|
||||
}
|
||||
|
||||
private get isMacOS(): boolean {
|
||||
private get isMacOs(): boolean {
|
||||
return this.runnerOs === "macOS";
|
||||
}
|
||||
|
||||
@@ -187,17 +194,22 @@ class NixInstallerAction extends DetSysAction {
|
||||
});
|
||||
|
||||
this.recordEvent("debug-probe-urls:response", {
|
||||
debug_probe_urls_ip: resp.ip, // eslint-disable-line camelcase
|
||||
debug_probe_urls_ok: resp.ok, // eslint-disable-line camelcase
|
||||
debug_probe_urls_status_code: resp.statusCode, // eslint-disable-line camelcase
|
||||
debug_probe_urls_body: resp.body, // eslint-disable-line camelcase
|
||||
// eslint-disable-next-line camelcase
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_ip: resp.ip,
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_ok: resp.ok,
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_status_code: resp.statusCode,
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_body: resp.body,
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_elapsed:
|
||||
(resp.timings.end ?? 0) - resp.timings.start,
|
||||
});
|
||||
} catch (e: unknown) {
|
||||
this.recordEvent("debug-probe-urls:exception", {
|
||||
debug_probe_urls_exception: stringifyError(e), // eslint-disable-line camelcase
|
||||
// biome-ignore lint/style/useNamingConvention: Posthog JSON
|
||||
debug_probe_urls_exception: stringifyError(e),
|
||||
});
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
@@ -207,211 +219,37 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
}
|
||||
|
||||
// Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker.
|
||||
// Detect if we're in a GHA runner which is Linux and doesn't have Systemd.
|
||||
// This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/),
|
||||
// and especially GitHub Enterprise Server.
|
||||
async detectAndForceDockerShim(): Promise<void> {
|
||||
async detectAndForceNoSystemd(): Promise<void> {
|
||||
if (!this.isLinux) {
|
||||
if (this.forceDockerShim) {
|
||||
if (this.forceNoSystemd) {
|
||||
this.forceNoSystemd = false;
|
||||
actionsCore.warning(
|
||||
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux.",
|
||||
"Ignoring force-no-systemd which is set to true, as it is only supported on Linux.",
|
||||
);
|
||||
this.forceDockerShim = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isRunningInAct) {
|
||||
actionsCore.debug(
|
||||
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
actionsCore.startGroup("Detecting systemd...");
|
||||
const systemdCheck = fs.statSync("/run/systemd/system", {
|
||||
throwIfNoEntry: false,
|
||||
});
|
||||
if (systemdCheck?.isDirectory()) {
|
||||
this.addFact(FACT_HAS_SYSTEMD, true);
|
||||
if (this.forceDockerShim) {
|
||||
actionsCore.warning(
|
||||
"Systemd is detected, but ignoring it since force-docker-shim is enabled.",
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.addFact(FACT_HAS_SYSTEMD, false);
|
||||
} else {
|
||||
this.addFact(FACT_HAS_SYSTEMD, false);
|
||||
|
||||
actionsCore.debug(
|
||||
"Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.",
|
||||
);
|
||||
|
||||
this.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
|
||||
let exitCode;
|
||||
try {
|
||||
exitCode = await actionsExec.exec("docker", ["info"], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
actionsCore.debug("Docker not detected, not enabling docker shim.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (exitCode !== 0) {
|
||||
if (this.forceDockerShim) {
|
||||
actionsCore.warning(
|
||||
"docker info check failed, but trying anyway since force-docker-shim is enabled.",
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.addFact(FACT_HAS_DOCKER, true);
|
||||
|
||||
if (
|
||||
!this.forceDockerShim &&
|
||||
(await this.detectDockerWithMountedDockerSocket())
|
||||
) {
|
||||
actionsCore.debug(
|
||||
"Detected a Docker container with a Docker socket mounted, not enabling docker shim.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
actionsCore.startGroup(
|
||||
"Enabling the Docker shim for running Nix on Linux in CI without Systemd.",
|
||||
);
|
||||
|
||||
if (this.init !== "none") {
|
||||
actionsCore.info(`Changing init from '${this.init}' to 'none'`);
|
||||
this.forceNoSystemd = true;
|
||||
this.init = "none";
|
||||
}
|
||||
if (this.planner !== "linux") {
|
||||
actionsCore.info(`Changing planner from '${this.planner}' to 'linux'`);
|
||||
this.planner = "linux";
|
||||
}
|
||||
|
||||
this.forceDockerShim = true;
|
||||
|
||||
actionsCore.endGroup();
|
||||
}
|
||||
|
||||
// Detect if we are running under `act` or some other system which is not using docker-in-docker,
|
||||
// and instead using a mounted docker socket.
|
||||
// In the case of the socket mount solution, the shim will cause issues since the given mount paths will
|
||||
// equate to mount paths on the host, not mount paths to the docker container in question.
|
||||
async detectDockerWithMountedDockerSocket(): Promise<boolean> {
|
||||
let cgroupsBuffer;
|
||||
try {
|
||||
// If we are inside a docker container, the last line of `/proc/self/cgroup` should be
|
||||
// 0::/docker/$SOME_ID
|
||||
//
|
||||
// If we are not, the line will likely be `0::/`
|
||||
cgroupsBuffer = await readFile("/proc/self/cgroup", {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
} catch (e) {
|
||||
actionsCore.debug(
|
||||
`Did not detect \`/proc/self/cgroup\` existence, bailing on docker container ID detection:\n${e}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const cgroups = cgroupsBuffer.trim().split("\n");
|
||||
const lastCgroup = cgroups[cgroups.length - 1];
|
||||
const lastCgroupParts = lastCgroup.split(":");
|
||||
const lastCgroupPath = lastCgroupParts[lastCgroupParts.length - 1];
|
||||
if (!lastCgroupPath.includes("/docker/")) {
|
||||
actionsCore.debug(
|
||||
"Did not detect a container ID, bailing on docker.sock detection",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
// We are in a docker container, now to determine if this container is visible from
|
||||
// the `docker` command, and if so, if there is a `docker.socket` mounted.
|
||||
const lastCgroupPathParts = lastCgroupPath.split("/");
|
||||
const containerId = lastCgroupPathParts[lastCgroupPathParts.length - 1];
|
||||
|
||||
// If we cannot `docker inspect` this discovered container ID, we'll fall through to the `catch` below.
|
||||
let stdoutBuffer = "";
|
||||
let stderrBuffer = "";
|
||||
let exitCode;
|
||||
try {
|
||||
exitCode = await actionsExec.exec("docker", ["inspect", containerId], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
stdoutBuffer += data.toString("utf-8");
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
stderrBuffer += data.toString("utf-8");
|
||||
},
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
actionsCore.debug(
|
||||
`Could not execute \`docker inspect ${containerId}\`, bailing on docker container inspection:\n${e}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (exitCode !== 0) {
|
||||
actionsCore.debug(
|
||||
`Unable to inspect detected docker container with id \`${containerId}\`, bailing on container inspection (exit ${exitCode}):\n${stderrBuffer}`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const output = JSON.parse(stdoutBuffer);
|
||||
// `docker inspect $ID` prints an array containing objects.
|
||||
// In our use case, we should only see 1 item in the array.
|
||||
if (output.length !== 1) {
|
||||
actionsCore.debug(
|
||||
`Got \`docker inspect ${containerId}\` output which was not one item (was ${output.length}), bailing on docker.sock detection.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
const item = output[0];
|
||||
// On this array item we want the `Mounts` field, which is an array
|
||||
// containing `{ Type, Source, Destination, Mode}`.
|
||||
// We are looking for a `Destination` ending with `docker.sock`.
|
||||
const mounts = item["Mounts"];
|
||||
if (typeof mounts !== "object") {
|
||||
actionsCore.debug(
|
||||
`Got non-object in \`Mounts\` field of \`docker inspect ${containerId}\` output, bailing on docker.sock detection.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
let foundDockerSockMount = false;
|
||||
for (const mount of mounts) {
|
||||
const destination = mount["Destination"];
|
||||
if (typeof destination === "string") {
|
||||
if (destination.endsWith("docker.sock")) {
|
||||
foundDockerSockMount = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundDockerSockMount;
|
||||
}
|
||||
|
||||
private async executionEnvironment(): Promise<ExecuteEnvironment> {
|
||||
const executionEnv: ExecuteEnvironment = {};
|
||||
|
||||
@@ -469,14 +307,14 @@ class NixInstallerAction extends DetSysAction {
|
||||
|
||||
// TODO: Error if the user uses these on not-MacOS
|
||||
if (this.macEncrypt !== null) {
|
||||
if (!this.isMacOS) {
|
||||
if (!this.isMacOs) {
|
||||
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
|
||||
}
|
||||
|
||||
if (this.macCaseSensitive !== null) {
|
||||
if (!this.isMacOS) {
|
||||
if (!this.isMacOs) {
|
||||
throw new Error(
|
||||
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
@@ -485,7 +323,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
|
||||
if (this.macVolumeLabel !== null) {
|
||||
if (!this.isMacOS) {
|
||||
if (!this.isMacOs) {
|
||||
throw new Error(
|
||||
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
@@ -494,7 +332,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
|
||||
if (this.macRootDisk !== null) {
|
||||
if (!this.isMacOS) {
|
||||
if (!this.isMacOs) {
|
||||
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
|
||||
@@ -510,7 +348,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
|
||||
// TODO: Error if the user uses these on MacOS
|
||||
if (this.init !== null) {
|
||||
if (this.isMacOS) {
|
||||
if (this.isMacOs) {
|
||||
throw new Error(
|
||||
"`init` is not a valid option when `$RUNNER_OS` is `macOS`",
|
||||
);
|
||||
@@ -667,8 +505,8 @@ class NixInstallerAction extends DetSysAction {
|
||||
await this.executeInstall(binaryPath);
|
||||
actionsCore.endGroup();
|
||||
|
||||
if (this.forceDockerShim) {
|
||||
await this.spawnDockerShim();
|
||||
if (this.forceNoSystemd) {
|
||||
await this.spawnDetached();
|
||||
}
|
||||
|
||||
await this.setGithubPath();
|
||||
@@ -678,192 +516,83 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
}
|
||||
|
||||
async spawnDockerShim(): Promise<void> {
|
||||
async spawnDetached(): Promise<void> {
|
||||
actionsCore.startGroup(
|
||||
"Configuring the Docker shim as the Nix Daemon's process supervisor",
|
||||
"Directly spawning the daemon, since systemd is not available.",
|
||||
);
|
||||
|
||||
const images: { [key: string]: string } = {
|
||||
X64: path.join(__dirname, "/../docker-shim/amd64.tar.gz"),
|
||||
ARM64: path.join(__dirname, "/../docker-shim/arm64.tar.gz"),
|
||||
const outputPath = path.join(this.daemonDir, "daemon.log");
|
||||
const output = openSync(outputPath, "a");
|
||||
|
||||
const opts: SpawnOptions = {
|
||||
stdio: ["ignore", output, output],
|
||||
detached: true,
|
||||
};
|
||||
|
||||
const runnerArch = process.env["RUNNER_ARCH"];
|
||||
let arch;
|
||||
const daemonBin = this.determinate
|
||||
? "/usr/local/bin/determinate-nixd"
|
||||
: "/nix/var/nix/profiles/default/bin/nix-daemon";
|
||||
const daemonCliFlags = this.determinate ? ["daemon"] : [];
|
||||
|
||||
if (runnerArch === "X64") {
|
||||
arch = "X64";
|
||||
} else if (runnerArch === "ARM64") {
|
||||
arch = "ARM64";
|
||||
let executable: string;
|
||||
let args: string[];
|
||||
|
||||
if (userInfo().uid === 0) {
|
||||
executable = daemonBin;
|
||||
args = daemonCliFlags;
|
||||
} else {
|
||||
throw Error("Architecture not supported in Docker shim mode.");
|
||||
}
|
||||
actionsCore.debug("Loading image: determinate-nix-shim:latest...");
|
||||
{
|
||||
const exitCode = await actionsExec.exec(
|
||||
"docker",
|
||||
["image", "load", "--input", images[arch]],
|
||||
{
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(
|
||||
`Failed to build the shim image, exit code: \`${exitCode}\``,
|
||||
);
|
||||
}
|
||||
executable = "sudo";
|
||||
args = [daemonBin].concat(daemonCliFlags);
|
||||
}
|
||||
|
||||
{
|
||||
actionsCore.debug("Starting the Nix daemon through Docker...");
|
||||
// Display the final command for debugging purposes
|
||||
actionsCore.debug("Full daemon start command:");
|
||||
actionsCore.debug(`${executable} ${args.join(" ")}`);
|
||||
|
||||
const candidateDirectories = [
|
||||
{
|
||||
dir: "/bin",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/etc",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/home",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/lib",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/lib64",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/tmp",
|
||||
readOnly: false,
|
||||
},
|
||||
{
|
||||
dir: "/usr",
|
||||
readOnly: true,
|
||||
},
|
||||
{
|
||||
dir: "/nix",
|
||||
readOnly: false,
|
||||
},
|
||||
];
|
||||
// Start the server, and wait for the socket to exist
|
||||
const daemon = spawn(executable, args, opts);
|
||||
|
||||
const mountArguments = [];
|
||||
const pidFile = path.join(this.daemonDir, "daemon.pid");
|
||||
if (daemon.pid) {
|
||||
await writeFile(pidFile, daemon.pid.toString());
|
||||
}
|
||||
|
||||
for (const { dir, readOnly } of candidateDirectories) {
|
||||
try {
|
||||
await access(dir);
|
||||
actionsCore.debug(`Will mount ${dir} in the docker shim.`);
|
||||
mountArguments.push("--mount");
|
||||
mountArguments.push(
|
||||
`type=bind,src=${dir},dst=${dir}${readOnly ? ",readonly" : ""}`,
|
||||
);
|
||||
} catch {
|
||||
actionsCore.debug(
|
||||
`Not mounting ${dir} in the docker shim: it doesn't appear to exist.`,
|
||||
);
|
||||
try {
|
||||
for (let i = 0; i <= 2400; i++) {
|
||||
// Approximately 2 minutes
|
||||
if (daemon.signalCode !== null || daemon.exitCode !== null) {
|
||||
let msg: string;
|
||||
if (daemon.signalCode) {
|
||||
msg = `Daemon was killed by signal ${daemon.signalCode}`;
|
||||
} else {
|
||||
msg = `Daemon exited with code ${daemon.exitCode}`;
|
||||
}
|
||||
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
if (await this.doesTheSocketExistYet()) {
|
||||
break;
|
||||
}
|
||||
|
||||
await setTimeout(50);
|
||||
}
|
||||
|
||||
const plausibleDeterminateOptions = [];
|
||||
const plausibleDeterminateArguments = [];
|
||||
if (this.determinate) {
|
||||
plausibleDeterminateOptions.push("--entrypoint");
|
||||
plausibleDeterminateOptions.push("/usr/local/bin/determinate-nixd");
|
||||
plausibleDeterminateArguments.push("daemon");
|
||||
if (!(await this.doesTheSocketExistYet())) {
|
||||
throw new Error("Timed out waiting for the daemon socket to appear.");
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
this.recordEvent(EVENT_NO_SYSTEMD_SHIM_FAILED, {
|
||||
error: stringifyError(error),
|
||||
log: await readFile(outputPath, "utf-8"),
|
||||
});
|
||||
|
||||
this.recordEvent(EVENT_START_DOCKER_SHIM);
|
||||
const exitCode = await actionsExec.exec(
|
||||
"docker",
|
||||
[
|
||||
"--log-level=debug",
|
||||
"run",
|
||||
"--detach",
|
||||
"--privileged",
|
||||
"--network=host",
|
||||
"--userns=host",
|
||||
"--pid=host",
|
||||
"--restart",
|
||||
"always",
|
||||
"--init",
|
||||
"--name",
|
||||
`determinate-nix-shim-${this.getUniqueId()}-${randomUUID()}`,
|
||||
]
|
||||
.concat(plausibleDeterminateOptions)
|
||||
.concat(mountArguments)
|
||||
.concat(["determinate-nix-shim:latest"])
|
||||
.concat(plausibleDeterminateArguments),
|
||||
{
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdline: (data: string) => {
|
||||
actionsCore.saveState("docker_shim_container_id", data.trimEnd());
|
||||
},
|
||||
stdout: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
const trimmed = data.toString("utf-8").trimEnd();
|
||||
if (trimmed.length >= 0) {
|
||||
actionsCore.debug(trimmed);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (exitCode !== 0) {
|
||||
throw new Error(
|
||||
`Failed to start the Nix daemon through Docker, exit code: \`${exitCode}\``,
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const maxDurationSeconds = 120;
|
||||
const delayPerAttemptInMiliseconds = 50;
|
||||
const maxAttempts =
|
||||
(maxDurationSeconds * 1000) / delayPerAttemptInMiliseconds;
|
||||
let didSucceed = false;
|
||||
|
||||
for (let attempt = 0; attempt <= maxAttempts; attempt += 1) {
|
||||
if (await this.doesTheSocketExistYet()) {
|
||||
didSucceed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
await setTimeout(50);
|
||||
}
|
||||
|
||||
if (!didSucceed) {
|
||||
throw new Error("Timed out waiting for the Nix Daemon");
|
||||
}
|
||||
daemon.unref();
|
||||
|
||||
actionsCore.endGroup();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async doesTheSocketExistYet(): Promise<boolean> {
|
||||
@@ -872,7 +601,6 @@ class NixInstallerAction extends DetSysAction {
|
||||
await stat(socketPath);
|
||||
return true;
|
||||
} catch (error: unknown) {
|
||||
// eslint-disable-next-line no-undef
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||
actionsCore.debug(`Socket '${socketPath}' does not exist yet`);
|
||||
return false;
|
||||
@@ -881,7 +609,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
actionsCore.warning(
|
||||
`Error waiting for the Nix Daemon socket: ${stringifyError(error)}`,
|
||||
);
|
||||
this.recordEvent("docker-shim:wait-for-socket", {
|
||||
this.recordEvent("shim:wait-for-socket", {
|
||||
exception: stringifyError(error),
|
||||
});
|
||||
throw error;
|
||||
@@ -890,12 +618,14 @@ class NixInstallerAction extends DetSysAction {
|
||||
|
||||
async summarizeExecution(): Promise<void> {
|
||||
const startDate = new Date(actionsCore.getState(STATE_START_DATETIME));
|
||||
const events = await getRecentEvents(startDate);
|
||||
const { events, hasMismatches } = await getRecentEvents(startDate);
|
||||
|
||||
const mermaidSummary = makeMermaidReport(events);
|
||||
const failureSummary = await summarizeFailures(events);
|
||||
|
||||
if (mermaidSummary || failureSummary) {
|
||||
const showResults = mermaidSummary || failureSummary || hasMismatches;
|
||||
|
||||
if (showResults) {
|
||||
actionsCore.summary.addRaw(
|
||||
`##  Determinate Nix build summary`,
|
||||
true,
|
||||
@@ -908,6 +638,18 @@ class NixInstallerAction extends DetSysAction {
|
||||
actionsCore.summary.addRaw("\n", true);
|
||||
}
|
||||
|
||||
if (hasMismatches) {
|
||||
actionsCore.summary.addRaw(
|
||||
[
|
||||
"> [!TIP]",
|
||||
"> Some derivations failed to build due to the hash in the Nix expression being outdated.",
|
||||
"> To find out how to automatically update your Nix expressions in GitHub Actions, see [our guide](https://docs.determinate.systems/guides/automatically-fix-hashes-in-github-actions).",
|
||||
"",
|
||||
].join("\n"),
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
if (failureSummary !== undefined) {
|
||||
for (const logLine of failureSummary.logLines) {
|
||||
actionsCore.info(logLine);
|
||||
@@ -917,7 +659,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
actionsCore.summary.addRaw("\n", true);
|
||||
}
|
||||
|
||||
if (mermaidSummary || failureSummary) {
|
||||
if (showResults) {
|
||||
actionsCore.summary.addRaw("---", true);
|
||||
actionsCore.summary.addRaw(
|
||||
`_Please let us know what you think about this summary on the [Determinate Systems Discord](https://determinate.systems/discord)._`,
|
||||
@@ -928,44 +670,6 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
}
|
||||
|
||||
async cleanupDockerShim(): Promise<void> {
|
||||
const containerId = actionsCore.getState("docker_shim_container_id");
|
||||
|
||||
if (containerId !== "") {
|
||||
actionsCore.startGroup("Cleaning up the Nix daemon's Docker shim");
|
||||
|
||||
let cleaned = false;
|
||||
try {
|
||||
await actionsExec.exec("docker", ["rm", "--force", containerId]);
|
||||
cleaned = true;
|
||||
} catch {
|
||||
actionsCore.warning("failed to cleanup nix daemon container");
|
||||
}
|
||||
|
||||
if (!cleaned) {
|
||||
actionsCore.info("trying to pkill the container's shim process");
|
||||
try {
|
||||
await actionsExec.exec("pkill", [containerId]);
|
||||
cleaned = true;
|
||||
} catch {
|
||||
actionsCore.warning(
|
||||
"failed to forcibly kill the container's shim process",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (cleaned) {
|
||||
this.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
|
||||
} else {
|
||||
actionsCore.warning(
|
||||
"Giving up on cleaning up the nix daemon container",
|
||||
);
|
||||
}
|
||||
|
||||
actionsCore.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
async setGithubPath(): Promise<void> {
|
||||
// Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
|
||||
try {
|
||||
@@ -1035,6 +739,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
["uninstall"],
|
||||
{
|
||||
env: {
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NO_CONFIRM: "true",
|
||||
...process.env, // To get $PATH, etc
|
||||
},
|
||||
@@ -1198,6 +903,47 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
}
|
||||
|
||||
async cleanupNoSystemd(): Promise<void> {
|
||||
if (!this.forceNoSystemd) {
|
||||
// Nothing to do, we didn't use the double fork
|
||||
return;
|
||||
}
|
||||
|
||||
const pidFile = path.join(this.daemonDir, "daemon.pid");
|
||||
const pid = parseInt(await readFile(pidFile, { encoding: "ascii" }));
|
||||
actionsCore.debug(`found daemon pid: ${pid}`);
|
||||
if (!pid) {
|
||||
throw new Error("the daemon did not start successfully");
|
||||
}
|
||||
|
||||
actionsCore.debug(`killing daemon process ${pid}`);
|
||||
|
||||
try {
|
||||
// Repeatedly signal 0 the daemon to test if it is up.
|
||||
// If it exits, kill will raise an exception which breaks us out of this control flow and skips the sigterm.
|
||||
// If it doesn't exit in 30s, we SIGTERM it.
|
||||
for (let i = 0; i < 30 * 10; i++) {
|
||||
process.kill(pid, 0);
|
||||
await setTimeout(100);
|
||||
}
|
||||
|
||||
this.addFact(FACT_SENT_SIGTERM, true);
|
||||
actionsCore.info(`Sending the daemon a SIGTERM`);
|
||||
process.kill(pid, "SIGTERM");
|
||||
} catch {
|
||||
// Perfectly normal to get an exception here, because the process shut down.
|
||||
}
|
||||
|
||||
if (actionsCore.isDebug()) {
|
||||
actionsCore.info("Entire log:");
|
||||
const entireLog = await readFile(
|
||||
path.join(this.daemonDir, "daemon.log"),
|
||||
"utf-8",
|
||||
);
|
||||
actionsCore.info(entireLog);
|
||||
}
|
||||
}
|
||||
|
||||
async reportOverall(): Promise<void> {
|
||||
try {
|
||||
this.recordEvent(EVENT_CONCLUDE_JOB, {
|
||||
@@ -1209,7 +955,7 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
|
||||
private get defaultPlanner(): string {
|
||||
if (this.isMacOS) {
|
||||
if (this.isMacOs) {
|
||||
return "macos";
|
||||
} else if (this.isLinux) {
|
||||
return "linux";
|
||||
@@ -1255,29 +1001,51 @@ class NixInstallerAction extends DetSysAction {
|
||||
}
|
||||
}
|
||||
|
||||
// All env vars are strings, no fanciness here.
|
||||
type ExecuteEnvironment = {
|
||||
// All env vars are strings, no fanciness here.
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
RUST_BACKTRACE?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_MODIFY_PROFILE?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_BUILD_GROUP_NAME?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_BUILD_GROUP_ID?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_BUILD_USER_PREFIX?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_BUILD_USER_COUNT?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_BUILD_USER_ID_BASE?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NIX_PACKAGE_URL?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_PROXY?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_SSL_CERT_FILE?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_DIAGNOSTIC_ENDPOINT?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_ENCRYPT?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_CASE_SENSITIVE?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_VOLUME_LABEL?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_ROOT_DISK?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_INIT?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_START_DAEMON?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_NO_CONFIRM?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_EXTRA_CONF?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_LOG_DIRECTIVES?: string;
|
||||
// biome-ignore lint/style/useNamingConvention: environment variable
|
||||
NIX_INSTALLER_LOGGER?: string;
|
||||
};
|
||||
|
||||
|
||||
+97
-43
@@ -1,11 +1,9 @@
|
||||
import { mermaidify, makeMermaidReport } from "./mermaid.js";
|
||||
import { DEvent, parseEvents } from "./events.js";
|
||||
import { expect, test } from "vitest";
|
||||
import { Event, parseEvents } from "./events.js";
|
||||
import { makeMermaidReport, mermaidify } from "./mermaid.js";
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
function generateEvents(count: number): DEvent[] {
|
||||
const events: DEvent[] = [];
|
||||
function generateEvents(count: number): Event[] {
|
||||
const events: Event[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
events.push({
|
||||
@@ -22,70 +20,86 @@ function generateEvents(count: number): DEvent[] {
|
||||
return events;
|
||||
}
|
||||
|
||||
test("Empty event list returns no report", () => {
|
||||
const report = makeMermaidReport([]);
|
||||
|
||||
expect(report).toBeUndefined();
|
||||
});
|
||||
|
||||
test("Create a very large report doc and make sure it is small enough", () => {
|
||||
{
|
||||
const report = makeMermaidReport(generateEvents(2000))!;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const report = makeMermaidReport(generateEvents(2500))!;
|
||||
|
||||
// Assert the `.drv` suffix was pruned (1 reference = the NOTE at the end)
|
||||
expect(report.match(/\.drv/g)!.length).equals(1);
|
||||
// Assert the `.drv` suffix was pruned (1 reference = the NOTE at the end)
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\.drv/g)!.length).equals(1);
|
||||
|
||||
// Assert the `/nix/store` prefix was pruned (1 reference = the NOTE at the end)
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(1);
|
||||
// Assert the `/nix/store` prefix was pruned (1 reference = the NOTE at the end)
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(1);
|
||||
|
||||
// Assert that some events were pruned
|
||||
expect(report.match(/dep-/g)!.length).lessThan(2000);
|
||||
expect(report.match(/dep-/g)!.length).greaterThan(1500);
|
||||
// Assert that some events were pruned
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/dep-/g)!.length).lessThan(2500);
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/dep-/g)!.length).greaterThan(1500);
|
||||
|
||||
expect(report).toContain("suffix, and builds that took less than 3");
|
||||
expect(report).toContain("suffix, and builds that took less than ");
|
||||
|
||||
expect(report.length).lessThan(50200);
|
||||
expect(report.length).greaterThan(49000);
|
||||
}
|
||||
expect(report.length).lessThan(50200);
|
||||
expect(report.length).greaterThan(49000);
|
||||
});
|
||||
|
||||
test("Create a medium large report doc and make sure it is small enough", () => {
|
||||
{
|
||||
const eventCount = 675;
|
||||
const report = makeMermaidReport(generateEvents(eventCount))!;
|
||||
const eventCount = 675;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const report = makeMermaidReport(generateEvents(eventCount))!;
|
||||
|
||||
// Assert the `.drv` suffix was pruned (1 reference = the NOTE at the end)
|
||||
expect(report.match(/\.drv/g)!.length).equals(1);
|
||||
// Assert the `.drv` suffix was pruned (1 reference = the NOTE at the end)
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\.drv/g)!.length).equals(1);
|
||||
|
||||
// Assert the `/nix/store` prefix was pruned (1 reference = the NOTE at the end)
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(1);
|
||||
// Assert the `/nix/store` prefix was pruned (1 reference = the NOTE at the end)
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(1);
|
||||
|
||||
// Assert that no lines were pruned
|
||||
expect(report.match(/dep-/g)!.length).toStrictEqual(eventCount);
|
||||
// Assert that no lines were pruned
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/dep-/g)!.length).toStrictEqual(eventCount);
|
||||
|
||||
expect(report).toContain(
|
||||
"suffixes have been removed to make the graph small enough to render",
|
||||
);
|
||||
expect(report).toContain(
|
||||
"suffixes have been removed to make the graph small enough to render",
|
||||
);
|
||||
|
||||
expect(report.length).lessThan(50200);
|
||||
expect(report.length).greaterThan(18000);
|
||||
}
|
||||
expect(report.length).lessThan(50200);
|
||||
expect(report.length).greaterThan(18000);
|
||||
});
|
||||
|
||||
test("Create a small report doc and make sure it isn't pruned", () => {
|
||||
{
|
||||
const report = makeMermaidReport(generateEvents(100))!;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const report = makeMermaidReport(generateEvents(100))!;
|
||||
|
||||
// Assert 100 events have the `.drv` suffix, ie: were not pruned
|
||||
expect(report.match(/\.drv/g)!.length).equals(100);
|
||||
// Assert 100 events have the `.drv` suffix, ie: were not pruned
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\.drv/g)!.length).equals(100);
|
||||
|
||||
// Assert 100 events have the `.drv` suffix, ie: were not pruned
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(100);
|
||||
// Assert 100 events have the `.drv` suffix, ie: were not pruned
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
expect(report.match(/\/nix\/store\//g)!.length).equals(100);
|
||||
|
||||
expect(report.length).lessThan(50000);
|
||||
}
|
||||
expect(report.length).lessThan(50000);
|
||||
});
|
||||
|
||||
test("Generate a really big report and shrink it", () => {
|
||||
const events = generateEvents(1000);
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const originalLength = mermaidify(events, -1)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthZero = mermaidify(events, 0)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthOne = mermaidify(events, 1)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthTwo = mermaidify(events, 2)!.length;
|
||||
|
||||
expect(originalLength).greaterThan(limitedLengthZero);
|
||||
@@ -94,7 +108,7 @@ test("Generate a really big report and shrink it", () => {
|
||||
});
|
||||
|
||||
test("Generate a rough report of various length", () => {
|
||||
const events = parseEvents([
|
||||
const { events } = parseEvents([
|
||||
{
|
||||
v: "1",
|
||||
c: "BuiltPathResponseEventV1",
|
||||
@@ -169,3 +183,43 @@ dep-2 (2s):d, 0, 2s
|
||||
hash-mismatch-md5-base16 (4s):crit, 3, 4s
|
||||
\`\`\``);
|
||||
});
|
||||
|
||||
test("Generate a really big report and shrink it", () => {
|
||||
const events = generateEvents(1000);
|
||||
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const originalLength = mermaidify(events, -1)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthZero = mermaidify(events, 0)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthOne = mermaidify(events, 1)!.length;
|
||||
// biome-ignore lint/style/noNonNullAssertion: testing
|
||||
const limitedLengthTwo = mermaidify(events, 2)!.length;
|
||||
|
||||
expect(originalLength).greaterThan(limitedLengthZero);
|
||||
expect(limitedLengthZero).greaterThan(limitedLengthOne);
|
||||
expect(limitedLengthOne).greaterThan(limitedLengthTwo);
|
||||
});
|
||||
|
||||
test("Really long builds get multi-unit timestamps", () => {
|
||||
const { events } = parseEvents([
|
||||
{
|
||||
v: "1",
|
||||
c: "BuiltPathResponseEventV1",
|
||||
drv: "/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-0.drv",
|
||||
outputs: ["/nix/store/qwlgz5da3pfb53gqpgdmazaj9jczrnly-dep-0"],
|
||||
timing: {
|
||||
startTime: "2025-04-11T14:38:02Z",
|
||||
stopTime: "2026-05-14T13:32:01Z",
|
||||
durationSeconds: 34383239,
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
expect(mermaidify(events, -1)).toStrictEqual(`\`\`\`mermaid
|
||||
gantt
|
||||
dateFormat X
|
||||
axisFormat %Mm%Ss
|
||||
/nix/store/rz9hrpay90sjrid5hx3x8v606ji679xa-dep-0.drv (573053m59s):d, 0, 34383239s
|
||||
\`\`\``);
|
||||
});
|
||||
|
||||
+12
-6
@@ -1,7 +1,7 @@
|
||||
import { DEvent } from "./events.js";
|
||||
import { Event } from "./events.js";
|
||||
import { truncateDerivation } from "./util.js";
|
||||
|
||||
export function makeMermaidReport(events: DEvent[]): string | undefined {
|
||||
export function makeMermaidReport(events: Event[]): string | undefined {
|
||||
// # 50k is the max: https://github.com/mermaid-js/mermaid/blob/c269dc822c528e1afbde34e18a1cad03d972d4fe/src/defaultConfig.js#L55
|
||||
const maxLength = 49900;
|
||||
let mermaid = "";
|
||||
@@ -12,7 +12,7 @@ export function makeMermaidReport(events: DEvent[]): string | undefined {
|
||||
mermaid = mermaidify(events, pruneLevel) ?? "";
|
||||
} while (mermaid.length > maxLength);
|
||||
|
||||
if (mermaid === undefined) {
|
||||
if (!mermaid) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export function makeMermaidReport(events: DEvent[]): string | undefined {
|
||||
} else if (pruneLevel > 0) {
|
||||
lines.push("> [!NOTE]");
|
||||
lines.push(
|
||||
`> \`/nix/store/[hash]\`, the \`.drv\` suffix, and builds that took less than ${pruneLevel}s have been removed to make the graph small enough to render.`,
|
||||
`> \`/nix/store/[hash]\`, the \`.drv\` suffix, and builds that took less than ${formatDuration(pruneLevel)} have been removed to make the graph small enough to render.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export function makeMermaidReport(events: DEvent[]): string | undefined {
|
||||
}
|
||||
|
||||
export function mermaidify(
|
||||
allEvents: DEvent[],
|
||||
allEvents: Event[],
|
||||
pruneLevel: number,
|
||||
): string | undefined {
|
||||
const events = allEvents
|
||||
@@ -81,10 +81,16 @@ export function mermaidify(
|
||||
(event.timing.startTime.getTime() - zeroMoment) / 1000;
|
||||
|
||||
lines.push(
|
||||
`${label} (${duration}s):${tag}, ${relativeStartTime}, ${duration}s`,
|
||||
`${label} (${formatDuration(duration)}):${tag}, ${relativeStartTime}, ${duration}s`,
|
||||
);
|
||||
}
|
||||
lines.push("```");
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function formatDuration(duration: number): string {
|
||||
const durSeconds = duration % 60;
|
||||
const durMinutes = (duration - durSeconds) / 60;
|
||||
return `${durMinutes > 0 ? `${durMinutes}m` : ""}${durSeconds}s`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user