Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
|
b60bbc162f | ||
|
85a6d6cc9a | ||
|
cb34302e17 | ||
|
8c271f669a | ||
|
e949478754 | ||
|
419976d275 | ||
|
6efdad5e66 | ||
|
19fa28545f | ||
|
0a7cf9f016 | ||
|
bef974eda7 |
8 changed files with 92 additions and 30 deletions
|
@ -5,7 +5,7 @@
|
|||
{
|
||||
projectRootFile = "Cargo.toml";
|
||||
programs = {
|
||||
nixfmt-rfc-style.enable = true; # nix
|
||||
nixfmt.enable = true; # nix
|
||||
statix.enable = true; # nix static analysis
|
||||
deadnix.enable = true; # find dead nix code
|
||||
rustfmt.enable = true; # rust
|
||||
|
|
|
@ -17,4 +17,4 @@ jobs:
|
|||
runs-on: native
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: https://github.com/webiny/action-conventional-commits@v1.3.0
|
||||
- uses: actions/action-conventional-commits@v1.3.0
|
||||
|
|
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -304,7 +304,7 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
|||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"workspace-hack",
|
||||
]
|
||||
|
@ -1109,7 +1109,7 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
|||
|
||||
[[package]]
|
||||
name = "nix-weather"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
|
|
|
@ -8,7 +8,7 @@ members = ["crates/*", "crates/workspace-hack"]
|
|||
|
||||
[workspace.package]
|
||||
description = "Guix weather, for nix!"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
edition = "2021"
|
||||
license = "EUPL-1.2"
|
||||
authors = ["Christina Sørensen <christina@cafkafk.com>"]
|
||||
|
|
|
@ -10,8 +10,10 @@ const DEFAULT_CACHE: &str = "cache.nixos.org";
|
|||
pub fn build_cli() -> Command {
|
||||
command!()
|
||||
.author(crate_authors!("\n"))
|
||||
// TODO: parse multiple installables, like e.g. build does?
|
||||
.arg(arg!([installable] "A nix installable").required(false))
|
||||
.arg(
|
||||
arg!(--cache <CACHE> "check a specific cache")
|
||||
arg!(--cache <CACHE> "Check a specific cache")
|
||||
.required(false)
|
||||
.default_value(DEFAULT_CACHE),
|
||||
)
|
||||
|
@ -31,4 +33,9 @@ pub fn build_cli() -> Command {
|
|||
.required(false),
|
||||
)
|
||||
.arg(arg!(-v --verbose ... "Verbosity level."))
|
||||
.arg(
|
||||
arg!(printBuildLogs: -L "Verbosity level.")
|
||||
.long("print-build-logs")
|
||||
.conflicts_with("verbose"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ async fn main() -> io::Result<()> {
|
|||
// message informing them.
|
||||
let mut very_bose = false;
|
||||
|
||||
// The Normal verbose flag, allowing multiple levels. Conflicts with
|
||||
// printBuildLogs.
|
||||
match matches
|
||||
.get_one::<u8>("verbose")
|
||||
.expect("Counts aren't defaulted")
|
||||
|
@ -52,6 +54,11 @@ async fn main() -> io::Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
// The -L flag, to give a more nix3 feel
|
||||
if matches.get_flag("printBuildLogs") {
|
||||
env::set_var("RUST_LOG", "trace")
|
||||
}
|
||||
|
||||
if matches.get_flag("timestamp") {
|
||||
pretty_env_logger::formatted_timed_builder()
|
||||
.parse_env("RUST_LOG")
|
||||
|
@ -96,7 +103,11 @@ async fn main() -> io::Result<()> {
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
let binding = get_requisites(&host_name, &config_dir);
|
||||
let binding = get_requisites(
|
||||
&host_name,
|
||||
&config_dir,
|
||||
matches.get_one::<String>("installable").cloned(),
|
||||
);
|
||||
|
||||
let get_requisites_duration = initial_time.elapsed().as_secs();
|
||||
|
||||
|
|
|
@ -9,8 +9,10 @@ use std::{
|
|||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
||||
let get_drv_path = Command::new("nix")
|
||||
/// Get nixosConfiguration derivation path
|
||||
#[inline]
|
||||
fn get_config_drv_path(host: &str, config_dir: &str) -> std::io::Result<std::process::Output> {
|
||||
Command::new("nix")
|
||||
.current_dir(Path::new(config_dir))
|
||||
.args([
|
||||
"build",
|
||||
|
@ -23,31 +25,69 @@ pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
|||
"--json",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let drv_path_json: Value =
|
||||
serde_json::from_str(&String::from_utf8(get_drv_path.stdout).unwrap()).unwrap();
|
||||
let drv_path = drv_path_json[0]["drvPath"].clone();
|
||||
/// Get installable derivation path
|
||||
#[inline]
|
||||
fn get_installable_drv_path(installable: &str) -> std::io::Result<std::process::Output> {
|
||||
Command::new("nix")
|
||||
.args(["build", "--quiet", installable, "--dry-run", "--json"])
|
||||
.output()
|
||||
}
|
||||
|
||||
log::debug!("drv_path: {}", &drv_path);
|
||||
|
||||
let get_drv_requisites = Command::new("nix-store")
|
||||
.args(["--query", "--requisites", drv_path.as_str().unwrap()])
|
||||
/// Takes a drv_path and gets all it's requisites from the nix store.
|
||||
#[inline]
|
||||
fn get_requisites_from_drv_path(drv_path: &str) -> std::io::Result<std::process::Child> {
|
||||
Command::new("nix-store")
|
||||
.args(["--query", "--requisites", drv_path])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Turns requisites into hashes
|
||||
#[inline]
|
||||
fn requisites_to_hashes(
|
||||
drv_requisites: std::process::Child,
|
||||
) -> std::io::Result<std::process::Child> {
|
||||
let drv_requisites_remove_base = Command::new("cut")
|
||||
.args(["-d", "/", "-f4"])
|
||||
.stdin(Stdio::from(get_drv_requisites.stdout.unwrap()))
|
||||
.stdin(Stdio::from(drv_requisites.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let drv_requisites_to_hash = Command::new("cut")
|
||||
Command::new("cut")
|
||||
.args(["-d", "-", "-f1"])
|
||||
.stdin(Stdio::from(drv_requisites_remove_base.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
String::from_utf8(drv_requisites_to_hash.wait_with_output().unwrap().stdout).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_requisites(host: &str, config_dir: &str, installable: Option<String>) -> String {
|
||||
// If the users specified an installable, we interpret that, instead of trying
|
||||
// to guess their config location.
|
||||
let drv_path;
|
||||
if let Some(installable) = installable {
|
||||
drv_path = get_installable_drv_path(&installable).unwrap();
|
||||
} else {
|
||||
drv_path = get_config_drv_path(host, config_dir).unwrap();
|
||||
}
|
||||
|
||||
let drv_path_json: Value =
|
||||
serde_json::from_str(&String::from_utf8(drv_path.stdout).unwrap()).unwrap();
|
||||
let drv_path = drv_path_json[0]["drvPath"].clone();
|
||||
|
||||
log::debug!("drv_path: {}", &drv_path);
|
||||
|
||||
let drv_requisites = get_requisites_from_drv_path(drv_path.as_str().unwrap()).unwrap();
|
||||
|
||||
let drv_requisite_hashes = requisites_to_hashes(drv_requisites);
|
||||
|
||||
String::from_utf8(
|
||||
drv_requisite_hashes
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap()
|
||||
.stdout,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
18
flake.nix
18
flake.nix
|
@ -3,7 +3,7 @@
|
|||
# SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
{
|
||||
description = "Nix Weather - Check Cache Availablility of NixOS Configurations";
|
||||
description = "Nix Weather - Check Cache Availability of NixOS Configurations";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
@ -13,10 +13,7 @@
|
|||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
crane = {
|
||||
url = "github:ipetkov/crane";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
crane.url = "github:ipetkov/crane";
|
||||
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
|
@ -109,6 +106,8 @@
|
|||
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||
# Additional darwin specific inputs can be set here
|
||||
pkgs.libiconv
|
||||
pkgs.darwin.apple_sdk.frameworks.Security
|
||||
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
|
||||
];
|
||||
|
||||
# Additional environment variables can be set directly
|
||||
|
@ -242,7 +241,10 @@
|
|||
pre-commit-check =
|
||||
let
|
||||
# some treefmt formatters are not supported in pre-commit-hooks we filter them out for now.
|
||||
toFilter = [ "yamlfmt" ];
|
||||
toFilter = [
|
||||
"yamlfmt"
|
||||
"nixfmt"
|
||||
];
|
||||
filterFn = n: _v: (!builtins.elem n toFilter);
|
||||
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
|
||||
pkgs.lib.filterAttrs filterFn (import ./.config/treefmt.nix).programs
|
||||
|
@ -253,10 +255,12 @@
|
|||
hooks = treefmtFormatters // {
|
||||
# not in treefmt
|
||||
convco.enable = true;
|
||||
# named nixfmt in treefmt (which defaults to nixfmt-classic for pre-commit-hooks)
|
||||
nixfmt-rfc-style.enable = true;
|
||||
reuse = {
|
||||
enable = true;
|
||||
name = "reuse";
|
||||
entry = with pkgs; "${pkgs.reuse}/bin/reuse lint";
|
||||
entry = with pkgs; "${reuse}/bin/reuse lint";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue