Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,020 changes: 581 additions & 439 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "fh"
version = "0.1.27"
authors = ["Determinate Systems <hello@determinate.systems>"]
edition = "2021"
edition = "2024"
license = "Apache 2.0"
repository = "https://github.com/DeterminateSystems/fh"

Expand Down
38 changes: 19 additions & 19 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
nixpkgs.url = "https://flakehub.com/f/DeterminateSystems/secure/0";

fenix = {
url = "https://flakehub.com/f/nix-community/fenix/=0.1.2375"; # Stick with v1.89 since v1.90 can't seem to compile nixel
url = "https://flakehub.com/f/nix-community/fenix/0.1";
inputs.nixpkgs.follows = "nixpkgs";
};

Expand Down Expand Up @@ -74,11 +74,9 @@
--fish <("$out/bin/fh" completion fish)
'';

LIBCLANG_PATH = "${final.buildPackages.libclang.lib}/lib";

env = {
LIBCLANG_PATH = "${final.buildPackages.libclang.lib}/lib";
SSL_CERT_FILE = "${final.cacert}/etc/ssl/certs/ca-bundle.crt";
NIX_CFLAGS_COMPILE = final.lib.optionalString final.stdenv.isDarwin "-I${final.libcxx.dev}/include/c++/v1";
};
};

Expand Down Expand Up @@ -108,7 +106,7 @@
}
);

formatter = forAllSystems ({ pkgs, ... }: pkgs.nixfmt-rfc-style);
formatter = forAllSystems ({ pkgs, ... }: pkgs.nixfmt);

devShells = forAllSystems (
{ system, pkgs }:
Expand All @@ -121,7 +119,7 @@

(writeShellApplication {
name = "check-nix-fmt";
runtimeInputs = [ nixfmt-rfc-style ];
runtimeInputs = [ nixfmt ];
text = ''
git ls-files '*.nix' | xargs nixfmt --check
'';
Expand All @@ -137,8 +135,11 @@
++ lib.optionals (stdenv.isDarwin) [ libiconv ];

env = {
LIBCLANG_PATH = "${pkgs.buildPackages.libclang.lib}/lib";
NIX_CFLAGS_COMPILE = pkgs.lib.optionalString pkgs.stdenv.isDarwin "-I${pkgs.libcxx.dev}/include/c++/v1";
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";

# Required for `cargo test` and `cargo clippy` on Linux
LD_LIBRARY_PATH = pkgs.lib.optionalString pkgs.stdenv.isLinux "${pkgs.buildPackages.libclang.lib}/lib:${pkgs.gcc.cc.lib}/lib";
};
};
}
Expand Down
25 changes: 16 additions & 9 deletions src/cli/cmd/add/flake.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::VecDeque;

use tracing::{span, Level};
use tracing::{Level, span};

const NEWLINE: &str = "\n";

Expand Down Expand Up @@ -285,7 +285,7 @@ impl std::str::FromStr for InputsInsertionLocation {
_ => {
return Err(color_eyre::eyre::eyre!(
"only `top` and `bottom` are valid insertion locations"
))
));
}
})
}
Expand Down Expand Up @@ -474,7 +474,9 @@ impl AttrType {
.iter()
.any(|arg| &*arg.identifier == flake_input_name)
{
tracing::debug!("input {flake_input_name} was already in the `outputs` function args, not adding it again");
tracing::debug!(
"input {flake_input_name} was already in the `outputs` function args, not adding it again"
);
return Ok(new_flake_contents);
}

Expand Down Expand Up @@ -505,8 +507,8 @@ impl AttrType {
new_flake_contents.insert_str(start, &span_text);
} else {
return Err(color_eyre::eyre::eyre!(
"could not find `{final_arg_identifier}` in the outputs function, but it existed when parsing it"
))?;
"could not find `{final_arg_identifier}` in the outputs function, but it existed when parsing it"
))?;
}
}
None => {
Expand All @@ -521,12 +523,14 @@ impl AttrType {
new_flake_contents.insert_str(start, &span_text);
} else {
return Err(color_eyre::eyre::eyre!(
"could not find the ellipsis (`...`) in the outputs function, but it existed when parsing it"
))?;
"could not find the ellipsis (`...`) in the outputs function, but it existed when parsing it"
))?;
}
} else {
// unfortunately this is legal, but I don't wanna support it
return Err(color_eyre::eyre::eyre!("the `outputs` function doesn't take any arguments, and fh add doesn't support that yet. Replace it with: outputs = {{ ... }}: and try again."))?;
return Err(color_eyre::eyre::eyre!(
"the `outputs` function doesn't take any arguments, and fh add doesn't support that yet. Replace it with: outputs = {{ ... }}: and try again."
))?;
}
}
}
Expand Down Expand Up @@ -1058,6 +1062,9 @@ mod test {
})
.unwrap();

assert!(wezterm_line_idx < nixpkgs_input_idx, "when inserting at the bottom, the new nixpkgs input should have come after the wezterm input");
assert!(
wezterm_line_idx < nixpkgs_input_idx,
"when inserting at the bottom, the new nixpkgs input should have come after the wezterm input"
);
}
}
14 changes: 7 additions & 7 deletions src/cli/cmd/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ pub(crate) async fn load_flake(

let mut parsed = nixel::parse(contents.clone());

if let nixel::Expression::Map(map) = *parsed.expression.clone() {
if map.bindings.is_empty() {
contents = FALLBACK_FLAKE_CONTENTS.to_string();
parsed = nixel::parse(FALLBACK_FLAKE_CONTENTS.to_string());
}
if let nixel::Expression::Map(map) = *parsed.expression.clone()
&& map.bindings.is_empty()
{
contents = FALLBACK_FLAKE_CONTENTS.to_string();
parsed = nixel::parse(FALLBACK_FLAKE_CONTENTS.to_string());
}

Ok((contents, parsed))
Expand All @@ -130,9 +130,9 @@ async fn infer_flake_input_name_url(
match (input_name, path_parts.next()) {
(Some(input_name), _) => Ok((input_name, parsed_url)),
(None, Some(input_name)) => Ok((input_name.to_string(), parsed_url)),
(None, _) => Err(color_eyre::eyre::eyre!(
(None, _) => Err(color_eyre::eyre::eyre!(
"cannot infer an input name for {parsed_url}; please specify one with the `--input-name` flag"
))
)),
}
}
// A URL like `nixos/nixpkgs` or `nixos/nixpkgs/0.2411`
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/apply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use clap::{Parser, Subcommand};
use color_eyre::eyre::Context;
use tempfile::{tempdir, TempDir};
use tempfile::{TempDir, tempdir};

use crate::{
cli::{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{io::stdout, process::ExitCode};

use crate::cli::Cli;
use clap::{CommandFactory, Parser};
use clap_complete::{generate, Shell};
use clap_complete::{Shell, generate};

use super::CommandExecute;

Expand Down
64 changes: 33 additions & 31 deletions src/cli/cmd/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::process::{ExitCode, Stdio};
use clap::Parser;
use color_eyre::eyre::Context;
use once_cell::sync::Lazy;
use tracing::{span, Level};
use tracing::{Level, span};

use super::{nix_command, CommandExecute};
use super::{CommandExecute, nix_command};

// match {nixos,nixpkgs,release}-YY.MM branches
static RELEASE_BRANCH_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
Expand Down Expand Up @@ -214,34 +214,34 @@ impl ConvertSubcommand {
}

// - has no nixpkgs in inputs but does have it in flake.lock, add it to flakehub.com/f/nixos/nixpkgs/0.1.0.tar.gz
if let Some(outputs_attr) = outputs_attr {
if let nixel::Expression::Function(f) = &*outputs_attr.to {
match &f.head {
// outputs = { nixpkgs, ... } @ inputs: { }
nixel::FunctionHead::Destructured(head)
if head
.arguments
.iter()
.any(|arg| *arg.identifier == input_name) =>
{
let (_, flakehub_url) = crate::cli::cmd::add::get_flakehub_project_and_url(
&self.api_addr,
"nixos",
&input_name,
None,
)
.await?;

new_flake_contents = crate::cli::cmd::add::flake::insert_flake_input(
expr,
input_name.clone(),
flakehub_url.clone(),
new_flake_contents,
crate::cli::cmd::add::flake::InputsInsertionLocation::Top,
)?;
}
_ => {}
if let Some(outputs_attr) = outputs_attr
&& let nixel::Expression::Function(f) = &*outputs_attr.to
{
match &f.head {
// outputs = { nixpkgs, ... } @ inputs: { }
nixel::FunctionHead::Destructured(head)
if head
.arguments
.iter()
.any(|arg| *arg.identifier == input_name) =>
{
let (_, flakehub_url) = crate::cli::cmd::add::get_flakehub_project_and_url(
&self.api_addr,
"nixos",
&input_name,
None,
)
.await?;

new_flake_contents = crate::cli::cmd::add::flake::insert_flake_input(
expr,
input_name.clone(),
flakehub_url.clone(),
new_flake_contents,
crate::cli::cmd::add::flake::InputsInsertionLocation::Top,
)?;
}
_ => {}
}
}

Expand Down Expand Up @@ -806,8 +806,10 @@ mod test {
.await
.unwrap();

assert!(new_flake_contents
.contains(r#"nixpkgs.url = "http://flakehub-localhost/f/NixOS/nixpkgs/*.tar.gz";"#));
assert!(
new_flake_contents
.contains(r#"nixpkgs.url = "http://flakehub-localhost/f/NixOS/nixpkgs/*.tar.gz";"#)
);
}

#[tokio::test]
Expand Down
9 changes: 4 additions & 5 deletions src/cli/cmd/eject/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process::ExitCode;

use clap::Parser;
use once_cell::sync::Lazy;
use tracing::{span, Level};
use tracing::{Level, span};

use super::{CommandExecute, FlakeHubClient, ProjectMetadata};

Expand Down Expand Up @@ -220,17 +220,16 @@ async fn eject_flakehub_input_to_github(

fn separate_year_from_month_in_version(version: &str) -> Option<String> {
let release_version_captures = RELEASE_VERSION_REGEX.captures(version);
let version = match release_version_captures {

match release_version_captures {
Some(captures) => {
let year = captures.name("year").unwrap().as_str();
let month = captures.name("month").unwrap().as_str();

Some(format!("{year}.{month}"))
}
_ => None,
};

version
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::process::ExitCode;

use clap::Parser;
use color_eyre::eyre;
use color_eyre::Result;
use color_eyre::eyre;

use crate::cli::cmd::copy_closure_with_gc_root;
use crate::shared::create_temp_netrc;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/init/handlers/php.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cli::cmd::init::{project::Project, prompt::Prompt};

use super::{version_as_attr_default, Flake, Handler, Input};
use super::{Flake, Handler, Input, version_as_attr_default};

const PHP_VERSIONS: &[&str] = &["8.3", "8.2", "8.1", "8.0", "7.4", "7.3"];

Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/init/handlers/python.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cli::cmd::init::{project::Project, prompt::Prompt};

use super::{version_as_attr_default, Flake, Handler};
use super::{Flake, Handler, version_as_attr_default};

const PYTHON_VERSIONS: &[&str] = &["3.11", "3.10", "3.9"];
const PYTHON_TOOLS: &[&str] = &["pip", "virtualenv", "pipenv"];
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cmd/init/handlers/ruby.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cli::cmd::init::{project::Project, prompt::Prompt};

use super::{version_as_attr, Flake, Handler};
use super::{Flake, Handler, version_as_attr};

const RUBY_VERSIONS: &[&str] = &["3.2", "3.1"];

Expand Down
Loading