initial commit

This commit is contained in:
⛧-440729 [sophie] 2025-05-06 00:22:31 +02:00
commit 8e1813ca0d
No known key found for this signature in database
GPG key ID: 8566000000440729
14 changed files with 2005 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use nix

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
/result

21
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,21 @@
stages:
- build
build:
stage: build
image: nixos/nix
parallel:
matrix:
- ARCH: ["x86_64", "aarch64"]
tags:
- ${ARCH}
before_script:
- |
cat >> /etc/nix/nix.conf << EOF
experimental-features = nix-command flakes
EOF
- nix profile install nixpkgs#cargo nixpkgs#nix-eval-jobs nixpkgs#gcc
- nix --version
script:
- cargo build --release
- target/release/nix-ci --check-cached

817
Cargo.lock generated Normal file
View file

@ -0,0 +1,817 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
name = "bytes"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "futures"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-executor"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]]
name = "futures-macro"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
[[package]]
name = "futures-task"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
[[package]]
name = "futures-util"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miniz_oxide"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd"
dependencies = [
"libc",
"wasi",
"windows-sys 0.52.0",
]
[[package]]
name = "nix-ci"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"futures",
"pin-project",
"serde",
"serde_json",
"strum",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "pin-project"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustversion"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "strum"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
[[package]]
name = "syn"
version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tokio"
version = "1.44.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

16
Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "nix-ci"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.98"
clap = { version = "4.5.37", features = ["derive"] }
futures = "0.3.31"
pin-project = "1.1.10"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
strum = { version = "0.27.1", features = ["derive"] }
tokio = { version = "1.44.2", features = ["io-util", "macros", "process", "rt-multi-thread", "sync"] }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1746141548,
"narHash": "sha256-IgBWhX7A2oJmZFIrpRuMnw5RAufVnfvOgHWgIdds+hc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "f02fddb8acef29a8b32f10a335d44828d7825b78",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

65
flake.nix Normal file
View file

@ -0,0 +1,65 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = {
nixpkgs,
self,
}: let
forAllSystems = fn:
builtins.foldl' (attrs: system: let
outputs = fn system;
outputNames = builtins.attrNames outputs;
in
builtins.foldl' (attrs: outName: let
existing = attrs.${outName} or {};
new = existing // {${system} = outputs.${outName};};
in
attrs // {${outName} = new;})
attrs
outputNames) {} ["x86_64-linux" "aarch64-linux"];
in
{
overlays.default = final: prev: {
nix-ci = final.lib.flip final.callPackage {} ({
rustPlatform,
lib,
makeWrapper,
nix-eval-jobs,
}: let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in
rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
version = cargoToml.package.version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./src
./Cargo.toml
./Cargo.lock
];
};
nativeBuildInputs = [makeWrapper];
cargoLock.lockFile = ./Cargo.lock;
preFixup = ''
wrapProgram "$out/bin/nix-ci" \
--prefix PATH : ${lib.makeBinPath [nix-eval-jobs]}
'';
});
};
}
// forAllSystems (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [self.overlays.default];
};
in {
devShells.default = import ./shell.nix {inherit pkgs;};
packages = {
default = pkgs.nix-ci;
nix-ci = pkgs.nix-ci;
};
checks = self.packages.${system};
});
}

4
shell.nix Normal file
View file

@ -0,0 +1,4 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [nix-eval-jobs];
}

300
src/build.rs Normal file
View file

@ -0,0 +1,300 @@
use std::collections::{HashMap, VecDeque};
use tokio::{process::Command, sync::mpsc::Receiver};
use crate::{
types::{
NixInternalLogLine, NixInternalLogLineActivity, NixInternalLogLineActivityType,
NixInternalLogLineResult, NixJob,
},
util::{ChildOutput, WrappedChild},
};
pub enum BuildLoopMessage {
Job(NixJob),
Stop,
}
#[derive(Debug)]
struct ActivityData {
#[allow(dead_code)]
parent: Option<u64>,
r#type: NixInternalLogLineActivityType,
running: bool,
data: Option<ActivityDataPerType>,
}
#[derive(Debug, Clone)]
enum ActivityDataPerType {
Build { drv_path: String, state: BuildState },
Substitute { store_path: String },
}
#[derive(Debug, Clone, Copy)]
enum BuildState {
Started,
Running,
Done,
Failed,
}
#[derive(Debug, Clone, Copy)]
struct BuildProgress {
done: u64,
running: u64,
failed: u64,
}
pub async fn build_loop(mut rx: Receiver<BuildLoopMessage>) {
let mut paths_built = Vec::new();
while let Some(msg) = rx.recv().await {
let job = match msg {
BuildLoopMessage::Job(job) => job,
BuildLoopMessage::Stop => {
tracing::debug!("stop signal received");
break;
}
};
tracing::info!("building {}", job.attr);
if !paths_built.contains(&job.drv_path) {
paths_built.push(job.drv_path.clone());
if let Err(e) = run_build(job).await {
tracing::error!("nix build process errored! {}", e);
}
}
}
}
#[tracing::instrument(skip(job), fields(attr = job.attr))]
pub async fn run_build(job: NixJob) -> anyhow::Result<()> {
let mut child = WrappedChild::new(
Command::new("nix")
.args(&[
"build",
"--keep-going",
"--verbose",
"--log-format",
"internal-json",
])
.arg(format!("{}^*", job.drv_path)),
Some(format!("nix build {}", job.attr)),
)?;
let mut activities = HashMap::<u64, ActivityData>::new();
let mut progress = BuildProgress {
done: 0,
running: 0,
failed: 0,
};
let mut started_builds = VecDeque::new();
let mut reported_builds = VecDeque::new();
loop {
let line = match child.next_line().await? {
ChildOutput::Finished => break,
ChildOutput::Stderr(line) => line,
ChildOutput::Stdout(line) => {
tracing::info!(line);
continue;
}
};
if !line.starts_with("@nix ") {
tracing::warn!("invalid nix build output: {}", line);
continue;
}
let log: NixInternalLogLine = match serde_json::from_str(&line[4..]) {
Ok(log) => log,
Err(e) => {
tracing::warn!("failed to parse nix log output {:?}: {}", line, e);
continue;
}
};
tracing::trace!("log line: {:?}", log);
match log {
NixInternalLogLine::Msg { msg, .. } => {
tracing::info!("{}", msg);
}
NixInternalLogLine::Result { id, result } => {
let activity = activities.get_mut(&id);
if activity.is_none() {
tracing::warn!("received result for unknown activity {}!", id);
}
match result {
NixInternalLogLineResult::BuildLogLine { log }
| NixInternalLogLineResult::PostBuildLogLine { log } => {
tracing::info!("{}", log)
}
// apparently only reported for the realise activity, with activity types of
// FileTransfer and CopyPath. contains bytes downloaded and unpacked, respectively
NixInternalLogLineResult::SetExpected { .. } => {}
// progress reporting, depends on the activity type
NixInternalLogLineResult::Progress {
done,
expected: _,
running,
failed,
} => {
if let Some(activity) = activity {
match activity.r#type {
// meta-progress counting the derivations being built as part of the build
NixInternalLogLineActivityType::Builds => {
while running > progress.running {
progress.running += 1;
if let Some(build_activity_id) = started_builds.pop_front()
{
let Some(a) = activities.get_mut(&build_activity_id)
else {
panic!("this can't happen (id without activity)");
};
let ActivityDataPerType::Build { state, .. } =
a.data.as_mut().unwrap()
else {
panic!(
"this can't happen (build activity without build data)"
);
};
*state = BuildState::Running;
} else {
tracing::warn!(
"no build started but we got a running report?"
);
}
}
while failed > progress.failed {
progress.failed += 1;
reported_builds.push_back(BuildState::Failed);
}
while done > progress.done {
progress.done += 1;
reported_builds.push_back(BuildState::Done);
}
}
// meta-progress counting the paths being downloaded as part of the build
NixInternalLogLineActivityType::CopyPaths => {}
// progress for a single download
NixInternalLogLineActivityType::FileTransfer => {}
// progress for a file unpack(?) downloaded nar -> store
NixInternalLogLineActivityType::CopyPath => {}
_ => {
tracing::warn!(
"progress reported for unhandled activity type {:?}",
activity.r#type
);
}
}
}
}
_ => {
tracing::warn!("unhandled result: activity {}, {:?}", id, result);
}
}
}
NixInternalLogLine::Start {
id,
level: _,
text,
parent,
activity,
} => {
tracing::debug!(
"activity {} (parent {}) started: {:?}",
id,
parent,
activity
);
let mut entry = {
let parent = if parent == 0 { None } else { Some(parent) };
activities.entry(id).insert_entry(ActivityData {
parent,
r#type: activity.get_type(),
running: true,
data: None,
})
};
if !text.is_empty() {
tracing::info!("{}", text);
}
match activity {
// these seem to be meta-activities for reporting progress
NixInternalLogLineActivity::Builds => {}
NixInternalLogLineActivity::CopyPaths => {}
NixInternalLogLineActivity::Realise => {}
// just ignore this, we don't really care about these
NixInternalLogLineActivity::Unknown => {}
NixInternalLogLineActivity::FileTransfer => {}
NixInternalLogLineActivity::QueryPathInfo { .. } => {
// has FileTransfer as child
}
NixInternalLogLineActivity::CopyPath => {
// has FileTransfer as child (when downloading)
}
NixInternalLogLineActivity::Substitute { store_path, .. } => {
// has CopyPath as child
entry
.get_mut()
.data
.replace(ActivityDataPerType::Substitute { store_path });
}
// useful activities
NixInternalLogLineActivity::Build { drv_path, .. } => {
entry.get_mut().data.replace(ActivityDataPerType::Build {
drv_path,
state: BuildState::Started,
});
started_builds.push_back(id);
}
_ => {
tracing::warn!(
"unhandled start: activity {} (parent {}), {:?}",
id,
parent,
activity
)
}
}
}
NixInternalLogLine::Stop { id } => {
tracing::debug!("activity {} stopped", id);
if let Some(entry) = activities.get_mut(&id) {
entry.running = false;
match entry.r#type {
NixInternalLogLineActivityType::Build => {
let ActivityDataPerType::Build { state, .. } =
entry.data.as_mut().unwrap()
else {
panic!("this can't happen (build activity without build data)");
};
if let Some(report) = reported_builds.pop_front() {
*state = report;
} else {
tracing::warn!(
"build stopped but no report (don't know whether it failed)"
);
}
}
_ => {}
}
}
}
}
}
let exit_status = child
.exit_status()
.ok_or(anyhow::anyhow!("child has exited, but no exit status????"))?;
if !exit_status.success() {
tracing::warn!("nix build failed with {}!", exit_status);
}
for (_, a) in &activities {
match a.data.as_ref() {
Some(ActivityDataPerType::Build { drv_path, state }) => match state {
BuildState::Done => tracing::info!("derivation {} built successfully", drv_path),
BuildState::Failed => tracing::warn!("derivation {} failed to build", drv_path),
_ => tracing::warn!("derivation {} somehow still running??", drv_path),
},
Some(ActivityDataPerType::Substitute { store_path }) => {
tracing::info!("downloaded {}", store_path);
}
_ => {}
}
}
// TODO: return the drv paths to upload!
Ok(())
}

7
src/config.rs Normal file
View file

@ -0,0 +1,7 @@
#[derive(clap::Parser, Debug)]
pub struct Options {
#[arg(long = "system", short)]
pub systems: Vec<String>,
#[arg(long)]
pub check_cached: bool,
}

99
src/main.rs Normal file
View file

@ -0,0 +1,99 @@
use clap::Parser;
use tokio::{process::Command, sync::mpsc};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
use crate::{
build::BuildLoopMessage,
config::Options,
types::{NixJob, NixJobCacheStatus},
util::{ChildOutput, WrappedChild},
};
mod build;
mod config;
mod types;
mod util;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut opts = Options::parse();
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();
if opts.systems.is_empty() {
let cmd = Command::new("nix")
.args(&["config", "show", "system"])
.output()
.await?;
let system = std::str::from_utf8(&cmd.stdout)?.trim().into();
tracing::info!("no system specified, defaulting to current {}", system);
opts.systems.push(system);
}
let (build_tx, build_rx) = mpsc::channel(4);
let build_loop = tokio::spawn(self::build::build_loop(build_rx));
let mut jobs = nix_eval_jobs(&opts)?;
loop {
let line = match jobs.next_line().await? {
ChildOutput::Finished => break,
ChildOutput::Stderr(line) => {
tracing::info!("nix-eval-jobs: {}", line);
continue;
}
ChildOutput::Stdout(line) => line,
};
tracing::trace!("nix-eval-jobs line: {}", line);
let job: NixJob = serde_json::from_str(&line)?;
tracing::debug!("got new job: {:?}", job);
if !opts.systems.contains(&job.system) {
tracing::info!("skipping unwanted system build for {}", job.attr);
continue;
}
match (job.cache_status, job.is_cached) {
(Some(NixJobCacheStatus::Cached), _) | (None, Some(true)) => {
tracing::info!("skipping cached build for {}", job.attr);
continue;
}
(Some(NixJobCacheStatus::Local), _) => {
// TODO: local paths should still be uploaded but needn't be built
// probably when lix-eval-jobs implements `cacheStatus` (in addition to `isCached`)
// they also have output paths already set in the nix-eval-jobs output
tracing::info!("skipping cached build for {}", job.attr);
continue;
}
_ => {}
}
build_tx.send(BuildLoopMessage::Job(job)).await?;
}
build_tx.send(BuildLoopMessage::Stop).await?;
build_loop.await?;
Ok(())
}
fn nix_eval_jobs(opts: &Options) -> anyhow::Result<WrappedChild> {
let mut command = Command::new("nix-eval-jobs");
// TODO: make this configurable
command.args(&[
"--force-recurse",
"--max-memory-size",
"3072",
"--workers",
"4",
"--flake",
".#checks",
]);
if opts.check_cached {
command.arg("--check-cache-status");
}
Ok(WrappedChild::new(&mut command, None)?)
}

159
src/types.rs Normal file
View file

@ -0,0 +1,159 @@
#![allow(dead_code)]
use std::collections::HashMap;
use serde::Deserialize;
use strum::FromRepr;
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum NixJobCacheStatus {
Cached,
Local,
NotBuilt,
Unknown,
}
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NixJob {
pub attr: String,
pub name: String,
pub drv_path: String,
pub system: String,
pub cache_status: Option<NixJobCacheStatus>,
pub is_cached: Option<bool>,
pub outputs: HashMap<String, Option<String>>,
}
#[derive(Deserialize, Debug)]
#[serde(tag = "action", rename_all = "camelCase")]
pub enum NixInternalLogLine {
Start {
id: u64,
level: u8,
text: String,
parent: u64,
#[serde(flatten)]
activity: NixInternalLogLineActivity,
},
Stop {
id: u64,
},
Msg {
level: u8,
msg: String,
},
Result {
id: u64,
#[serde(flatten)]
result: NixInternalLogLineResult,
},
}
#[derive(FromRepr, Debug, Clone, Copy)]
#[repr(u64)]
pub enum NixInternalLogLineActivityType {
Unknown = 0,
CopyPath = 100,
FileTransfer = 101,
Realise = 102,
CopyPaths = 103,
Builds = 104,
Build = 105,
OptimiseStore = 106,
VerifyPaths = 107,
Substitute = 108,
QueryPathInfo = 109,
PostBuildHook = 110,
BuildWaiting = 111,
}
#[derive(Debug)]
pub enum NixInternalLogLineActivity {
Unknown,
CopyPath,
FileTransfer,
Realise,
CopyPaths,
Builds,
Build {
drv_path: String,
machine: String,
cur_round: u64,
nr_rounds: u64,
},
OptimiseStore,
VerifyPaths,
Substitute {
store_path: String,
substituter: String,
},
QueryPathInfo {
store_path: String,
substituter: String,
},
PostBuildHook {
store_path: String,
},
BuildWaiting,
}
impl NixInternalLogLineActivity {
pub fn get_type(&self) -> NixInternalLogLineActivityType {
match self {
NixInternalLogLineActivity::Unknown => NixInternalLogLineActivityType::Unknown,
NixInternalLogLineActivity::CopyPath => NixInternalLogLineActivityType::CopyPath,
NixInternalLogLineActivity::FileTransfer => {
NixInternalLogLineActivityType::FileTransfer
}
NixInternalLogLineActivity::Realise => NixInternalLogLineActivityType::Realise,
NixInternalLogLineActivity::CopyPaths => NixInternalLogLineActivityType::CopyPaths,
NixInternalLogLineActivity::Builds => NixInternalLogLineActivityType::Builds,
NixInternalLogLineActivity::Build { .. } => NixInternalLogLineActivityType::Build,
NixInternalLogLineActivity::OptimiseStore => {
NixInternalLogLineActivityType::OptimiseStore
}
NixInternalLogLineActivity::VerifyPaths => NixInternalLogLineActivityType::VerifyPaths,
NixInternalLogLineActivity::Substitute { .. } => {
NixInternalLogLineActivityType::Substitute
}
NixInternalLogLineActivity::QueryPathInfo { .. } => {
NixInternalLogLineActivityType::QueryPathInfo
}
NixInternalLogLineActivity::PostBuildHook { .. } => {
NixInternalLogLineActivityType::PostBuildHook
}
NixInternalLogLineActivity::BuildWaiting => {
NixInternalLogLineActivityType::BuildWaiting
}
}
}
}
#[derive(Debug)]
pub enum NixInternalLogLineResult {
FileLinked {
bytes_linked: i64,
},
BuildLogLine {
log: String,
},
UntrustedPath,
CorruptedPath,
SetPhase {
phase_name: String,
},
Progress {
done: u64,
expected: u64,
running: u64,
failed: u64,
},
SetExpected {
activity_type: NixInternalLogLineActivityType,
expected: u64,
},
PostBuildLogLine {
log: String,
},
}

212
src/util.rs Normal file
View file

@ -0,0 +1,212 @@
use std::{
pin::Pin,
process::{ExitStatus, Stdio},
task::Poll,
};
use futures::{
FutureExt,
future::{BoxFuture, poll_fn},
};
use tokio::{
io::{AsyncBufReadExt, BufReader, Lines},
process::{Child, ChildStderr, ChildStdout, Command},
};
pub mod deserializer;
pub struct WrappedChild {
// this ensures the `!Unpin`` internal struct is not moved at all
inner: Pin<Box<WrappedChildInternal>>,
}
impl WrappedChild {
pub fn new(command: &mut Command, name: Option<String>) -> anyhow::Result<Self> {
let name = name.unwrap_or_else(|| command.as_std().get_program().to_string_lossy().into());
let mut child = command
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
tracing::info!("spawned {}", name);
let stdout = BufReader::new(child.stdout.take().unwrap()).lines();
let stderr = BufReader::new(child.stderr.take().unwrap()).lines();
let inner = WrappedChildInternal {
name,
exit_status: None,
child,
child_wait_fut: None,
stdout: Some(stdout),
stderr: Some(stderr),
};
Ok(Self {
inner: Box::pin(inner),
})
}
pub async fn next_line(&mut self) -> anyhow::Result<ChildOutput> {
poll_fn(|cx| self.inner.as_mut().poll(cx)).await
}
/// return the exit status if the child process has already exited, `None` otherwise
pub fn exit_status(&self) -> Option<ExitStatus> {
self.inner.exit_status
}
}
#[pin_project::pin_project(!Unpin)]
struct WrappedChildInternal {
name: String,
exit_status: Option<ExitStatus>,
#[pin]
child: Child,
#[pin]
stdout: Option<Lines<BufReader<ChildStdout>>>,
#[pin]
stderr: Option<Lines<BufReader<ChildStderr>>>,
#[pin]
// this future keeps a mutable reference to `child`
// this struct must thus not be moved!! (thus the `!Unpin`)
child_wait_fut: Option<BoxFuture<'static, std::io::Result<ExitStatus>>>,
}
impl WrappedChildInternal {
fn do_lifetime_extension<'a>(
mut pin: Pin<&mut Option<BoxFuture<'static, std::io::Result<ExitStatus>>>>,
future: BoxFuture<'a, std::io::Result<ExitStatus>>,
) {
if pin.is_some() {
return;
}
// SAFETY: this transmute just does a lifetime extension from Pin<Box<'a>> to Pin<Box<'static>>
// the types must be the same except for the lifetime parameter
pin.replace(unsafe { std::mem::transmute(future) });
}
fn map_stdio_poll_result(
result: std::io::Result<Option<String>>,
) -> Result<String, StdioState> {
match result {
Ok(Some(line)) => Ok(line),
Ok(None) => Err(StdioState::Closed),
Err(e) => Err(StdioState::Errored(e)),
}
}
}
enum StdioState {
Closed,
Errored(std::io::Error),
}
pub enum ChildOutput {
Stdout(String),
Stderr(String),
Finished,
}
impl Future for WrappedChildInternal {
type Output = anyhow::Result<ChildOutput>;
fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
let mut this = self.as_mut().project();
tracing::trace!("[child process {}] poll called", this.name);
if this.exit_status.is_some() {
// process has exited already, so just return asap
return Poll::Ready(Ok(ChildOutput::Finished));
}
let state = match (
this.stdout.as_mut().as_pin_mut(),
this.stderr.as_mut().as_pin_mut(),
) {
(Some(stdout), Some(stderr)) => match stdout
.poll_next_line(cx)
.map(Self::map_stdio_poll_result)
{
Poll::Pending => match stderr.poll_next_line(cx).map(Self::map_stdio_poll_result) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Ok(line)) => {
return Poll::Ready(Ok(ChildOutput::Stderr(line)));
}
Poll::Ready(Err(e)) => {
tracing::debug!("[child process {}] stderr closed", this.name);
drop(this.stderr.as_mut().take());
e
}
},
Poll::Ready(Ok(line)) => {
return Poll::Ready(Ok(ChildOutput::Stdout(line)));
}
Poll::Ready(Err(e)) => {
tracing::debug!("[child process {}] stdout closed", this.name);
drop(this.stdout.as_mut().take());
e
}
},
(Some(stdout), None) => {
match stdout.poll_next_line(cx).map(Self::map_stdio_poll_result) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Ok(line)) => {
return Poll::Ready(Ok(ChildOutput::Stdout(line)));
}
Poll::Ready(Err(e)) => {
tracing::debug!("[child process {}] stdout closed", this.name);
drop(this.stdout.as_mut().take());
e
}
}
}
(None, Some(stderr)) => {
match stderr.poll_next_line(cx).map(Self::map_stdio_poll_result) {
Poll::Pending => return Poll::Pending,
Poll::Ready(Ok(line)) => {
return Poll::Ready(Ok(ChildOutput::Stderr(line)));
}
Poll::Ready(Err(e)) => {
tracing::debug!("[child process {}] stderr closed", this.name);
drop(this.stderr.as_mut().take());
e
}
}
}
(None, None) => StdioState::Closed,
};
if let StdioState::Errored(e) = state {
tracing::debug!("[child process {}] io error: {}", this.name, e);
}
// pending if at least some i/o still exists
if this.stderr.is_some() || this.stdout.is_some() {
// make sure we immediately poll the non-closed stream again, otherwise this future might not be awoken again
return self.poll(cx);
}
// now do the process kill/wait/exit stuff as both stdios are closed
if this.child_wait_fut.is_none() {
// send kill signal to child
if let Err(e) = this.child.start_kill() {
return Poll::Ready(Err(e.into()));
}
// start waiting for the child to exit
Self::do_lifetime_extension(this.child_wait_fut.as_mut(), this.child.wait().boxed());
}
// we can unwrap here because the future has been set if it didn't exist already above
let child_wait = this.child_wait_fut.as_mut().as_pin_mut().unwrap();
match child_wait.poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(Err(e)) => {
this.child_wait_fut.as_mut().take();
Poll::Ready(Err(e.into()))
}
Poll::Ready(Ok(status)) => {
this.child_wait_fut.as_mut().take();
this.exit_status.replace(status);
tracing::info!("[child process {}] exited with {}", this.name, status);
Poll::Ready(Ok(ChildOutput::Finished))
}
}
}
}

275
src/util/deserializer.rs Normal file
View file

@ -0,0 +1,275 @@
use serde::{
__private::de::{Content, ContentDeserializer},
Deserialize,
de::Visitor,
};
use crate::types::{
NixInternalLogLineActivity, NixInternalLogLineActivityType, NixInternalLogLineResult,
};
struct TypeFieldsVisitor;
impl<'de> Visitor<'de> for TypeFieldsVisitor {
type Value = (u64, Content<'de>);
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("type + fields")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: serde::de::MapAccess<'de>,
{
let mut tag = None;
let mut fields = None;
while let Some(key) = map.next_key::<String>()? {
match key.as_str() {
"type" => {
if tag.is_some() {
return Err(serde::de::Error::duplicate_field("type"));
}
tag.replace(map.next_value::<u64>()?);
}
"fields" => {
if fields.is_some() {
return Err(serde::de::Error::duplicate_field("fields"));
}
fields.replace(map.next_value::<Content>()?);
}
_ => return Err(serde::de::Error::unknown_field(&key, &[])),
}
}
let Some(tag) = tag else {
return Err(serde::de::Error::missing_field("type"));
};
let fields = fields.unwrap_or(Content::None);
Ok((tag, fields))
}
}
struct TypedTupleVisitor<T> {
_marker: std::marker::PhantomData<T>,
}
impl<T> TypedTupleVisitor<T> {
fn new() -> Self {
Self {
_marker: std::marker::PhantomData,
}
}
}
impl<'de, T0> Visitor<'de> for TypedTupleVisitor<(T0,)>
where
T0: Deserialize<'de>,
{
type Value = (T0,);
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("tuple")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let Some(v0) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(0, &"1"));
};
Ok((v0,))
}
}
impl<'de, T0, T1> Visitor<'de> for TypedTupleVisitor<(T0, T1)>
where
T0: Deserialize<'de>,
T1: Deserialize<'de>,
{
type Value = (T0, T1);
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("tuple")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let Some(v0) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(0, &"2"));
};
let Some(v1) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(1, &"2"));
};
Ok((v0, v1))
}
}
impl<'de, T0, T1, T2, T3> Visitor<'de> for TypedTupleVisitor<(T0, T1, T2, T3)>
where
T0: Deserialize<'de>,
T1: Deserialize<'de>,
T2: Deserialize<'de>,
T3: Deserialize<'de>,
{
type Value = (T0, T1, T2, T3);
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("tuple")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let Some(v0) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(0, &"4"));
};
let Some(v1) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(1, &"4"));
};
let Some(v2) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(2, &"4"));
};
let Some(v3) = seq.next_element()? else {
return Err(serde::de::Error::invalid_length(3, &"4"));
};
Ok((v0, v1, v2, v3))
}
}
impl<'de> Deserialize<'de> for NixInternalLogLineResult {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let (r#type, fields) = deserializer.deserialize_any(TypeFieldsVisitor)?;
let de = ContentDeserializer::<D::Error>::new(fields);
match r#type {
100 => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_,)>::new())?;
Ok(NixInternalLogLineResult::FileLinked {
bytes_linked: fields.0,
})
}
101 => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_,)>::new())?;
Ok(NixInternalLogLineResult::BuildLogLine { log: fields.0 })
}
102 => Ok(NixInternalLogLineResult::UntrustedPath),
103 => Ok(NixInternalLogLineResult::CorruptedPath),
104 => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_,)>::new())?;
Ok(NixInternalLogLineResult::BuildLogLine { log: fields.0 })
}
105 => {
let fields = serde::Deserializer::deserialize_seq(
de,
TypedTupleVisitor::<(_, _, _, _)>::new(),
)?;
Ok(NixInternalLogLineResult::Progress {
done: fields.0,
expected: fields.1,
running: fields.2,
failed: fields.3,
})
}
106 => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_, _)>::new())?;
Ok(NixInternalLogLineResult::SetExpected {
activity_type: NixInternalLogLineActivityType::from_repr(fields.0).ok_or(
serde::de::Error::invalid_value(
serde::de::Unexpected::Unsigned(fields.0),
&"valid activity type",
),
)?,
expected: fields.1,
})
}
107 => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_,)>::new())?;
Ok(NixInternalLogLineResult::PostBuildLogLine { log: fields.0 })
}
_ => Err(serde::de::Error::invalid_value(
serde::de::Unexpected::Unsigned(r#type),
&"valid result type tag",
)),
}
}
}
impl<'de> Deserialize<'de> for NixInternalLogLineActivity {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let (r#type, fields) = deserializer.deserialize_any(TypeFieldsVisitor)?;
let de = ContentDeserializer::<D::Error>::new(fields);
let r#type = NixInternalLogLineActivityType::from_repr(r#type).ok_or(
serde::de::Error::invalid_value(
serde::de::Unexpected::Unsigned(r#type),
&"valid activity type",
),
)?;
match r#type {
NixInternalLogLineActivityType::Unknown => Ok(NixInternalLogLineActivity::Unknown),
NixInternalLogLineActivityType::CopyPath => Ok(NixInternalLogLineActivity::CopyPath),
NixInternalLogLineActivityType::FileTransfer => {
Ok(NixInternalLogLineActivity::FileTransfer)
}
NixInternalLogLineActivityType::Realise => Ok(NixInternalLogLineActivity::Realise),
NixInternalLogLineActivityType::CopyPaths => Ok(NixInternalLogLineActivity::CopyPaths),
NixInternalLogLineActivityType::Builds => Ok(NixInternalLogLineActivity::Builds),
NixInternalLogLineActivityType::Build => {
let fields = serde::Deserializer::deserialize_seq(
de,
TypedTupleVisitor::<(_, _, _, _)>::new(),
)?;
Ok(NixInternalLogLineActivity::Build {
drv_path: fields.0,
machine: fields.1,
cur_round: fields.2,
nr_rounds: fields.3,
})
}
NixInternalLogLineActivityType::OptimiseStore => {
Ok(NixInternalLogLineActivity::OptimiseStore)
}
NixInternalLogLineActivityType::VerifyPaths => {
Ok(NixInternalLogLineActivity::VerifyPaths)
}
NixInternalLogLineActivityType::Substitute => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_, _)>::new())?;
Ok(NixInternalLogLineActivity::Substitute {
store_path: fields.0,
substituter: fields.1,
})
}
NixInternalLogLineActivityType::QueryPathInfo => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_, _)>::new())?;
Ok(NixInternalLogLineActivity::QueryPathInfo {
store_path: fields.0,
substituter: fields.1,
})
}
NixInternalLogLineActivityType::PostBuildHook => {
let fields =
serde::Deserializer::deserialize_seq(de, TypedTupleVisitor::<(_,)>::new())?;
Ok(NixInternalLogLineActivity::PostBuildHook {
store_path: fields.0,
})
}
NixInternalLogLineActivityType::BuildWaiting => {
Ok(NixInternalLogLineActivity::BuildWaiting)
}
}
}
}