Skip to content

Commit

Permalink
darwin updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ToyVo committed Dec 1, 2024
1 parent 24293d6 commit 1e458a5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ 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: nix run -L .#nh -- darwin switch --hostname nh_test --dry --no-nom --verbose .
name: Test Switching to Nix Darwin Configuration
21 changes: 21 additions & 0 deletions flake.lock

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

19 changes: 18 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{ self, nixpkgs }:
{
self,
nixpkgs,
nix-darwin,
}:
let
forAllSystems =
function:
Expand All @@ -31,5 +39,14 @@
});

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

darwinConfigurations.nh_test = nix-darwin.lib.darwinSystem {
modules = [
{
nixpkgs.hostPlatform = "aarch64-darwin";
system.stateVersion = 5;
}
];
};
};
}
2 changes: 1 addition & 1 deletion src/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +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")]
#[cfg(not(target_os = "macos"))]
let uid_min = 1000;
#[cfg(target_os = "macos")]
let uid_min = 501;
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)
#[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"]
},
);

cmd.arg(&self.command).args(&self.args)
} else {
Exec::cmd(&self.command).args(&self.args)
}
Expand Down
9 changes: 6 additions & 3 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 @@ -133,20 +133,23 @@ impl DarwinRebuildArgs {
Command::new("nix")
.args(["build", "--profile", SYSTEM_PROFILE])
.arg(out_path.get_path())
.elevate(true)
.elevate(!self.common.dry)
.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)
.elevate(!self.common.dry)
.message("Activating configuration")
.dry(self.common.dry)
.run()?;
}

Expand Down

0 comments on commit 1e458a5

Please sign in to comment.