Fixup multiple --extra-conf usages (#456)

* Fixup multiple --extra-conf usages

* Merge experimental-features passed in extra-conf
This commit is contained in:
Ana Hobden 2023-05-09 07:53:25 -07:00 committed by GitHub
parent 217c3683bc
commit 7c9dfacf8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View file

@ -5,6 +5,7 @@ use crate::action::base::{CreateDirectory, CreateOrMergeNixConfig};
use crate::action::{
Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction,
};
use std::collections::hash_map::Entry;
const NIX_CONF_FOLDER: &str = "/etc/nix";
const NIX_CONF: &str = "/etc/nix/nix.conf";
@ -32,10 +33,21 @@ impl PlaceNixConfiguration {
let settings = nix_config.settings_mut();
settings.insert("build-users-group".to_string(), nix_build_group_name);
settings.insert(
"experimental-features".to_string(),
"nix-command flakes auto-allocate-uids".to_string(),
);
let experimental_features = ["nix-command", "flakes", "auto-allocate-uids"];
match settings.entry("experimental-features".to_string()) {
Entry::Occupied(mut slot) => {
let slot_mut = slot.get_mut();
for experimental_feature in experimental_features {
if !slot_mut.contains(experimental_feature) {
*slot_mut += " ";
*slot_mut += experimental_feature;
}
}
},
Entry::Vacant(slot) => {
let _ = slot.insert(experimental_features.join(" ").to_string());
},
};
settings.insert("auto-optimise-store".to_string(), "true".to_string());
settings.insert(
"bash-prompt-prefix".to_string(),

View file

@ -140,7 +140,7 @@ pub struct CommonSettings {
pub ssl_cert_file: Option<PathBuf>,
/// Extra configuration lines for `/etc/nix.conf`
#[cfg_attr(feature = "cli", clap(long, action = ArgAction::Set, num_args = 0.., value_delimiter = ',', env = "NIX_INSTALLER_EXTRA_CONF", global = true))]
#[cfg_attr(feature = "cli", clap(long, action = ArgAction::Append, num_args = 0.., env = "NIX_INSTALLER_EXTRA_CONF", global = true))]
pub extra_conf: Vec<String>,
/// If `nix-installer` should forcibly recreate files it finds existing