Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab9788b

Browse files
committedSep 23, 2024··
nix_rs: Enforce API docs (in CI)
- Use `#![warn(missing_docs)]` to enforce that all public entites are documented - Make an exception for `schema.rs` & `output.rs` since those can be documented as part of #235
1 parent 52fe61a commit ab9788b

25 files changed

+109
-15
lines changed
 

‎crates/nix_rs/src/command.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ static NIXCMD: OnceCell<NixCmd> = OnceCell::const_new();
7272
///
7373
/// The command will be highlighted to distinguish it (for copying) from the
7474
/// rest of the instrumentation parameters.
75-
7675
#[instrument(name = "command")]
7776
pub fn trace_cmd(cmd: &tokio::process::Command) {
7877
trace_cmd_with("🐚", cmd);
7978
}
8079

80+
/// Like [traace_cmd] but with a custom icon
8181
#[instrument(name = "command")]
8282
pub fn trace_cmd_with(icon: &str, cmd: &tokio::process::Command) {
8383
use colored::Colorize;
@@ -227,19 +227,24 @@ fn to_cli(cmd: &tokio::process::Command) -> String {
227227
/// Errors when running and interpreting the output of a nix command
228228
#[derive(Error, Debug)]
229229
pub enum NixCmdError {
230+
/// A [CommandError]
230231
#[error("Command error: {0}")]
231232
CmdError(#[from] CommandError),
232233

234+
/// Failed to unicode-decode the output of a command
233235
#[error("Failed to decode command stdout (utf8 error): {0}")]
234236
DecodeErrorUtf8(#[from] std::string::FromUtf8Error),
235237

238+
/// Failed to parse the output of a command
236239
#[error("Failed to decode command stdout (from_str error): {0}")]
237240
DecodeErrorFromStr(#[from] FromStrError),
238241

242+
/// Failed to parse the output of a command as JSON
239243
#[error("Failed to decode command stdout (json error): {0}")]
240244
DecodeErrorJson(#[from] serde_json::Error),
241245
}
242246

247+
/// Errors when parsing a string into a type
243248
#[derive(Debug)]
244249
pub struct FromStrError(String);
245250

@@ -251,10 +256,14 @@ impl Display for FromStrError {
251256

252257
impl std::error::Error for FromStrError {}
253258

259+
/// Errors when running a command
254260
#[derive(Error, Debug)]
255261
pub enum CommandError {
262+
/// Error when spawning a child process
256263
#[error("Child process error: {0}")]
257264
ChildProcessError(#[from] std::io::Error),
265+
266+
/// Child process exited unsuccessfully
258267
#[error(
259268
"Process exited unsuccessfully. exit_code={:?}{}",
260269
exit_code,
@@ -264,9 +273,13 @@ pub enum CommandError {
264273
},
265274
)]
266275
ProcessFailed {
276+
/// The stderr of the process, if available.
267277
stderr: Option<String>,
278+
/// The exit code of the process
268279
exit_code: Option<i32>,
269280
},
281+
282+
/// Failed to decode the stderr of a command
270283
#[error("Failed to decode command stderr: {0}")]
271284
Decode(#[from] std::string::FromUtf8Error),
272285
}

‎crates/nix_rs/src/config.rs

+13
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ use super::flake::system::System;
1919
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2020
#[serde(rename_all = "kebab-case")]
2121
pub struct NixConfig {
22+
/// Number of CPU cores used for nix builds
2223
pub cores: ConfigVal<i32>,
24+
/// Experimental features currently enabled
2325
pub experimental_features: ConfigVal<Vec<String>>,
26+
/// Extra platforms to build for
2427
pub extra_platforms: ConfigVal<Vec<String>>,
28+
/// The flake registry to use to lookup atomic flake inputs
2529
pub flake_registry: ConfigVal<String>,
30+
/// Maximum number of jobs to run in parallel
2631
pub max_jobs: ConfigVal<i32>,
32+
/// Cache substituters
2733
pub substituters: ConfigVal<Vec<Url>>,
34+
/// Current system
2835
pub system: ConfigVal<System>,
36+
/// Trusted users
2937
pub trusted_users: ConfigVal<Vec<TrustedUserValue>>,
3038
}
3139

@@ -91,15 +99,19 @@ impl NixConfig {
9199
}
92100
}
93101

102+
/// Error type for `NixConfig`
94103
#[derive(thiserror::Error, Debug)]
95104
pub enum NixConfigError {
105+
/// A [NixCmdError]
96106
#[error("Nix command error: {0}")]
97107
NixCmdError(#[from] NixCmdError),
98108

109+
/// A [NixCmdError] with a static lifetime
99110
#[error("Nix command error: {0}")]
100111
NixCmdErrorStatic(#[from] &'static NixCmdError),
101112
}
102113

114+
/// Accepted value for "trusted-users" in nix.conf
103115
#[derive(Debug, Clone, PartialEq, Eq, Serialize, DeserializeFromStr)]
104116
pub enum TrustedUserValue {
105117
/// All users are trusted
@@ -123,6 +135,7 @@ impl TrustedUserValue {
123135
}
124136
}
125137

138+
/// Display the nix.conf original string
126139
pub fn display_original(val: &[TrustedUserValue]) -> String {
127140
val.iter()
128141
.map(|x| match x {

‎crates/nix_rs/src/copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Rust module for `nix copy`.
12
use crate::{
23
command::{CommandError, NixCmd},
34
store::uri::StoreURI,

‎crates/nix_rs/src/detsys_installer.rs

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct DetSysNixInstaller {
1414
}
1515

1616
impl DetSysNixInstaller {
17+
/// Detects if the DetSys nix-installer is installed
1718
pub fn detect() -> Result<Option<Self>, BadInstallerVersion> {
1819
let nix_installer_path = Path::new("/nix/nix-installer");
1920
if nix_installer_path.exists() {
@@ -46,14 +47,22 @@ impl Display for InstallerVersion {
4647
}
4748
}
4849

50+
/// Errors that can occur when trying to get the [DetSysNixInstaller] version
4951
#[derive(Error, Debug)]
5052
pub enum BadInstallerVersion {
53+
/// Regex error
5154
#[error("Regex error: {0}")]
5255
Regex(#[from] regex::Error),
56+
57+
/// Failed to decode installer output
5358
#[error("Failed to decode installer output: {0}")]
5459
Decode(#[from] std::string::FromUtf8Error),
60+
61+
/// Failed to parse installer version
5562
#[error("Failed to parse installer version: {0}")]
5663
Parse(#[from] std::num::ParseIntError),
64+
65+
/// Failed to fetch installer version
5766
#[error("Failed to fetch installer version: {0}")]
5867
Command(std::io::Error),
5968
}

‎crates/nix_rs/src/env.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum OS {
9595
MacOS {
9696
/// Using nix-darwin
9797
nix_darwin: bool,
98+
/// Architecture
9899
arch: MacOSArch,
99100
},
100101
/// On NixOS
@@ -103,19 +104,26 @@ pub enum OS {
103104
Other(os_info::Type),
104105
}
105106

107+
/// macOS CPU architecture
106108
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107109
pub enum MacOSArch {
110+
/// Apple Silicon
108111
Arm64(AppleEmulation),
112+
/// Other architecture
109113
Other(Option<String>),
110114
}
111115

116+
/// Apple emulation mode
112117
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
113118
pub enum AppleEmulation {
119+
/// Not running on Apple Silicon
114120
None,
121+
/// Running under Rosetta
115122
Rosetta,
116123
}
117124

118125
impl AppleEmulation {
126+
/// Detect Apple emulation mode for current process
119127
pub fn new() -> Self {
120128
use is_proc_translated::is_proc_translated;
121129
if is_proc_translated() {
@@ -133,6 +141,7 @@ impl Default for AppleEmulation {
133141
}
134142

135143
impl MacOSArch {
144+
/// Create a [MacOSArch] from an OS architecture string
136145
pub fn from(os_arch: Option<&str>) -> MacOSArch {
137146
match os_arch {
138147
Some("arm64") => MacOSArch::Arm64(AppleEmulation::new()),
@@ -162,6 +171,7 @@ impl Display for OS {
162171
}
163172

164173
impl OS {
174+
/// Detect the OS
165175
pub async fn detect() -> Self {
166176
let os_info = tokio::task::spawn_blocking(os_info::get).await.unwrap();
167177
let os_type = os_info.os_type();
@@ -221,6 +231,7 @@ impl Display for NixInstaller {
221231
}
222232

223233
impl NixInstaller {
234+
/// Detect the Nix installer
224235
pub fn detect() -> Result<Self, NixEnvError> {
225236
match super::detsys_installer::DetSysNixInstaller::detect()? {
226237
Some(installer) => Ok(NixInstaller::DetSys(installer)),
@@ -230,18 +241,17 @@ impl NixInstaller {
230241
}
231242

232243
/// Errors while trying to fetch [NixEnv]
233-
234244
#[derive(thiserror::Error, Debug)]
235245
pub enum NixEnvError {
236-
#[error("Cannot find $USER: {0}")]
237-
UserError(#[from] std::env::VarError),
238-
246+
/// Unable to find user groups
239247
#[error("Failed to fetch groups: {0}")]
240248
GroupsError(std::io::Error),
241249

250+
/// Unable to find /nix volume
242251
#[error("Unable to find root disk or /nix volume")]
243252
NoDisk,
244253

254+
/// Unable to find Nix installer
245255
#[error("Failed to detect Nix installer: {0}")]
246256
InstallerError(#[from] super::detsys_installer::BadInstallerVersion),
247257
}

‎crates/nix_rs/src/flake/command.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Nix commands for working with flakes
12
use std::{
23
collections::{BTreeMap, HashMap},
34
path::PathBuf,

‎crates/nix_rs/src/flake/eval.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Work with `nix eval`
12
use crate::command::{CommandError, NixCmd, NixCmdError};
23

34
use super::{command::FlakeOptions, url::FlakeUrl};

‎crates/nix_rs/src/flake/metadata.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Work with `nix flake metadata`
12
use serde::{Deserialize, Serialize};
23
use std::path::PathBuf;
34

‎crates/nix_rs/src/flake/outputs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Nix flake outputs
2+
// TODO: Document this module!
3+
#![allow(missing_docs)]
24

35
use lazy_static::lazy_static;
46
use serde::{Deserialize, Serialize};

‎crates/nix_rs/src/flake/schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! High-level schema of a flake
22
//!
33
//! TODO: Consolidate with `outputs.rs`
4+
#![allow(missing_docs)]
45
use std::collections::BTreeMap;
56

67
use serde::{Deserialize, Serialize};

‎crates/nix_rs/src/flake/system.rs

+5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ use serde_with::{DeserializeFromStr, SerializeDisplay};
1616
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, SerializeDisplay, DeserializeFromStr,
1717
)]
1818
pub enum System {
19+
/// macOS system
1920
Darwin(Arch),
21+
/// Linux system
2022
Linux(Arch),
23+
/// Other system
2124
Other(String),
2225
}
2326

2427
/// CPU architecture in the system
2528
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
2629
pub enum Arch {
30+
/// aarch64
2731
Aarch64,
32+
/// x86_64
2833
X86_64,
2934
}
3035

‎crates/nix_rs/src/flake/url/attr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Work with flake attributes
12
use serde::{Deserialize, Serialize};
23

34
/// The (optional) attribute output part of a [super::FlakeUrl]
@@ -7,10 +8,12 @@ use serde::{Deserialize, Serialize};
78
pub struct FlakeAttr(pub Option<String>);
89

910
impl FlakeAttr {
11+
/// Create a new [FlakeAttr]
1012
pub fn new(attr: &str) -> Self {
1113
FlakeAttr(Some(attr.to_owned()))
1214
}
1315

16+
/// A missing flake attribute
1417
pub fn none() -> Self {
1518
FlakeAttr(None)
1619
}

‎crates/nix_rs/src/flake/url/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Work with flake URLs
12
pub mod attr;
23
mod core;
34
pub mod qualified_attr;

‎crates/nix_rs/src/flake/url/qualified_attr.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Flake attributes that are "qualified"
12
use crate::{
23
command::{NixCmd, NixCmdError},
34
flake::eval::nix_eval_attr,
@@ -35,11 +36,14 @@ where
3536
}
3637
}
3738

39+
/// Error type for [nix_eval_qualified_attr]
3840
#[derive(thiserror::Error, Debug)]
3941
pub enum QualifiedAttrError {
42+
/// When the attribute is not found in the flake
4043
#[error("Unexpected attribute, when config not present in flake: {0}")]
4144
UnexpectedAttribute(String),
4245

46+
/// A [NixCmdError]
4347
#[error("Nix command error: {0}")]
4448
CommandError(#[from] NixCmdError),
4549
}

‎crates/nix_rs/src/info.rs

+7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use crate::{config::NixConfig, env::NixEnv, version::NixVersion};
99
pub struct NixInfo {
1010
/// Nix version string
1111
pub nix_version: NixVersion,
12+
/// nix.conf configuration
1213
pub nix_config: NixConfig,
14+
/// Environment in which Nix was installed
1315
pub nix_env: NixEnv,
1416
}
1517

@@ -42,17 +44,22 @@ impl NixInfo {
4244
}
4345
}
4446

47+
/// Error type for [NixInfo]
4548
#[derive(thiserror::Error, Debug)]
4649
pub enum NixInfoError {
50+
/// A [NixCmdError]
4751
#[error("Nix command error: {0}")]
4852
NixCmdError(#[from] crate::command::NixCmdError),
4953

54+
/// A [NixCmdError] with a static lifetime
5055
#[error("Nix command error: {0}")]
5156
NixCmdErrorStatic(#[from] &'static crate::command::NixCmdError),
5257

58+
/// A [NixEnvError]
5359
#[error("Nix environment error: {0}")]
5460
NixEnvError(#[from] crate::env::NixEnvError),
5561

62+
/// A [NixConfigError]
5663
#[error("Nix config error: {0}")]
5764
NixConfigError(#[from] &'static crate::config::NixConfigError),
5865
}

‎crates/nix_rs/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! This crate exposes various types representing what nix command gives us,
44
//! along with a `from_nix` command to evaluate them.
5+
#![warn(missing_docs)]
56
pub mod command;
67
pub mod config;
78
pub mod copy;

‎crates/nix_rs/src/store/command.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Rust wrapper for `nix-store`
1+
//! Rust wrapper for `nix-store`
22
use std::path::PathBuf;
33

44
use crate::command::{CommandError, NixCmdError};
@@ -14,6 +14,7 @@ use super::path::StorePath;
1414
pub struct NixStoreCmd;
1515

1616
impl NixStoreCmd {
17+
/// Get the associated [Command]
1718
pub fn command(&self) -> Command {
1819
let mut cmd = Command::new("nix-store");
1920
cmd.kill_on_drop(true);
@@ -101,9 +102,11 @@ impl NixStoreCmd {
101102
/// `nix-store` command errors
102103
#[derive(Error, Debug)]
103104
pub enum NixStoreCmdError {
105+
/// A [NixCmdError]
104106
#[error(transparent)]
105107
NixCmdError(#[from] NixCmdError),
106108

109+
/// nix-store returned "unknown-deriver"
107110
#[error("Unknown deriver")]
108111
UnknownDeriver,
109112
}

‎crates/nix_rs/src/store/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Dealing with the Nix store
12
pub mod command;
23
pub mod path;
34
pub mod uri;

‎crates/nix_rs/src/store/path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Store path management
1+
//! Store path management
22
use std::{convert::Infallible, fmt, path::PathBuf, str::FromStr};
33

44
use serde_with::{DeserializeFromStr, SerializeDisplay};
@@ -30,6 +30,7 @@ impl From<&StorePath> for PathBuf {
3030
}
3131

3232
impl StorePath {
33+
/// Create a new `StorePath` from the given path
3334
pub fn new(path: PathBuf) -> Self {
3435
if path.ends_with(".drv") {
3536
StorePath::Drv(path)
@@ -38,6 +39,7 @@ impl StorePath {
3839
}
3940
}
4041

42+
/// Drop store path type distinction, returning the inner path.
4143
pub fn as_path(&self) -> &PathBuf {
4244
match self {
4345
StorePath::Drv(p) => p,

‎crates/nix_rs/src/store/uri.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Store URI management
1+
//! Store URI management
22
use std::{fmt, str::FromStr};
33

44
use serde::{Deserialize, Serialize};
@@ -20,17 +20,24 @@ pub struct SSHStoreURI {
2020
pub host: String,
2121
}
2222

23+
/// Error parsing a store URI
2324
#[derive(Error, Debug)]
2425
pub enum StoreURIParseError {
26+
/// Invalid URI format
2527
#[error("Invalid URI format")]
2628
InvalidFormat,
29+
/// Unsupported scheme
2730
#[error("Unsupported scheme: {0}")]
2831
UnsupportedScheme(String),
32+
/// Missing host
2933
#[error("Missing host")]
3034
MissingHost,
3135
}
3236

3337
impl StoreURI {
38+
/// Parse a Nix store URI
39+
///
40+
/// Currently only supports `ssh` scheme
3441
pub fn parse(uri: &str) -> Result<Self, StoreURIParseError> {
3542
let (scheme, rest) = uri
3643
.split_once("://")

‎crates/nix_rs/src/system_list.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
use lazy_static::lazy_static;
99

1010
lazy_static! {
11-
/// As a HashMap<String, String>
11+
/// Builtin list of [SystemsListFlakeRef]
1212
pub static ref NIX_SYSTEMS: HashMap<String, FlakeUrl> = {
1313
serde_json::from_str(env!("NIX_SYSTEMS")).unwrap()
1414
};
@@ -19,6 +19,7 @@ lazy_static! {
1919
pub struct SystemsListFlakeRef(pub FlakeUrl);
2020

2121
impl SystemsListFlakeRef {
22+
/// Lookup a known [SystemListFlakeRef] that will not require network calls
2223
pub fn from_known_system(system: &System) -> Option<Self> {
2324
NIX_SYSTEMS
2425
.get(&system.to_string())

‎crates/nix_rs/src/version.rs

+9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ use crate::command::{NixCmd, NixCmdError};
1212
/// Nix version as parsed from `nix --version`
1313
#[derive(Clone, Copy, PartialOrd, PartialEq, Eq, Debug, SerializeDisplay, DeserializeFromStr)]
1414
pub struct NixVersion {
15+
/// Major version
1516
pub major: u32,
17+
/// Minor version
1618
pub minor: u32,
19+
/// Patch version
1720
pub patch: u32,
1821
}
1922

23+
/// Error type for parsing `nix --version`
2024
#[derive(Error, Debug, Clone, PartialEq)]
2125
pub enum BadNixVersion {
26+
/// Regex error
2227
#[error("Regex error: {0}")]
2328
Regex(#[from] regex::Error),
29+
30+
/// Parse error
2431
#[error("Parse error (regex): `nix --version` cannot be parsed")]
2532
Parse(#[from] std::num::ParseIntError),
33+
34+
/// Command error
2635
#[error("Parse error (int): `nix --version` cannot be parsed")]
2736
Command,
2837
}

‎crates/omnix-cli/crate.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
{ flake
2-
, rust-project
1+
{ rust-project
32
, pkgs
43
, lib
54
, ...
65
}:
76

87
let
9-
inherit (flake) inputs;
108
inherit (pkgs) stdenv pkgsStatic;
119
in
1210
{

‎crates/omnix-cli/tests/flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
outputs = inputs:
1515
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
1616
systems = import inputs.systems;
17-
perSystem = { pkgs, system, ... }: {
17+
perSystem = { system, ... }: {
1818
packages = {
1919
haskell-multi-nix = inputs.haskell-multi-nix.packages.${system}.default;
2020
};

‎nix/modules/devshell.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ inputs, ... }:
1+
{ ... }:
22

33
let
44
root = ../..;
@@ -8,7 +8,7 @@ in
88
(root + /crates/nix_health/module/flake-module.nix)
99
];
1010

11-
perSystem = { config, self', inputs', pkgs, lib, ... }: {
11+
perSystem = { config, self', pkgs, ... }: {
1212
devShells.default = pkgs.mkShell {
1313
name = "omnix-devshell";
1414
meta.description = "Omnix development environment";

0 commit comments

Comments
 (0)
Please sign in to comment.