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";
|
projectRootFile = "Cargo.toml";
|
||||||
programs = {
|
programs = {
|
||||||
nixfmt-rfc-style.enable = true; # nix
|
nixfmt.enable = true; # nix
|
||||||
statix.enable = true; # nix static analysis
|
statix.enable = true; # nix static analysis
|
||||||
deadnix.enable = true; # find dead nix code
|
deadnix.enable = true; # find dead nix code
|
||||||
rustfmt.enable = true; # rust
|
rustfmt.enable = true; # rust
|
||||||
|
|
|
@ -17,4 +17,4 @@ jobs:
|
||||||
runs-on: native
|
runs-on: native
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- 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]]
|
[[package]]
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
]
|
]
|
||||||
|
@ -1109,7 +1109,7 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix-weather"
|
name = "nix-weather"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
|
|
|
@ -8,7 +8,7 @@ members = ["crates/*", "crates/workspace-hack"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
description = "Guix weather, for nix!"
|
description = "Guix weather, for nix!"
|
||||||
version = "0.0.3"
|
version = "0.0.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "EUPL-1.2"
|
license = "EUPL-1.2"
|
||||||
authors = ["Christina Sørensen <christina@cafkafk.com>"]
|
authors = ["Christina Sørensen <christina@cafkafk.com>"]
|
||||||
|
|
|
@ -10,8 +10,10 @@ const DEFAULT_CACHE: &str = "cache.nixos.org";
|
||||||
pub fn build_cli() -> Command {
|
pub fn build_cli() -> Command {
|
||||||
command!()
|
command!()
|
||||||
.author(crate_authors!("\n"))
|
.author(crate_authors!("\n"))
|
||||||
|
// TODO: parse multiple installables, like e.g. build does?
|
||||||
|
.arg(arg!([installable] "A nix installable").required(false))
|
||||||
.arg(
|
.arg(
|
||||||
arg!(--cache <CACHE> "check a specific cache")
|
arg!(--cache <CACHE> "Check a specific cache")
|
||||||
.required(false)
|
.required(false)
|
||||||
.default_value(DEFAULT_CACHE),
|
.default_value(DEFAULT_CACHE),
|
||||||
)
|
)
|
||||||
|
@ -31,4 +33,9 @@ pub fn build_cli() -> Command {
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
.arg(arg!(-v --verbose ... "Verbosity level."))
|
.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.
|
// message informing them.
|
||||||
let mut very_bose = false;
|
let mut very_bose = false;
|
||||||
|
|
||||||
|
// The Normal verbose flag, allowing multiple levels. Conflicts with
|
||||||
|
// printBuildLogs.
|
||||||
match matches
|
match matches
|
||||||
.get_one::<u8>("verbose")
|
.get_one::<u8>("verbose")
|
||||||
.expect("Counts aren't defaulted")
|
.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") {
|
if matches.get_flag("timestamp") {
|
||||||
pretty_env_logger::formatted_timed_builder()
|
pretty_env_logger::formatted_timed_builder()
|
||||||
.parse_env("RUST_LOG")
|
.parse_env("RUST_LOG")
|
||||||
|
@ -96,7 +103,11 @@ async fn main() -> io::Result<()> {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.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();
|
let get_requisites_duration = initial_time.elapsed().as_secs();
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@ use std::{
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
/// Get nixosConfiguration derivation path
|
||||||
let get_drv_path = Command::new("nix")
|
#[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))
|
.current_dir(Path::new(config_dir))
|
||||||
.args([
|
.args([
|
||||||
"build",
|
"build",
|
||||||
|
@ -23,31 +25,69 @@ pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
||||||
"--json",
|
"--json",
|
||||||
])
|
])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
}
|
||||||
|
|
||||||
let drv_path_json: Value =
|
/// Get installable derivation path
|
||||||
serde_json::from_str(&String::from_utf8(get_drv_path.stdout).unwrap()).unwrap();
|
#[inline]
|
||||||
let drv_path = drv_path_json[0]["drvPath"].clone();
|
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);
|
/// Takes a drv_path and gets all it's requisites from the nix store.
|
||||||
|
#[inline]
|
||||||
let get_drv_requisites = Command::new("nix-store")
|
fn get_requisites_from_drv_path(drv_path: &str) -> std::io::Result<std::process::Child> {
|
||||||
.args(["--query", "--requisites", drv_path.as_str().unwrap()])
|
Command::new("nix-store")
|
||||||
|
.args(["--query", "--requisites", drv_path])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.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")
|
let drv_requisites_remove_base = Command::new("cut")
|
||||||
.args(["-d", "/", "-f4"])
|
.args(["-d", "/", "-f4"])
|
||||||
.stdin(Stdio::from(get_drv_requisites.stdout.unwrap()))
|
.stdin(Stdio::from(drv_requisites.stdout.unwrap()))
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let drv_requisites_to_hash = Command::new("cut")
|
Command::new("cut")
|
||||||
.args(["-d", "-", "-f1"])
|
.args(["-d", "-", "-f1"])
|
||||||
.stdin(Stdio::from(drv_requisites_remove_base.stdout.unwrap()))
|
.stdin(Stdio::from(drv_requisites_remove_base.stdout.unwrap()))
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.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
|
# 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 = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
@ -13,10 +13,7 @@
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
crane = {
|
crane.url = "github:ipetkov/crane";
|
||||||
url = "github:ipetkov/crane";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
|
|
||||||
fenix = {
|
fenix = {
|
||||||
url = "github:nix-community/fenix";
|
url = "github:nix-community/fenix";
|
||||||
|
@ -109,6 +106,8 @@
|
||||||
++ lib.optionals pkgs.stdenv.isDarwin [
|
++ lib.optionals pkgs.stdenv.isDarwin [
|
||||||
# Additional darwin specific inputs can be set here
|
# Additional darwin specific inputs can be set here
|
||||||
pkgs.libiconv
|
pkgs.libiconv
|
||||||
|
pkgs.darwin.apple_sdk.frameworks.Security
|
||||||
|
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
|
||||||
];
|
];
|
||||||
|
|
||||||
# Additional environment variables can be set directly
|
# Additional environment variables can be set directly
|
||||||
|
@ -242,7 +241,10 @@
|
||||||
pre-commit-check =
|
pre-commit-check =
|
||||||
let
|
let
|
||||||
# some treefmt formatters are not supported in pre-commit-hooks we filter them out for now.
|
# 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);
|
filterFn = n: _v: (!builtins.elem n toFilter);
|
||||||
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
|
treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
|
||||||
pkgs.lib.filterAttrs filterFn (import ./.config/treefmt.nix).programs
|
pkgs.lib.filterAttrs filterFn (import ./.config/treefmt.nix).programs
|
||||||
|
@ -253,10 +255,12 @@
|
||||||
hooks = treefmtFormatters // {
|
hooks = treefmtFormatters // {
|
||||||
# not in treefmt
|
# not in treefmt
|
||||||
convco.enable = true;
|
convco.enable = true;
|
||||||
|
# named nixfmt in treefmt (which defaults to nixfmt-classic for pre-commit-hooks)
|
||||||
|
nixfmt-rfc-style.enable = true;
|
||||||
reuse = {
|
reuse = {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "reuse";
|
name = "reuse";
|
||||||
entry = with pkgs; "${pkgs.reuse}/bin/reuse lint";
|
entry = with pkgs; "${reuse}/bin/reuse lint";
|
||||||
pass_filenames = false;
|
pass_filenames = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue