From 6396dadb1d90d060c2beba48bc466ad63026cee2 Mon Sep 17 00:00:00 2001 From: Florian Finkernagel Date: Wed, 6 Nov 2024 09:44:12 +0100 Subject: [PATCH] remove unnecessary flake rewriting --- examples/basic/anysnake2.toml | 5 +++++ examples/flake_in_non_root_github/anysnake2.toml | 5 +++++ .../github_tarballs_can_be_unstable/anysnake2.toml | 4 ++-- examples/just_python/anysnake2.toml | 11 +++++------ .../anysnake2.toml | 5 +++++ examples/minimal/anysnake2.toml | 5 +++++ .../anysnake2.toml | 5 +++++ .../anysnake2.toml | 5 +++++ src/main.rs | 2 +- src/tofu.rs | 8 ++++---- src/util.rs | 14 ++++++++++++-- 11 files changed, 54 insertions(+), 15 deletions(-) diff --git a/examples/basic/anysnake2.toml b/examples/basic/anysnake2.toml index 985f3af..86593a3 100644 --- a/examples/basic/anysnake2.toml +++ b/examples/basic/anysnake2.toml @@ -71,6 +71,11 @@ done """ +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] # the nixpkgs used to run singularity and nixfmt url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/flake_in_non_root_github/anysnake2.toml b/examples/flake_in_non_root_github/anysnake2.toml index 65a6dd6..47b914b 100644 --- a/examples/flake_in_non_root_github/anysnake2.toml +++ b/examples/flake_in_non_root_github/anysnake2.toml @@ -22,6 +22,11 @@ home="./no-home" +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/github_tarballs_can_be_unstable/anysnake2.toml b/examples/github_tarballs_can_be_unstable/anysnake2.toml index 59f25ac..d194811 100644 --- a/examples/github_tarballs_can_be_unstable/anysnake2.toml +++ b/examples/github_tarballs_can_be_unstable/anysnake2.toml @@ -1,5 +1,5 @@ [anysnake2] - url2 = "dev" # replace with fixed version outside of tests/examples + url = "dev" # replace with fixed version outside of tests/examples [nixpkgs] @@ -7,7 +7,7 @@ [python] # python section is optional - ecosystem_date="2024-08-01" # you get whatever packages the solver would have produced on that day + ecosystem_date="2024-11-01" # you get whatever packages the solver would have produced on that day version="3.10" # does not go down to 3.8.x. That's implicit in the nixpkgs (for now) diff --git a/examples/just_python/anysnake2.toml b/examples/just_python/anysnake2.toml index 8c88343..caadf17 100644 --- a/examples/just_python/anysnake2.toml +++ b/examples/just_python/anysnake2.toml @@ -31,6 +31,11 @@ tomli=">1.2" +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] url = "github:nixos/nixpkgs/master/24.05" @@ -52,9 +57,3 @@ [flake-util] url = "github:numtide/flake-utils/main/b1d9ab70662946ef0850d488da1c9019f3a9752a" - -[devshell] - inputs = [] - shell = "bash" - - diff --git a/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml b/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml index d2ba6f2..d6bc67a 100644 --- a/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml +++ b/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml @@ -42,6 +42,11 @@ version="0.2" +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] rev = "23.11" url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/minimal/anysnake2.toml b/examples/minimal/anysnake2.toml index 917e5d1..c92dd63 100644 --- a/examples/minimal/anysnake2.toml +++ b/examples/minimal/anysnake2.toml @@ -9,6 +9,11 @@ url = "github:NixOS/nixpkgs/master/24.05" +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml b/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml index dcb2cc9..ca29880 100644 --- a/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml +++ b/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml @@ -29,6 +29,11 @@ testrepo2 = { url = "github:TyberiusPrime/_anysnake2_test_repo2/main/a42420f8ba0a6bc9bda0425cd665515fb92dc2b4", poetry2nix.buildInputs = ["setuptools"]} +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/test_python_pulled_by_other_editable/anysnake2.toml b/examples/test_python_pulled_by_other_editable/anysnake2.toml index 0bd7a6f..e0d9518 100644 --- a/examples/test_python_pulled_by_other_editable/anysnake2.toml +++ b/examples/test_python_pulled_by_other_editable/anysnake2.toml @@ -50,6 +50,11 @@ version="1.70.0" # this is the default, but you can override it here +[dev_shell] + inputs = [] + shell = "bash" + + [outside_nixpkgs] url = "github:NixOS/nixpkgs/master/24.05" diff --git a/src/main.rs b/src/main.rs index 649fc3d..51346ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1269,7 +1269,7 @@ fn extract_python_exec_from_python_env_bin(path: &PathBuf) -> Result { Some(x) => std::str::from_utf8(&x[1])?.to_string(), None => { let text = std::str::from_utf8(&text).with_context(|| { - format!("failed utf-8 converting {path:?}, but also had no NIX_PYTHONEXECUTABLE") + format!("failed utf-8 converting {path:?}, but also had no NIX_PYTHONEXECUTABLE. Did you leak a python binary with one of your input flakes into the container?") })?; let re = Regex::new("exec \"([^\"]+)\"").unwrap(); let out: String = re diff --git a/src/tofu.rs b/src/tofu.rs index 055eb8e..322dbc0 100644 --- a/src/tofu.rs +++ b/src/tofu.rs @@ -1351,12 +1351,12 @@ impl Tofu for Option { let (inputs, shell) = match self { None => { updates.push(( - vec!["devshell".to_string(), "inputs".to_string()], + vec!["dev_shell".to_string(), "inputs".to_string()], value(toml_edit::Array::default()), )); updates.push(( - vec!["devshell".to_string(), "shell".to_string()], + vec!["dev_shell".to_string(), "shell".to_string()], value("bash"), )); (Vec::new(), "bash".to_string()) @@ -1364,14 +1364,14 @@ impl Tofu for Option { Some(inner_self) => { let shell = inner_self.shell.unwrap_or_else(|| { updates.push(( - vec!["devshell".to_string(), "shell".to_string()], + vec!["dev_shell".to_string(), "shell".to_string()], value("bash"), )); "bash".to_string() }); let inputs = inner_self.inputs.unwrap_or_else(|| { updates.push(( - vec!["devshell".to_string(), "inputs".to_string()], + vec!["dev_shell".to_string(), "inputs".to_string()], value(toml_edit::Array::default()), )); Vec::new() diff --git a/src/util.rs b/src/util.rs index 7b93afb..1adfc72 100644 --- a/src/util.rs +++ b/src/util.rs @@ -179,9 +179,19 @@ pub fn change_toml_file(toml_path: &PathBuf, updates: TomlUpdates) -> Result<()> } } + let old_toml = std::fs::read(toml_path).ok().and_then(|x| std::string::String::from_utf8(x).ok()).unwrap_or_default(); + /* if !old_toml.is_empty() { + //copy to backup + let backup_path = toml_path.with_extension("toml.bak"); + std::fs::write(&backup_path, old_toml.clone()).context("failed to write backup")?; + } */ let out_toml = doc.to_string(); - std::fs::write(toml_path, out_toml.trim_start()).context("failed to rewrite config file")?; - info!("Wrote updated {:?}", toml_path); + if old_toml.trim() != out_toml.trim() { + std::fs::write(toml_path, out_toml.trim_start()).context("failed to rewrite config file")?; + info!("Wrote updated {:?}", toml_path); + } else { + debug!("Toml contents unchanged"); + } Ok(()) }