Skip to content

Commit

Permalink
introduce permitted_insecure_packages for nixpkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Jul 1, 2024
1 parent ac9f0bd commit 5ae73bf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anysnake2"
version = "1.15.2"
version = "1.15.5"
authors = ["Florian Finkernagel <[email protected]>"]
edition = "2021"

Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ pub struct NixPkgs {
pub packages: Option<Vec<String>>,
#[serde(default = "NixPkgs::default_allow_unfree")]
pub allow_unfree: bool,

pub permitted_insecure_packages: Option<Vec<String>>,
}

impl NixPkgs {
Expand Down
1 change: 1 addition & 0 deletions src/flake_template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
inherit system overlays;
config = {
allowUnfree = "%ALLOW_UNFREE%";
permittedInsecurePackages = [ "%PERMITTED_INSECURE_PACKAGES%" ];
};
};
mach-nix_ = "%MACHNIX%";
Expand Down
48 changes: 30 additions & 18 deletions src/flake_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,30 +277,39 @@ old: old // {{\"_\" = old.\"_\" // {{

fn attrset_from_hashmap(attrset: &HashMap<String, String>) -> String {
let mut out = "".to_string();
for (pkg_name, override_nix_func) in attrset.iter() {
out
.push_str(&format!("\"{}\" = ({});", pkg_name, override_nix_func));
}
out

for (pkg_name, override_nix_func) in attrset.iter() {
out.push_str(&format!("\"{}\" = ({});", pkg_name, override_nix_func));
}
out
}

let r_override_args = r_config.override_attrs.as_ref().map_or("".to_string(), attrset_from_hashmap);
let r_dependency_overrides = r_config.dependency_overrides.as_ref().map_or("".to_string(), attrset_from_hashmap);
let r_additional_packages = r_config.additional_packages.as_ref().map_or("".to_string(), attrset_from_hashmap);
let r_override_args = r_config
.override_attrs
.as_ref()
.map_or("".to_string(), attrset_from_hashmap);
let r_dependency_overrides = r_config
.dependency_overrides
.as_ref()
.map_or("".to_string(), attrset_from_hashmap);
let r_additional_packages = r_config
.additional_packages
.as_ref()
.map_or("".to_string(), attrset_from_hashmap);

let mut r_pkg_list: Vec<String> = r_config.packages.iter().map(|x| x.to_string()).collect();
let mut r_pkg_list: Vec<String> =
r_config.packages.iter().map(|x| x.to_string()).collect();
if let Some(additional_packages) = &r_config.additional_packages {
for pkg_ver in additional_packages.keys() {
let (pkg, _ver) = pkg_ver.split_once("_").expect("R.additional_packages key did not conform to 'name_version' schema");
let (pkg, _ver) = pkg_ver.split_once("_").expect(
"R.additional_packages key did not conform to 'name_version' schema",
);
r_pkg_list.push(pkg.to_string());
}
}
//remove duplicates
r_pkg_list.sort();
r_pkg_list.dedup();


let r_packages = format!(
"
R_tracked = nixR.R_by_date {{
Expand All @@ -312,14 +321,10 @@ old: old // {{\"_\" = old.\"_\" // {{
}};
",
&r_config.date,
r_pkg_list .iter()
.map(|x| format!("\"{}\"", x))
.join(" "),

r_override_args,
r_pkg_list.iter().map(|x| format!("\"{}\"", x)).join(" "),
r_override_args,
r_dependency_overrides,
r_additional_packages

);
overlays.push(
"(final: prev: {
Expand Down Expand Up @@ -408,6 +413,13 @@ old: old // {{\"_\" = old.\"_\" // {{
"false"
},
);
flake_contents = flake_contents.replace(
"\"%PERMITTED_INSECURE_PACKAGES%\"",
&(parsed_config
.nixpkgs
.permitted_insecure_packages.as_ref()
.map_or_else(|| String::new(), |x| x.join(" "))),
);

let input_list: Vec<&str> = inputs.iter().map(|i| &i.name[..]).collect();
let input_list = input_list.join(", ");
Expand Down

0 comments on commit 5ae73bf

Please sign in to comment.