Skip to content

Commit

Permalink
remove unnecessary flake rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Nov 6, 2024
1 parent fedad48 commit 6396dad
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 15 deletions.
5 changes: 5 additions & 0 deletions examples/basic/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions examples/flake_in_non_root_github/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
home="./no-home"


[dev_shell]
inputs = []
shell = "bash"


[outside_nixpkgs]
url = "github:NixOS/nixpkgs/master/24.05"

Expand Down
4 changes: 2 additions & 2 deletions examples/github_tarballs_can_be_unstable/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[anysnake2]
url2 = "dev" # replace with fixed version outside of tests/examples
url = "dev" # replace with fixed version outside of tests/examples


[nixpkgs]
url = "github:NixOS/nixpkgs/master/24.05"


[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)


Expand Down
11 changes: 5 additions & 6 deletions examples/just_python/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
tomli=">1.2"


[dev_shell]
inputs = []
shell = "bash"


[outside_nixpkgs]
url = "github:nixos/nixpkgs/master/24.05"

Expand All @@ -52,9 +57,3 @@
[flake-util]
url = "github:numtide/flake-utils/main/b1d9ab70662946ef0850d488da1c9019f3a9752a"


[devshell]
inputs = []
shell = "bash"


5 changes: 5 additions & 0 deletions examples/just_python_poetry2nix_escape_hatch/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
version="0.2"


[dev_shell]
inputs = []
shell = "bash"


[outside_nixpkgs]
rev = "23.11"
url = "github:NixOS/nixpkgs/master/24.05"
Expand Down
5 changes: 5 additions & 0 deletions examples/minimal/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions examples/test_python_pulled_by_other_editable/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ fn extract_python_exec_from_python_env_bin(path: &PathBuf) -> Result<String> {
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
Expand Down
8 changes: 4 additions & 4 deletions src/tofu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,27 +1351,27 @@ impl Tofu<TofuDevShell> for Option<config::DevShell> {
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())
}
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()
Expand Down
14 changes: 12 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit 6396dad

Please sign in to comment.