|
1 | 1 | use std::collections::HashMap;
|
2 | 2 | use std::fs;
|
3 |
| -use std::path::{Path, PathBuf}; |
| 3 | +use std::path::Path; |
4 | 4 | use std::process;
|
5 | 5 |
|
6 | 6 | use chrono::{DateTime, Local, TimeZone, Utc};
|
@@ -66,16 +66,34 @@ pub fn describe(generation_dir: &Path) -> Option<GenerationInfo> {
|
66 | 66 | let nixos_version = fs::read_to_string(generation_dir.join("nixos-version"))
|
67 | 67 | .unwrap_or_else(|_| "Unknown".to_string());
|
68 | 68 |
|
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 |
70 | 75 | .join("kernel")
|
71 | 76 | .canonicalize()
|
72 | 77 | .ok()
|
73 | 78 | .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"); |
75 | 81 |
|
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) { |
79 | 97 | Ok(entries) => {
|
80 | 98 | let mut versions = Vec::with_capacity(4);
|
81 | 99 | for entry in entries.filter_map(Result::ok) {
|
|
0 commit comments