Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ToyVo committed Dec 5, 2024
1 parent 5f7b0da commit df692aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ jobs:
- run: nix build -L --no-link
name: Build

- run: nix run -L .#nh -- darwin switch --hostname nh_test --dry --no-nom --verbose .
- run: |
NH_DIR=$(pwd)
NH_FLAKE=/tmp/nh-darwin
mkdir -p $NH_FLAKE
cd $NH_FLAKE
nix flake init -t nix-darwin
cd $NH_DIR
nix run -L .#nh -- darwin switch --hostname simple --dry --no-nom --verbose $NH_FLAKE
name: Test Switching to Nix Darwin Configuration
14 changes: 0 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{
self,
nixpkgs,
nix-darwin,
}:
let
forAllSystems =
Expand Down Expand Up @@ -39,14 +34,5 @@
});

formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);

darwinConfigurations.nh_test = nix-darwin.lib.darwinSystem {
modules = [
{
nixpkgs.hostPlatform = "aarch64-darwin";
system.stateVersion = 5;
}
];
};
};
}
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(not(target_os = "macos"))]
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
35 changes: 19 additions & 16 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,25 @@ impl Command {
#[cfg(not(target_os = "macos"))]
let cmd = Exec::cmd("sudo");

// Check for if sudo has the preserve-env flag
#[cfg(target_os = "macos")]
let cmd = 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"]
},
);
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 {
Expand Down
23 changes: 10 additions & 13 deletions src/darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ fn get_hostname(hostname: Option<String>) -> Result<String> {
match &hostname {
Some(h) => Ok(h.to_owned()),
None => {
#[cfg(not(target_os = "macos"))]
{
Ok(hostname::get()
.context("Failed to get hostname")?
.to_str()
.unwrap()
.to_string())
}
#[cfg(target_os = "macos")]
{
let hostname = if cfg!(target_os = "macos") {
use system_configuration::{
core_foundation::{base::TCFType, string::CFString},
sys::dynamic_store_copy_specific::SCDynamicStoreCopyLocalHostName,
Expand All @@ -52,9 +43,15 @@ fn get_hostname(hostname: Option<String>) -> Result<String> {
bail!("Failed to get hostname");
}
let name = unsafe { CFString::wrap_under_get_rule(ptr) };

Ok(name.to_string())
}
name.to_string()
} else {
hostname::get()
.context("Failed to get hostname")?
.to_str()
.unwrap()
.to_string()
};
Ok(hostname)
}
}
}
Expand Down

0 comments on commit df692aa

Please sign in to comment.