Skip to content

Commit ce5a8ce

Browse files
committed
generations: try the new kernel module path first
Signed-off-by: NotAShelf <[email protected]> Change-Id: I6a6a69645653279117db34cc192ceb784836870a
1 parent d652f6b commit ce5a8ce

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/generations.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22
use std::fs;
3-
use std::path::{Path, PathBuf};
3+
use std::path::Path;
44
use std::process;
55

66
use chrono::{DateTime, Local, TimeZone, Utc};
@@ -66,16 +66,34 @@ pub fn describe(generation_dir: &Path) -> Option<GenerationInfo> {
6666
let nixos_version = fs::read_to_string(generation_dir.join("nixos-version"))
6767
.unwrap_or_else(|_| "Unknown".to_string());
6868

69-
let kernel_dir = generation_dir
69+
// XXX: Nixpkgs appears to have changed where kernel modules are stored in a
70+
// recent change. I do not care to track which, but we should try the new path
71+
// and fall back to the old one IF and ONLY IF the new one fails. This is to
72+
// avoid breakage for outdated channels.
73+
let kernel_modules_dir_new = generation_dir.join("kernel-modules/lib/modules");
74+
let kernel_modules_dir_old = generation_dir
7075
.join("kernel")
7176
.canonicalize()
7277
.ok()
7378
.and_then(|path| path.parent().map(std::path::Path::to_path_buf))
74-
.unwrap_or_else(|| PathBuf::from("Unknown"));
79+
.unwrap_or_else(|| generation_dir.to_path_buf())
80+
.join("lib/modules");
7581

76-
let kernel_modules_dir = kernel_dir.join("lib/modules");
77-
let kernel_version = if kernel_modules_dir.exists() {
78-
match fs::read_dir(&kernel_modules_dir) {
82+
let kernel_version = if kernel_modules_dir_new.exists() {
83+
match fs::read_dir(&kernel_modules_dir_new) {
84+
Ok(entries) => {
85+
let mut versions = Vec::with_capacity(4);
86+
for entry in entries.filter_map(Result::ok) {
87+
if let Some(name) = entry.file_name().to_str() {
88+
versions.push(name.to_string());
89+
}
90+
}
91+
versions.join(", ")
92+
}
93+
Err(_) => "Unknown".to_string(),
94+
}
95+
} else if kernel_modules_dir_old.exists() {
96+
match fs::read_dir(&kernel_modules_dir_old) {
7997
Ok(entries) => {
8098
let mut versions = Vec::with_capacity(4);
8199
for entry in entries.filter_map(Result::ok) {

0 commit comments

Comments
 (0)