Skip to content

Commit

Permalink
Fixup multiple --extra-conf usages (#456)
Browse files Browse the repository at this point in the history
* Fixup multiple --extra-conf usages

* Merge experimental-features passed in extra-conf
  • Loading branch information
Hoverbear authored May 9, 2023
1 parent 217c368 commit 7c9dfac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/action/common/place_nix_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c9dfac

Please sign in to comment.