Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ToyVo authored and viperML committed Dec 6, 2024
1 parent 6752252 commit 8d552c0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ jobs:
./fix.sh
git diff-index --quiet HEAD
name: Check formatting
Test_Darwin:
runs-on: macos-latest

steps:
- uses: cachix/install-nix-action@master
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4

- run: nix build -L --no-link
name: Build

- run: |
mkdir flake
cd flake
nix flake init -t nix-darwin
git add flake.nix
cd ..
nix run .#nh -- darwin switch --hostname simple --dry --no-nom --verbose ./flake
name: Test Switching to Nix Darwin Configuration
5 changes: 1 addition & 4 deletions src/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ impl interface::CleanMode {

// Most unix systems start regular users at uid 1000+, but macos is special at 501+
// https://en.wikipedia.org/wiki/User_identifier
#[cfg(target_os = "linux")]
let uid_min = 1000;
#[cfg(target_os = "macos")]
let uid_min = 501;
let uid_min = if cfg!(target_os = "macos") { 501 } else { 1000 };
let uid_max = uid_min + 100;
debug!("Scanning XDG profiles for users 0, ${uid_min}-${uid_max}");
for user in unsafe { uzers::all_users() } {
Expand Down
22 changes: 21 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,27 @@ impl Command {

pub fn run(&self) -> Result<()> {
let cmd = if self.elevate {
Exec::cmd("sudo").arg(&self.command).args(&self.args)
let cmd = if cfg!(target_os = "macos") {
// Check for if sudo has the preserve-env flag
Exec::cmd("sudo").args(
if Exec::cmd("sudo")
.args(&["--help"])
.stderr(Redirection::None)
.stdout(Redirection::Pipe)
.capture()?
.stdout_str()
.contains("--preserve-env")
{
&["--set-home", "--preserve-env=PATH", "env"]
} else {
&["--set-home"]
},
)
} else {
Exec::cmd("sudo")
};

cmd.arg(&self.command).args(&self.args)
} else {
Exec::cmd(&self.command).args(&self.args)
}
Expand Down
11 changes: 5 additions & 6 deletions src/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl DarwinRebuildArgs {
ref mut attribute, ..
} = installable
{
// If user explicitely selects some other attribute, don't push darwinConfigurations
// If user explicitly selects some other attribute, don't push darwinConfigurations
if attribute.is_empty() {
attribute.push(String::from("darwinConfigurations"));
attribute.push(hostname.clone());
Expand Down Expand Up @@ -116,11 +116,7 @@ impl DarwinRebuildArgs {
.message("Comparing changes")
.run()?;

if self.common.dry || matches!(variant, Build) {
return Ok(());
}

if self.common.ask {
if self.common.ask && !self.common.dry && !matches!(variant, Build) {
info!("Apply the config?");
let confirmation = dialoguer::Confirm::new().default(false).interact()?;

Expand All @@ -134,19 +130,22 @@ impl DarwinRebuildArgs {
.args(["build", "--profile", SYSTEM_PROFILE])
.arg(out_path.get_path())
.elevate(true)
.dry(self.common.dry)
.run()?;

let switch_to_configuration = out_path.get_path().join("activate-user");

Command::new(switch_to_configuration)
.message("Activating configuration for user")
.dry(self.common.dry)
.run()?;

let switch_to_configuration = out_path.get_path().join("activate");

Command::new(switch_to_configuration)
.elevate(true)
.message("Activating configuration")
.dry(self.common.dry)
.run()?;
}

Expand Down

0 comments on commit 8d552c0

Please sign in to comment.