parser complete

This commit is contained in:
atagen 2025-09-10 22:39:34 +10:00
commit 8ffd3b9aff
12 changed files with 1321 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1003
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

6
Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[workspace]
edition = "2024"
resolver = "3"
members = [ "parser", "state", "tui" ]

43
flake.lock generated Normal file
View file

@ -0,0 +1,43 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1753151930,
"narHash": "sha256-XSQy6wRKHhRe//iVY5lS/ZpI/Jn6crWI8fQzl647wCg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "83e677f31c84212343f4cc553bab85c2efcad60a",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1689347949,
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
"owner": "nix-systems",
"repo": "default-linux",
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default-linux",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

58
flake.nix Normal file
View file

@ -0,0 +1,58 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
inputs.systems.url = "github:nix-systems/default-linux";
outputs =
{
self,
nixpkgs,
systems,
}:
let
mkDeps = pkgs: {
dev = getPkgs {
inherit (pkgs)
rust-analyzer
clippy
rustc
cargo
rustfmt
;
};
build = getPkgs {
# rustc + cargo are inherent in rustPlatform
};
};
forAllSystems =
function:
nixpkgs.lib.genAttrs (import systems) (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
function pkgs (mkDeps pkgs)
);
getPkgs = builtins.attrValues;
in
{
devShells = forAllSystems (
pkgs: deps: {
default = pkgs.mkShell {
packages = with deps; dev ++ build;
};
}
);
packages = forAllSystems (
pkgs: deps: {
default =
let
inherit (pkgs.rustPlatform) buildRustPackage;
in
buildRustPackage {
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
};
}
);
};
}

13
parser/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "nix_json_parser"
version = "0.1.0"
edition = "2024"
crate-type = [ "lib" ]
[lib]
path = "./lib.rs"
[dependencies]
serde = { version = "1.0.219", features = ["derive"] }
serde_repr = "0.1.20"

61
parser/lib.rs Normal file
View file

@ -0,0 +1,61 @@
use serde::Deserialize;
use serde_repr::Deserialize_repr;
#[derive(Deserialize_repr, Debug)]
#[repr(u8)]
pub enum Activities {
Unknown = 0,
CopyPath = 100,
FileTransfer = 101,
Realise = 102,
CopyPaths = 103,
Builds = 104,
Build = 105,
OptimiseStore = 106,
VerifyPath = 107,
Substitute = 108,
QueryPathInfo = 109,
PostBuildHook = 110,
BuildWaiting = 111,
FetchTree = 112,
}
#[derive(Deserialize_repr, Debug)]
#[repr(u8)]
pub enum Verbosity {
Error = 0,
Warning = 1,
Notice = 2,
Info = 3,
Talkative = 4,
Chatty = 5,
Debug = 6,
Vomit = 7,
}
pub type Id = u64;
#[derive(Deserialize, Debug)]
#[serde(tag = "action")]
pub enum Actions {
#[serde(rename = "start")]
Start {
id: Id,
level: Verbosity,
parent: Id,
text: String,
#[serde(rename = "type")]
activity: Activities,
},
#[serde(rename = "stop")]
Stop { id: Id },
#[serde(rename = "msg")]
Message { level: Verbosity, msg: String },
#[serde(rename = "result")]
Result {
fields: Vec<u8>,
id: Id,
#[serde(rename = "type")]
activity: Activities,
},
}

12
state/Cargo.toml Normal file
View file

@ -0,0 +1,12 @@
[package]
name = "nix_build_state"
version = "0.1.0"
edition = "2024"
crate-type = [ "lib" ]
[lib]
path = "./lib.rs"
[dependencies]
serde_json = "1.0.141"
nix_json_parser = { path = "../parser" }

76
state/lib.rs Normal file
View file

@ -0,0 +1,76 @@
use std::{
collections::{HashMap, HashSet},
path::PathBuf,
};
use nix_json_parser::Actions;
pub type Id = u64;
pub enum StorePath {
Downloading,
Uploading,
Downloaded,
Uploaded,
}
pub enum BuildStatus {
Planned,
Running,
Complete,
Failed,
}
pub enum Progress {
JustStarted,
InputReceived,
Finished,
}
pub enum OutputName {
Out,
Doc,
Dev,
Bin,
Info,
Lib,
Man,
Dist,
Other(String),
}
pub enum Host {
Local,
Host(String),
}
pub struct Derivation {
store_path: PathBuf,
}
pub struct BuildInfo {
start: f64,
host: Host,
estimate: Option<u64>,
activity_id: Id,
state: BuildStatus,
}
pub enum DependencyState {
Planned,
Running,
Completed,
}
pub struct Dependencies {
deps: HashMap<Id, BuildInfo>,
}
// #[derive(Default)]
pub struct State {
progress: Progress,
}
impl State {
pub fn imbibe(&mut self, update: Actions) {}
}

14
tui/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[package]
name = "nous"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "nous"
path = "./main.rs"
[dependencies]
nix_json_parser = { path = "../parser" }
color-eyre = "0.6.5"
crossterm = "0.29.0"
ratatui = "0.29.0"

33
tui/main.rs Normal file
View file

@ -0,0 +1,33 @@
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
use nix_json_parser::*;
use ratatui::{
DefaultTerminal, Frame,
buffer::Buffer,
layout::Rect,
style::Stylize,
symbols::border,
text::{Line, Text},
widgets::{Block, Paragraph, Widget},
};
use std::io::{self, stdin};
fn main() -> io::Result<()> {
let mut terminal = ratatui::init();
let app_result = Nous::default().run(&mut terminal);
ratatui::restore();
app_result
}
#[derive(Default)]
struct Nous {}
impl Nous {
pub fn run(&mut self, terminal: &mut DefaultTerminal) -> io::Result<()> {
let lines = stdin().lines();
for line in lines.map_while(Result::ok) {
let trim = line.trim_start_matches("@nix ");
println!("{:?}", serde_json::from_str::<Actions>(trim).unwrap());
}
Ok(())
}
}