Compare commits

..

10 commits
v0.0.3 ... main

Author SHA1 Message Date
Christina Sørensen
b60bbc162f
chore(release): cargo v0.0.4
All checks were successful
conventional commits / conventional commits (push) Successful in 9s
build / run (push) Successful in 8m14s
check / run (push) Successful in 1m40s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-13 07:19:58 +02:00
Christina Sørensen
85a6d6cc9a
refactor: handle clippy lints
All checks were successful
conventional commits / conventional commits (push) Successful in 13s
build / run (push) Successful in 1m1s
check / run (push) Successful in 1m50s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-13 07:16:34 +02:00
Christina Sørensen
cb34302e17
refactor(nix): tidy things into separate functions (this should be typestate but I'm eepy)
Some checks failed
conventional commits / conventional commits (push) Successful in 9s
build / run (push) Successful in 41s
check / run (push) Failing after 1m26s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-12 19:15:11 +02:00
Christina Sørensen
8c271f669a
fix: relative dir installables
Some checks failed
conventional commits / conventional commits (push) Successful in 6s
build / run (push) Successful in 36s
check / run (push) Failing after 56s
A leftover `current_dir` in the command builder for installables
resulted in `nix-weather ./#` invocations, and others relying on
relative filesystem paths failing.

Resolves: #20
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-12 13:09:18 +02:00
Christina Sørensen
e949478754
feat: parse installables
Some checks failed
conventional commits / conventional commits (push) Successful in 10s
build / run (push) Successful in 54s
check / run (push) Failing after 1m4s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-12 11:56:04 +02:00
Christina Sørensen
419976d275
feat(args): add -L/--print-build-logs flag, to feel more like nix3
All checks were successful
conventional commits / conventional commits (push) Successful in 12s
build / run (push) Successful in 1m3s
check / run (push) Successful in 1m38s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-12 11:21:10 +02:00
Jalil David Salamé Messina
6efdad5e66
fix: the small things
All checks were successful
conventional commits / conventional commits (push) Successful in 13s
build / run (push) Successful in 21s
check / run (push) Successful in 1m15s
* small typo on the flake description
* crane went full lib mode so it doesn't have any inputs to override
* `treefmt` warns on `nixfmt-rfc-style` as its `nixfmt` module is also
  `nixfmt-rfc-style`, switch to the `nixfmt` module.
* `pre-commit-hooks` uses `nixfmt-classic` when requesting `nixfmt` so
  we need to filter out `nixfmt` and enable `nixfmt-rfc-style` manually.
* there was an unneeded with statement warning from `nixd`

Signed-off-by: Jalil David Salame Messina <jalil.salame@gmail.com>
2024-09-11 09:29:02 +02:00
Christina Sørensen
19fa28545f
merge: fix-darwin from #27 into main
All checks were successful
conventional commits / conventional commits (push) Successful in 5s
build / run (push) Successful in 11s
check / run (push) Successful in 36s
2024-09-09 07:57:40 +02:00
Christina Sørensen
0a7cf9f016
fix: use our own forgejo actions repo
All checks were successful
conventional commits / conventional commits (pull_request) Successful in 9s
build / run (pull_request) Successful in 12s
check / run (pull_request) Successful in 46s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-09 07:50:42 +02:00
Christina Sørensen
bef974eda7
build(darwin): add nescesarry apple_sdk packages
Some checks failed
conventional commits / conventional commits (pull_request) Failing after 3s
check / run (pull_request) Failing after 4s
build / run (pull_request) Failing after 1s
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-09-08 22:21:22 +02:00
8 changed files with 92 additions and 30 deletions

View file

@ -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

View file

@ -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
View file

@ -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",

View file

@ -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>"]

View file

@ -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"),
)
}

View file

@ -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();

View file

@ -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()
}

View file

@ -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;
};
};