Skip to content

Commit 65211db

Browse files
authored
Merge pull request #213 from serokell/rvem/darwin-activation
[#210] Add activation script for darwin system and provide a usage example
2 parents c801899 + 8ef5b94 commit 65211db

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

examples/darwin/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io/>
3+
4+
SPDX-License-Identifier: MPL-2.0
5+
-->
6+
7+
# Example nix-darwin system deployment
8+
9+
## Prerequisites
10+
11+
1) Install `nix` and `nix-darwin` (the latter creates `/run` sets up `/etc/nix/nix.conf` symlink and so on)
12+
on the target machine.
13+
2) Enable remote login on the mac to allow ssh access.
14+
3) `deploy-rs` doesn't support password provisioning for `sudo`, so the `sshUser` should
15+
have passwordless `sudo` access.
16+
17+
## Deploying
18+
19+
Run `nix run github:serokell/deploy-rs -- --ssh-user <user>`.

examples/darwin/flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
description = "Deploy simple 'darwinSystem' to a darwin machine";
3+
4+
inputs.deploy-rs.url = "github:serokell/deploy-rs";
5+
inputs.darwin.url = "github:LnL7/nix-darwin";
6+
7+
outputs = { self, nixpkgs, deploy-rs, darwin }: {
8+
darwinConfigurations.example = darwin.lib.darwinSystem {
9+
system = "x86_64-darwin";
10+
modules = [
11+
({lib, config, pkgs, ...}: {
12+
services.nix-daemon.enable = true;
13+
nix = {
14+
settings = {
15+
trusted-users = [ "rvem" ];
16+
};
17+
extraOptions = ''
18+
experimental-features = flakes nix-command
19+
'';
20+
};
21+
# nix commands are added to PATH in the zsh config
22+
programs.zsh.enable = true;
23+
})
24+
];
25+
};
26+
deploy = {
27+
# remoteBuild = true; # Uncomment in case the system you're deploying from is not darwin
28+
nodes.example = {
29+
hostname = "localhost";
30+
profiles.system = {
31+
user = "root";
32+
path = deploy-rs.lib.x86_64-darwin.activate.darwin self.darwinConfigurations.example;
33+
};
34+
};
35+
};
36+
37+
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
38+
};
39+
}

flake.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106

107107
home-manager = base: custom base.activationPackage "$PROFILE/activate";
108108

109+
# Activation script for 'darwinSystem' from nix-darwin.
110+
# 'HOME=/var/root' is needed because 'sudo' on darwin doesn't change 'HOME' directory,
111+
# while 'darwin-rebuild' (which is invoked under the hood) performs some nix-channel
112+
# checks that rely on 'HOME'. As a result, if 'sshUser' is different from root,
113+
# deployment may fail without explicit 'HOME' redefinition.
114+
darwin = base: custom base.config.system.build.toplevel "HOME=/var/root $PROFILE/activate";
115+
109116
noop = base: custom base ":";
110117
};
111118

0 commit comments

Comments
 (0)