Skip to content

Commit 6a31b63

Browse files
authored
Merge pull request #438 from divnix/darwin-support
Add Support for Darwin/macOS Hosts
2 parents d60f27f + 580fc57 commit 6a31b63

38 files changed

+690
-320
lines changed

.github/workflows/check.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ on:
99

1010
jobs:
1111
check:
12-
runs-on: ubuntu-latest
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
os: [ubuntu-latest, macos-latest]
1317
steps:
1418

1519
- uses: actions/checkout@v3

default.nix

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ let
77
sha256 = lock.nodes.flake-compat.locked.narHash;
88
}
99
)
10-
{ src = ./.; }
11-
) defaultNix;
10+
{ src = ./.; }) defaultNix;
1211
in
13-
# Pass this flake as inputs.digga
14-
defaultNix // {
15-
inputs = defaultNix.inputs // { digga = defaultNix; };
16-
shell = import ./devShell.nix { };
17-
}
12+
# Pass this flake as inputs.digga
13+
defaultNix // {
14+
inputs = defaultNix.inputs // { digga = defaultNix; };
15+
shell = import ./devShell.nix { };
16+
}
1817

deprecated.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, flake-utils-plus, internal-modules, importers, nixosModules }:
1+
{ lib, importers }:
22
lib.warn ''
33
You are accessing a deprecated item of the digga lib.
44
Please update timely, it will be remove soon.

devShell.nix

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
, inputs ? (import ./.).inputs
33
}:
44
let
5-
65
pkgs = inputs.nixpkgs.legacyPackages.${system};
7-
devshell = import inputs.devshell { inherit pkgs system; };
6+
unstablePkgs = inputs.nixpkgs-unstable.legacyPackages.${system};
7+
devshell = import inputs.devshell { inherit system; };
8+
nixBin = "${unstablePkgs.nix}/bin/nix";
89

910
withCategory = category: attrset: attrset // { inherit category; };
1011
utils = withCategory "utils";
@@ -79,9 +80,9 @@ let
7980
digga_fixture
8081
8182
test -f flake.lock && lockfile_present=$? || true
82-
${pkgs.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?;
83-
${pkgs.nixUnstable}/bin/nix flake show "$@"
84-
${pkgs.nixUnstable}/bin/nix flake check "$@"
83+
${nixBin} flake lock --update-input digga "$@"; lockfile_updated=$?;
84+
${nixBin} flake show "$@"
85+
${nixBin} flake check "$@"
8586
8687
cleanup
8788
'';
@@ -93,7 +94,8 @@ devshell.mkShell {
9394
packages = with pkgs; [
9495
fd
9596
nixpkgs-fmt
96-
nixUnstable
97+
# Use the latest stable version of nix
98+
unstablePkgs.nix
9799
];
98100

99101
env = [

doc/api-reference-channels.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ nix flake
5757
## channels.\<name\>.overlays
5858
overlays to apply to this channel
5959
these will get exported under the 'overlays' flake output
60-
as \<channel\>/\<name\> and any overlay pulled from ${inputs}
60+
as \<channel\>/\<name\> and any overlay pulled from \<inputs\>
6161
will be filtered out
6262

6363

@@ -73,3 +73,19 @@ list of valid Nixpkgs overlay or path convertible to its or anything convertible
7373

7474

7575

76+
## channels.\<name\>.patches
77+
patches to apply to this channel
78+
79+
80+
*_Type_*:
81+
list of paths
82+
83+
84+
*_Default_*
85+
```
86+
[]
87+
```
88+
89+
90+
91+

doc/api-reference-home.md

-48
Original file line numberDiff line numberDiff line change
@@ -101,54 +101,6 @@ list of valid modules or anything convertible to it or path convertible to it
101101

102102

103103

104-
## home.profiles
105-
WARNING: The 'suites' and `profiles` options have been deprecated, you can now create
106-
both with the importables option. `rakeLeaves` can be used to create profiles and
107-
by passing a module or `rec` set to `importables`, suites can access profiles.
108-
Example:
109-
```
110-
importables = rec {
111-
profiles = digga.lib.rakeLeaves ./profiles;
112-
suites = with profiles; { };
113-
}
114-
```
115-
See https://github.com/divnix/digga/pull/30 for more details
116-
117-
118-
*_Type_*:
119-
list of paths or path convertible to it
120-
121-
122-
*_Default_*
123-
```
124-
[]
125-
```
126-
127-
128-
129-
130-
## home.suites
131-
WARNING: The 'suites' and `profiles` options have been deprecated, you can now create
132-
both with the importables option. `rakeLeaves` can be used to create profiles and
133-
by passing a module or `rec` set to `importables`, suites can access profiles.
134-
Example:
135-
```
136-
importables = rec {
137-
profiles = digga.lib.rakeLeaves ./profiles;
138-
suites = with profiles; { };
139-
}
140-
```
141-
See https://github.com/divnix/digga/pull/30 for more details
142-
143-
144-
*_Type_*:
145-
function that evaluates to a(n) attrs or path convertible to it
146-
147-
148-
149-
150-
151-
152104
## home.users
153105
HM users that can be deployed portably without a host.
154106

doc/api-reference-nixos.md

-48
Original file line numberDiff line numberDiff line change
@@ -232,51 +232,3 @@ null
232232

233233

234234

235-
## nixos.profiles
236-
WARNING: The 'suites' and `profiles` options have been deprecated, you can now create
237-
both with the importables option. `rakeLeaves` can be used to create profiles and
238-
by passing a module or `rec` set to `importables`, suites can access profiles.
239-
Example:
240-
```
241-
importables = rec {
242-
profiles = digga.lib.rakeLeaves ./profiles;
243-
suites = with profiles; { };
244-
}
245-
```
246-
See https://github.com/divnix/digga/pull/30 for more details
247-
248-
249-
*_Type_*:
250-
list of paths or path convertible to it
251-
252-
253-
*_Default_*
254-
```
255-
[]
256-
```
257-
258-
259-
260-
261-
## nixos.suites
262-
WARNING: The 'suites' and `profiles` options have been deprecated, you can now create
263-
both with the importables option. `rakeLeaves` can be used to create profiles and
264-
by passing a module or `rec` set to `importables`, suites can access profiles.
265-
Example:
266-
```
267-
importables = rec {
268-
profiles = digga.lib.rakeLeaves ./profiles;
269-
suites = with profiles; { };
270-
}
271-
```
272-
See https://github.com/divnix/digga/pull/30 for more details
273-
274-
275-
*_Type_*:
276-
function that evaluates to a(n) attrs or path convertible to it
277-
278-
279-
280-
281-
282-

doc/api-reference.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Home](./api-reference-home.md)
66
- [Devshell](./api-reference-devshell.md)
77
- [NixOS](./api-reference-nixos.md)
8+
- [Darwin](./api-reference-darwin.md)
89

910
## channelsConfig
1011
nixpkgs config for all channels
@@ -39,7 +40,7 @@ The builder gets passed an attrset of all channels
3940

4041

4142
*_Type_*:
42-
function that evaluates to a(n) attrs or path convertible to it
43+
function that evaluates to a(n) attribute set or path convertible to it
4344

4445

4546
*_Default_*

examples/devos/flake.nix

+73-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
# Track channels with commits tested and built by hydra
1111
nixos.url = "github:nixos/nixpkgs/nixos-21.11";
1212
latest.url = "github:nixos/nixpkgs/nixos-unstable";
13+
# For darwin hosts: it can be helpful to track this darwin-specific stable
14+
# channel equivalent to the `nixos-*` channels for NixOS. For one, these
15+
# channels are more likely to provide cached binaries for darwin systems.
16+
# But, perhaps even more usefully, it provides a place for adding
17+
# darwin-specific overlays and packages which could otherwise cause build
18+
# failures on Linux systems.
19+
nixpkgs-darwin-stable.url = "github:NixOS/nixpkgs/nixpkgs-21.11-darwin";
1320

1421
digga.url = "github:divnix/digga";
1522
digga.inputs.nixpkgs.follows = "nixos";
@@ -25,7 +32,7 @@
2532
home.inputs.nixpkgs.follows = "nixos";
2633

2734
darwin.url = "github:LnL7/nix-darwin";
28-
darwin.inputs.nixpkgs.follows = "nixos";
35+
darwin.inputs.nixpkgs.follows = "nixpkgs-darwin-stable";
2936

3037
deploy.url = "github:serokell/deploy-rs";
3138
deploy.inputs.nixpkgs.follows = "nixos";
@@ -55,6 +62,7 @@
5562
, agenix
5663
, nvfetcher
5764
, deploy
65+
, nixpkgs
5866
, ...
5967
} @ inputs:
6068
digga.lib.mkFlake
@@ -66,12 +74,11 @@
6674
channels = {
6775
nixos = {
6876
imports = [ (digga.lib.importOverlays ./overlays) ];
69-
overlays = [
70-
nur.overlay
71-
agenix.overlay
72-
nvfetcher.overlay
73-
./pkgs/default.nix
74-
];
77+
overlays = [ ];
78+
};
79+
nixpkgs-darwin-stable = {
80+
imports = [ (digga.lib.importOverlays ./overlays) ];
81+
overlays = [ ];
7582
};
7683
latest = { };
7784
};
@@ -85,6 +92,12 @@
8592
our = self.lib;
8693
});
8794
})
95+
96+
nur.overlay
97+
agenix.overlay
98+
nvfetcher.overlay
99+
100+
(import ./pkgs)
88101
];
89102

90103
nixos = {
@@ -102,17 +115,45 @@
102115
];
103116
};
104117

105-
imports = [ (digga.lib.importHosts ./hosts) ];
118+
imports = [ (digga.lib.importHosts ./hosts/nixos) ];
106119
hosts = {
107-
/* set host specific properties here */
120+
/* set host-specific properties here */
108121
NixOS = { };
109122
};
110123
importables = rec {
111124
profiles = digga.lib.rakeLeaves ./profiles // {
112125
users = digga.lib.rakeLeaves ./users;
113126
};
114127
suites = with profiles; rec {
115-
base = [ core users.nixos users.root ];
128+
base = [ core.nixos users.nixos users.root ];
129+
};
130+
};
131+
};
132+
133+
darwin = {
134+
hostDefaults = {
135+
system = "x86_64-darwin";
136+
channelName = "nixpkgs-darwin-stable";
137+
imports = [ (digga.lib.importExportableModules ./modules) ];
138+
modules = [
139+
{ lib.our = self.lib; }
140+
digga.darwinModules.nixConfig
141+
home.darwinModules.home-manager
142+
agenix.nixosModules.age
143+
];
144+
};
145+
146+
imports = [ (digga.lib.importHosts ./hosts/darwin) ];
147+
hosts = {
148+
/* set host-specific properties here */
149+
Mac = { };
150+
};
151+
importables = rec {
152+
profiles = digga.lib.rakeLeaves ./profiles // {
153+
users = digga.lib.rakeLeaves ./users;
154+
};
155+
suites = with profiles; rec {
156+
base = [ core.darwin users.darwin ];
116157
};
117158
};
118159
};
@@ -127,13 +168,34 @@
127168
};
128169
};
129170
users = {
171+
# TODO: does this naming convention still make sense with darwin support?
172+
#
173+
# - it doesn't make sense to make a 'nixos' user available on
174+
# darwin, and vice versa
175+
#
176+
# - the 'nixos' user might have special significance as the default
177+
# user for fresh systems
178+
#
179+
# - perhaps a system-agnostic home-manager user is more appropriate?
180+
# something like 'primaryuser'?
181+
#
182+
# all that said, these only exist within the `hmUsers` attrset, so
183+
# it could just be left to the developer to determine what's
184+
# appropriate. after all, configuring these hm users is one of the
185+
# first steps in customizing the template.
130186
nixos = { suites, ... }: { imports = suites.base; };
187+
darwin = { suites, ... }: { imports = suites.base; };
131188
}; # digga.lib.importers.rakeLeaves ./users/hm;
132189
};
133190

134191
devshell = ./shell;
135192

136-
homeConfigurations = digga.lib.mkHomeConfigurations self.nixosConfigurations;
193+
# TODO: similar to the above note: does it make sense to make all of
194+
# these users available on all systems?
195+
homeConfigurations = digga.lib.mergeAny
196+
(digga.lib.mkHomeConfigurations self.darwinConfigurations)
197+
(digga.lib.mkHomeConfigurations self.nixosConfigurations)
198+
;
137199

138200
deploy.nodes = digga.lib.mkDeployNodes self.nixosConfigurations { };
139201

examples/devos/hosts/darwin/Mac.nix

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{ config, pkgs, suites, ... }:
2+
3+
{
4+
imports = with suites;
5+
base;
6+
}
File renamed without changes.

examples/devos/hosts/bootstrap.nix examples/devos/hosts/nixos/bootstrap.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# interface that has the local link to the target machine
77
imports = [
88
# profiles.networking
9-
profiles.core
9+
profiles.core.nixos
1010
profiles.users.root # make sure to configure ssh keys
1111
profiles.users.nixos
1212
];

0 commit comments

Comments
 (0)