Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for macOS #45

Merged
merged 44 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
880b5b9
split hosts by nixos/darwin to accomodate new mode
kalbasit Aug 8, 2021
d850549
construct the hosts based on their mode
kalbasit Aug 9, 2021
27f66d3
remove mode out of host attributes passed over to flake-utils-plus
kalbasit Aug 9, 2021
a4633e7
send down mode as a special arg
kalbasit Aug 9, 2021
2da7382
fix tmux inclusion
kalbasit Aug 9, 2021
f676629
fix zsh inclusion
kalbasit Aug 9, 2021
7a373e4
make sure modules are included
kalbasit Aug 9, 2021
c6d299b
fix keybase inclusion
kalbasit Aug 9, 2021
7998641
forgot host.modules
kalbasit Aug 9, 2021
ecca320
add default output and builder for darwin
kalbasit Aug 10, 2021
b7c35d6
add todo
kalbasit Aug 11, 2021
6d74cad
darwin hosts should include darwinModule
kalbasit Aug 11, 2021
007ea9d
add some R&D to the keyboard setting
kalbasit Aug 11, 2021
9bcb0db
import saneFlakeDefaults from flake-utils-plus
kalbasit Aug 11, 2021
c03aead
do we really need this?
kalbasit Aug 11, 2021
a5c3b61
remove dead code
kalbasit Aug 14, 2021
d3b54c8
tmux.secureSocket only on Linux
kalbasit Aug 14, 2021
bf4e0ad
the host specialArgs should come after the hardcoded ones
kalbasit Aug 18, 2021
1f8b502
update the template
kalbasit Aug 18, 2021
d2d3809
remove the host script I will incude it later in a documentation pull…
kalbasit Aug 18, 2021
733505d
add darwin home
kalbasit Aug 18, 2021
0642cfe
remove unused hostname variable
kalbasit Aug 18, 2021
725e7ec
add more stuff
kalbasit Aug 18, 2021
1b11e63
put the merge on the next line
kalbasit Aug 18, 2021
21897e8
enable verbose mode
kalbasit Aug 18, 2021
6758b1e
Revert "enable verbose mode"
kalbasit Aug 18, 2021
ca3f7a9
enable zsh on nix-darwin
kalbasit Aug 18, 2021
63c8815
forward plugins to nix-darwin
kalbasit Aug 18, 2021
ed2b9ec
organise them for easier reading
kalbasit Aug 18, 2021
7dedfd3
Merge remote-tracking branch 'origin/main' into personal/soxin/suppor…
kalbasit Mar 20, 2022
5926932
wip
kalbasit Mar 29, 2022
f97a53d
fix the location of modules
kalbasit Mar 29, 2022
bfbcd86
fix
kalbasit Mar 31, 2022
3c4db9b
add missing sops module
kalbasit Mar 31, 2022
29da32f
wip
kalbasit Apr 5, 2022
d0c0c88
Merge remote-tracking branch 'origin/main' into personal/soxin/suppor…
kalbasit May 28, 2022
14c744d
Update flake.nix
kalbasit May 30, 2022
49c37c3
fix the M1 only issue
kalbasit May 31, 2022
2430f9e
Merge branch 'main' into personal/soxin/support-mac
kalbasit Aug 27, 2023
ad882ec
remove stuff coming from git conflict resolve
kalbasit Aug 30, 2023
74354cf
revert starship changes, not needed anymore
kalbasit Aug 30, 2023
430c517
fix the template build
kalbasit Aug 30, 2023
e7f94bd
enable zsh and set system state version
kalbasit Aug 30, 2023
75cc555
fmt tree
kalbasit Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions flake.lock

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

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
description = "soxin: opiniated configs for everyone";

inputs = {
darwin.url = "github:lnl7/nix-darwin/master";
deploy-rs.url = "github:serokell/deploy-rs";
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.1.0";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs";
nur.url = "github:nix-community/NUR";
sops-nix.url = "github:Mic92/sops-nix";

darwin.inputs.nixpkgs.follows = "nixpkgs";

home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
251 changes: 190 additions & 61 deletions lib/system-flake.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ deploy-rs
{ darwin
, deploy-rs
, home-manager
, flake-utils-plus
, nixpkgs
Expand Down Expand Up @@ -34,6 +35,9 @@
# NixOS specific modules.
, extraNixosModules ? [ ]

# nix-darwin specific modules.
, extraNixDarwinModules ? [ ]

# The global extra arguments are included in both NixOS and home-manager.
, globalSpecialArgs ? { }

Expand All @@ -43,6 +47,9 @@
# NixOS specific extra arguments.
, nixosSpecialArgs ? { }

# nix-darwin specific extra arguments.
, nixDarwinSpecialArgs ? { }

# Evaluates to `packages.<system>.<pname> = <unstable-channel-reference>.<pname>`.
, packagesBuilder ? (_: { })

Expand All @@ -59,8 +66,18 @@ let
soxincfg = inputs.self;

inherit (nixpkgs) lib;
inherit (lib) asserts filterAttrs mapAttrs optionalAttrs optionals recursiveUpdate singleton;
inherit (builtins) removeAttrs;
inherit (lib)
asserts
filterAttrs
mapAttrs
mkOption
optionalAttrs
optionals
recursiveUpdate
singleton
types
;

otherArguments = removeAttrs args [
"self"
Expand All @@ -72,43 +89,192 @@ let
"extraGlobalModules"
"extraHomeManagerModules"
"extraNixosModules"
"extraNixDarwinModules"
"globalSpecialArgs"
"hmSpecialArgs"
"nixosSpecialArgs"
"nixDarwinSpecialArgs"
"packagesBuilder"
"sharedOverlays"
];

# generate each host by injecting special arguments and the given host
# without certain soxin-only attributes.
hosts' =
mapAttrs
(hostname: host: (recursiveUpdate
{
specialArgs = {
inherit soxin soxincfg home-manager;

# the mode allows us to tell at what level we are within the modules.
mode = "NixOS";
}
# include the global special arguments.
// globalSpecialArgs
# include the NixOS special arguments.
// nixosSpecialArgs;
}

# pass along the hosts minus the deploy key that's specific to soxin.
(removeAttrs host [ "deploy" ])
))
hosts;
let
darwinHosts =
let
darwinOnlyHosts = filterAttrs (n: host: host.mode == "nix-darwin") hosts;

# Build host with darwinSystem. `removeAttrs` workaround due to https://github.com/LnL7/nix-darwin/issues/319
builder = args: darwin.lib.darwinSystem (builtins.removeAttrs args [ "system" ]);

# Setup the output
output = "darwinConfigurations";
in
mapAttrs
(_: host:
# setup the default attributes, users can override it by passing them through their host definition.
{ inherit builder output; }
//
(recursiveUpdate
# pass along the hosts minus few keys that are implementation detail to soxin.
(removeAttrs host [ "deploy" "mode" ])

{
specialArgs =
{
inherit
home-manager
soxin
soxincfg
;

inherit (host)
mode
;
}
# include the specialArgs that were passed in.
// (host.specialArgs or { })
# include the global special arguments.
// globalSpecialArgs
# include the NixDarwin special arguments.
// nixDarwinSpecialArgs
;

modules =
(host.modules or [ ])
# include sops
# ++ (optionals withSops (singleton sops-nix.nixosModules.sops))
# TODO: include sops above, or remove if unsupported.
# include sane flake defaults from flake-utils-plus which sets sane `nix.*` defaults.
# Please refer to implementation/readme in
# github:gytis-ivaskevicius/flake-utils-plus for more details.
#
++ (singleton flake-utils-plus.nixosModules.saneFlakeDefaults)
# include the nix-darwin modules
++ extraNixDarwinModules
# include Soxin modules
++ (singleton soxin.nixosModule)
# include home-manager modules
++ (singleton home-manager.darwinModules.home-manager)
# configure home-manager
++ (singleton {
# tell home-manager to use the global (as in NixOS system-level) pkgs and
# install all user packages through the users.users.<name>.packages.
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

home-manager.extraSpecialArgs = {
inherit soxin soxincfg home-manager;

# the mode allows us to tell at what level we are within the modules.
mode = "home-manager";
}
# include the global special arguments.
// globalSpecialArgs
# include the home-manager special arguments.
// hmSpecialArgs;

home-manager.sharedModules =
# include the global modules
extraGlobalModules
# include the home-manager modules
++ extraHomeManagerModules
# include Soxin module
++ (singleton soxin.nixosModule);
})
;
}
))
darwinOnlyHosts;

nixosHosts =
let
nixosOnlyHosts = filterAttrs (n: host: host.mode == "NixOS") hosts;
in
mapAttrs
(_: host: (recursiveUpdate
# pass along the hosts minus few keys that are implementation detail to soxin.
(removeAttrs host [ "deploy" "mode" ])

{
specialArgs =
{
inherit
home-manager
soxin
soxincfg
;

inherit (host)
mode
;
}
# include the specialArgs that were passed in.
// (host.specialArgs or { })
# include the global special arguments.
// globalSpecialArgs
# include the NixOS special arguments.
// nixosSpecialArgs
;

modules =
(host.modules or [ ])
# include sops
++ (optionals withSops (singleton sops-nix.nixosModules.sops))
# include sane flake defaults from flake-utils-plus which sets sane `nix.*` defaults.
# Please refer to implementation/readme in
# github:gytis-ivaskevicius/flake-utils-plus for more details.
++ (singleton flake-utils-plus.nixosModules.saneFlakeDefaults)
# include the NixOS modules
++ extraNixosModules
# include Soxin modules
++ (singleton soxin.nixosModule)
# include home-manager modules
++ (singleton home-manager.nixosModules.home-manager)
rissson marked this conversation as resolved.
Show resolved Hide resolved
# configure home-manager
++ (singleton {
# tell home-manager to use the global (as in NixOS system-level) pkgs and
# install all user packages through the users.users.<name>.packages.
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

home-manager.extraSpecialArgs = {
inherit soxin soxincfg home-manager;

# the mode allows us to tell at what level we are within the modules.
mode = "home-manager";
}
# include the global special arguments.
// globalSpecialArgs
# include the home-manager special arguments.
// hmSpecialArgs;

home-manager.sharedModules =
# include the global modules
extraGlobalModules
# include the home-manager modules
++ extraHomeManagerModules
# include Soxin module
++ (singleton soxin.nixosModule);
})
;
}
))
nixosOnlyHosts;

# TODO: add support for home-manager modes
in
darwinHosts // nixosHosts;

# Generate the deployment nodes.
deploy.nodes =
let
# filter out hosts without a deploy attribute.
deploy-hosts = filterAttrs (n: v: (v.deploy or { }) != { }) hosts;
in
mapAttrs (hostname: host: host.deploy) deploy-hosts;
mapAttrs (_: host: host.deploy) deploy-hosts;

soxinSystemFlake = {
# inherit the required fields as-is
Expand Down Expand Up @@ -198,46 +364,9 @@ let
modules =
# include the modules that are passed in
(hostDefaults.modules or [ ])
# include sops
++ (optionals withSops (singleton sops-nix.nixosModules.sops))
# include the global modules
++ extraGlobalModules
# include sane flake defaults from flake-utils-plus which sets sane `nix.*` defaults.
# Please refer to implementation/readme in
# github:gytis-ivaskevicius/flake-utils-plus for more details.
++ (singleton flake-utils-plus.nixosModules.saneFlakeDefaults)
# include the NixOS modules
++ extraNixosModules
# include Soxin modules
++ (singleton soxin.nixosModule)
# include home-manager modules
++ (singleton home-manager.nixosModules.home-manager)
# configure home-manager
++ (singleton {
# tell home-manager to use the global (as in NixOS system-level) pkgs and
# install all user packages through the users.users.<name>.packages.
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

home-manager.extraSpecialArgs = {
inherit soxin soxincfg home-manager;

# the mode allows us to tell at what level we are within the modules.
mode = "home-manager";
}
# include the global special arguments.
// globalSpecialArgs
# include the home-manager special arguments.
// hmSpecialArgs;

home-manager.sharedModules =
# include the global modules
extraGlobalModules
# include the home-manager modules
++ extraHomeManagerModules
# include Soxin module
++ (singleton soxin.nixosModule);
});
;
};
}
// (optionalAttrs withDeploy {
Expand All @@ -256,7 +385,7 @@ flake-utils-plus.lib.systemFlake (recursiveUpdate soxinSystemFlake otherArgument
# TODO: Let flake-utils-plus.lib.systemFlake handle the home-managers by using the host's builder function
// {
homeConfigurations = (mapAttrs
(hostname: host: soxin.lib.homeManagerConfiguration (host // {
(_: host: soxin.lib.homeManagerConfiguration (host // {
inherit inputs;
hmModules =
# include the global modules
Expand Down
4 changes: 2 additions & 2 deletions modules/programs/keybase/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ in
};

config = mkIf cfg.enable (mkMerge [
{
(optionalAttrs (mode == "NixOS" || mode == "home-manager") {
services.keybase.enable = true;
services.kbfs.enable = cfg.enableFs;
}
})
]);
}
Loading