Skip to content

Commit 60c6117

Browse files
kalbasitrissson
andauthored
Add support for macOS (#45)
Co-authored-by: risson <[email protected]>
1 parent 81239e3 commit 60c6117

File tree

21 files changed

+372
-93
lines changed

21 files changed

+372
-93
lines changed

flake.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
description = "soxin: opiniated configs for everyone";
33

44
inputs = {
5+
darwin = {
6+
url = "github:lnl7/nix-darwin/master";
7+
inputs.nixpkgs.follows = "nixpkgs";
8+
};
59
deploy-rs.url = "github:serokell/deploy-rs";
610
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1";
711
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";

lib/home-manager-configuration.nix

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ let
3939

4040
in
4141
home-manager.lib.homeManagerConfiguration (recursiveUpdate
42-
{
43-
extraSpecialArgs = {
44-
inherit inputs soxin soxincfg;
45-
46-
mode = "home-manager";
47-
}
48-
# include the home-manager special arguments.
49-
// hmSpecialArgs;
50-
51-
extraModules =
52-
# include the home-manager modules
53-
hmModules
54-
# include Soxin module
55-
++ (singleton soxin.nixosModules.soxin)
56-
# include SoxinCFG module
57-
++ (singleton soxincfg.nixosModules.soxincfg);
42+
{
43+
extraSpecialArgs = {
44+
inherit inputs soxin soxincfg;
45+
46+
mode = "home-manager";
5847
}
48+
# include the home-manager special arguments.
49+
// hmSpecialArgs;
50+
51+
extraModules =
52+
# include the home-manager modules
53+
hmModules
54+
# include Soxin module
55+
++ (singleton soxin.nixosModules.soxin)
56+
# include SoxinCFG module
57+
++ (singleton soxincfg.nixosModules.soxincfg);
58+
}
5959
otherArguments)

lib/mk-flake.nix

Lines changed: 118 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{ deploy-rs
1+
{ darwin
2+
, deploy-rs
23
, home-manager
34
, flake-utils-plus
45
, nixpkgs
@@ -34,6 +35,9 @@
3435
# NixOS specific modules.
3536
, extraNixosModules ? [ ]
3637

38+
# nix-darwin specific modules.
39+
, extraNixDarwinModules ? [ ]
40+
3741
# The global extra arguments are included in both NixOS and home-manager.
3842
, globalSpecialArgs ? { }
3943

@@ -43,6 +47,9 @@
4347
# NixOS specific extra arguments.
4448
, nixosSpecialArgs ? { }
4549

50+
# nix-darwin specific extra arguments.
51+
, nixDarwinSpecialArgs ? { }
52+
4653
# Shared overlays between channels, gets applied to all `channels.<name>.input`
4754
, sharedOverlays ? [ ]
4855

@@ -95,43 +102,125 @@ let
95102
"extraGlobalModules"
96103
"extraHomeManagerModules"
97104
"extraNixosModules"
105+
"extraNixDarwinModules"
98106
"globalSpecialArgs"
99107
"hmSpecialArgs"
100108
"nixosSpecialArgs"
109+
"nixDarwinSpecialArgs"
101110
"outputsBuilder"
102111
"sharedOverlays"
103112
];
104113

105114
# generate each host by injecting special arguments and the given host
106115
# without certain soxin-only attributes.
107116
hosts' =
108-
mapAttrs
109-
(hostname: host: (recursiveUpdate
110-
{
111-
specialArgs = {
112-
inherit soxin soxincfg home-manager;
113-
114-
# the mode allows us to tell at what level we are within the modules.
115-
mode = "NixOS";
116-
}
117-
# include the global special arguments.
118-
// globalSpecialArgs
119-
# include the NixOS special arguments.
120-
// nixosSpecialArgs;
121-
}
122-
123-
# pass along the hosts minus the deploy key that's specific to soxin.
124-
(removeAttrs host [ "deploy" ])
125-
))
126-
hosts;
117+
let
118+
darwinHosts =
119+
let
120+
darwinOnlyHosts = filterAttrs (n: host: host.mode == "nix-darwin") hosts;
121+
122+
# Build host with darwinSystem.
123+
builder = args: darwin.lib.darwinSystem args;
124+
125+
# Setup the output
126+
output = "darwinConfigurations";
127+
in
128+
mapAttrs
129+
(_: host:
130+
# setup the default attributes, users can override it by passing them through their host definition.
131+
{ inherit builder output; }
132+
//
133+
(recursiveUpdate
134+
# pass along the hosts minus few keys that are implementation detail to soxin.
135+
(removeAttrs host [ "deploy" "mode" "modules" ])
136+
137+
{
138+
modules = [ ]
139+
# include modules for the host
140+
++ (host.modules or [ ])
141+
# include the NixOS modules
142+
++ extraNixDarwinModules
143+
# include home-manager modules
144+
++ (singleton home-manager.darwinModules.home-manager)
145+
;
146+
specialArgs =
147+
{
148+
inherit
149+
home-manager
150+
soxin
151+
soxincfg
152+
;
153+
154+
inherit (host)
155+
mode
156+
;
157+
}
158+
# include the specialArgs that were passed in.
159+
// (host.specialArgs or { })
160+
# include the global special arguments.
161+
// globalSpecialArgs
162+
# include the NixDarwin special arguments.
163+
// nixDarwinSpecialArgs
164+
;
165+
}
166+
))
167+
darwinOnlyHosts;
168+
169+
nixosHosts =
170+
let
171+
nixosOnlyHosts = filterAttrs (n: host: host.mode == "NixOS") hosts;
172+
in
173+
mapAttrs
174+
(_: host: (recursiveUpdate
175+
# pass along the hosts minus few keys that are implementation detail to soxin.
176+
(removeAttrs host [ "deploy" "mode" ])
177+
178+
{
179+
modules = [ ]
180+
# include modules for the host
181+
++ (host.modules or [ ])
182+
# include the NixOS modules
183+
++ extraNixosModules
184+
# include sops
185+
++ (optionals withSops (singleton sops-nix.nixosModules.sops))
186+
# include home-manager modules
187+
++ (singleton home-manager.nixosModules.home-manager)
188+
;
189+
190+
specialArgs =
191+
{
192+
inherit
193+
home-manager
194+
soxin
195+
soxincfg
196+
;
197+
198+
inherit (host)
199+
mode
200+
;
201+
}
202+
# include the specialArgs that were passed in.
203+
// (host.specialArgs or { })
204+
# include the global special arguments.
205+
// globalSpecialArgs
206+
# include the NixOS special arguments.
207+
// nixosSpecialArgs
208+
;
209+
}
210+
))
211+
nixosOnlyHosts;
212+
213+
# TODO: add support for home-manager modes
214+
in
215+
darwinHosts // nixosHosts;
127216

128217
# Generate the deployment nodes.
129218
deploy.nodes =
130219
let
131220
# filter out hosts without a deploy attribute.
132221
deploy-hosts = filterAttrs (n: v: (v.deploy or { }) != { }) hosts;
133222
in
134-
mapAttrs (hostname: host: host.deploy) deploy-hosts;
223+
mapAttrs (_: host: host.deploy) deploy-hosts;
135224

136225
soxinSystemFlake = {
137226
# inherit the required fields as-is
@@ -236,22 +325,17 @@ let
236325
modules =
237326
# include the modules that are passed in
238327
(hostDefaults.modules or [ ])
239-
# include sops
240-
++ (optionals withSops (singleton sops-nix.nixosModules.sops))
241328
# include the global modules
242329
++ extraGlobalModules
243-
# include the NixOS modules
244-
++ extraNixosModules
245330
# include Soxin modules
246331
++ (singleton soxin.nixosModule)
247-
# include home-manager modules
248-
++ (singleton home-manager.nixosModules.home-manager)
249332
# configure fup to expose NIX_PATH and Nix registry from inputs.
250333
++ (singleton { nix = { inherit generateNixPathFromInputs generateRegistryFromInputs linkInputs; }; })
251334
# configure home-manager
252335
++ (singleton {
253-
# tell home-manager to use the global (as in NixOS system-level) pkgs and
254-
# install all user packages through the users.users.<name>.packages.
336+
# tell home-manager to use the global (as in NixOS/Nix-Darwin
337+
# system-level) pkgs and install all user packages through the
338+
# users.users.<name>.packages.
255339
home-manager.useGlobalPkgs = true;
256340
home-manager.useUserPackages = true;
257341

@@ -264,15 +348,17 @@ let
264348
# include the global special arguments.
265349
// globalSpecialArgs
266350
# include the home-manager special arguments.
267-
// hmSpecialArgs;
351+
// hmSpecialArgs
352+
;
268353

269354
home-manager.sharedModules =
270355
# include the global modules
271356
extraGlobalModules
272357
# include the home-manager modules
273358
++ extraHomeManagerModules
274359
# include Soxin module
275-
++ (singleton soxin.nixosModule);
360+
++ (singleton soxin.nixosModule)
361+
;
276362
});
277363
};
278364
}
@@ -292,7 +378,7 @@ flake-utils-plus.lib.mkFlake (recursiveUpdate soxinSystemFlake otherArguments)
292378
# TODO: Let flake-utils-plus.lib.mkFlake handle the home-managers by using the host's builder function
293379
// {
294380
homeConfigurations = (mapAttrs
295-
(hostname: host: soxin.lib.homeManagerConfiguration (host // {
381+
(_: host: soxin.lib.homeManagerConfiguration (host // {
296382
inherit inputs;
297383
hmModules =
298384
# include the global modules

modules/programs/keybase/default.nix

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
{ mode, config, pkgs, lib, ... }:
22

3-
with lib;
43
let
54
cfg = config.soxin.programs.keybase;
5+
6+
inherit (lib)
7+
mkEnableOption
8+
mkIf
9+
mkMerge
10+
optionalAttrs
11+
recursiveUpdate
12+
;
13+
14+
inherit (pkgs.hostPlatform)
15+
isLinux
16+
;
617
in
718
{
819
options = {
@@ -11,14 +22,14 @@ in
1122
enableFs =
1223
recursiveUpdate
1324
(mkEnableOption "Keybase filesystem")
14-
{ default = true; };
25+
{ default = isLinux; };
1526
};
1627
};
1728

1829
config = mkIf cfg.enable (mkMerge [
19-
{
30+
(optionalAttrs (mode == "NixOS" || mode == "home-manager") {
2031
services.keybase.enable = true;
2132
services.kbfs.enable = cfg.enableFs;
22-
}
33+
})
2334
]);
2435
}

modules/programs/tmux/default.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ in
8686

8787
secureSocket = mkOption {
8888
type = types.bool;
89-
default = true;
89+
default = pkgs.stdenv.isLinux;
9090
description = ''
9191
Store tmux socket under <filename>/run</filename>, which is more
9292
secure than <filename>/tmp</filename>, but as a downside it doesn't
@@ -99,7 +99,9 @@ in
9999

100100
config = mkIf cfg.enable (mkMerge [
101101
# add all plugins installed by themes
102-
{ soxin.programs.tmux.plugins = cfg.theme.plugins; }
102+
(optionalAttrs (mode == "NixOS" || mode == "home-manager") {
103+
soxin.programs.tmux.plugins = cfg.theme.plugins;
104+
})
103105

104106
(optionalAttrs (mode == "NixOS") (mkMerge [
105107
{ programs.tmux = { inherit (cfg) enable extraConfig secureSocket; }; }

0 commit comments

Comments
 (0)