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 38 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.

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

inputs = {
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs.url = "github:serokell/deploy-rs";
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
Expand Down
150 changes: 118 additions & 32 deletions lib/mk-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 Down Expand Up @@ -98,9 +105,11 @@ let
"extraGlobalModules"
"extraHomeManagerModules"
"extraNixosModules"
"extraNixDarwinModules"
"globalSpecialArgs"
"hmSpecialArgs"
"nixosSpecialArgs"
"nixDarwinSpecialArgs"
"packagesBuilder"
"devShellBuilder"
"sharedOverlays"
Expand All @@ -109,33 +118,113 @@ let
# 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.
builder = args: darwin.lib.darwinSystem args;

# 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" "modules" ])

{
modules = [ ]
# include modules for the host
++ (host.modules or [ ])
# include the NixOS modules
++ extraNixDarwinModules
# include home-manager modules
++ (singleton home-manager.darwinModules.home-manager)
;
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
;
}
))
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" ])

{
modules = [ ]
# include modules for the host
++ (host.modules or [ ])
# include the NixOS modules
++ extraNixosModules
# include sops
++ (optionals withSops (singleton sops-nix.nixosModules.sops))
# include home-manager modules
++ (singleton home-manager.nixosModules.home-manager)
;

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
;
}
))
nixosOnlyHosts;

# TODO: add support for home-manager modes
in
darwinHosts // nixosHosts;
rissson marked this conversation as resolved.
Show resolved Hide resolved

# 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 @@ -235,22 +324,17 @@ 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 the NixOS modules
++ extraNixosModules
# include Soxin modules
++ (singleton soxin.nixosModule)
# include home-manager modules
++ (singleton home-manager.nixosModules.home-manager)
# configure fup to expose NIX_PATH and Nix registry from inputs.
++ (singleton { nix = { inherit generateNixPathFromInputs generateRegistryFromInputs linkInputs; }; })
# 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.
# tell home-manager to use the global (as in NixOS/Nix-Darwin
# system-level) pkgs and install all user packages through the
# users.users.<name>.packages.
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
rissson marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -263,15 +347,17 @@ let
# include the global special arguments.
// globalSpecialArgs
# include the home-manager special arguments.
// hmSpecialArgs;
// hmSpecialArgs
;

home-manager.sharedModules =
# include the global modules
extraGlobalModules
# include the home-manager modules
++ extraHomeManagerModules
# include Soxin module
++ (singleton soxin.nixosModule);
++ (singleton soxin.nixosModule)
;
});
};
}
Expand All @@ -291,7 +377,7 @@ flake-utils-plus.lib.mkFlake (recursiveUpdate soxinSystemFlake otherArguments)
# TODO: Let flake-utils-plus.lib.mkFlake 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
19 changes: 15 additions & 4 deletions modules/programs/keybase/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{ mode, config, pkgs, lib, ... }:

with lib;
let
cfg = config.soxin.programs.keybase;

inherit (lib)
mkEnableOption
mkIf
mkMerge
optionalAttrs
recursiveUpdate
;

inherit (pkgs.hostPlatform)
isLinux
;
in
{
options = {
Expand All @@ -11,14 +22,14 @@ in
enableFs =
recursiveUpdate
(mkEnableOption "Keybase filesystem")
{ default = true; };
{ default = isLinux; };
};
};

config = mkIf cfg.enable (mkMerge [
{
(optionalAttrs (mode == "NixOS" || mode == "home-manager") {
services.keybase.enable = true;
services.kbfs.enable = cfg.enableFs;
}
})
]);
}
38 changes: 33 additions & 5 deletions modules/programs/starship/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{ mode, config, pkgs, lib, ... }:

with lib;
let
cfg = config.soxin.programs.starship;

inherit (lib)
mkEnableOption
mkAfter
mkIf
mkMerge
optionalAttrs
;

inherit (pkgs.hostPlatform)
isDarwin
;
in
{
options = {
Expand All @@ -21,10 +32,27 @@ in
})

(optionalAttrs (mode == "home-manager") {
programs.starship = {
enable = true;
enableZshIntegration = config.soxin.programs.zsh.enable;
};
programs.starship = mkMerge [
{
enable = true;
enableZshIntegration = config.soxin.programs.zsh.enable;
}

(mkIf (isDarwin && pkgs.system == "aarch64-darwin") {
package = pkgs.writeShellScriptBin "starship" ''
set -euo pipefail

readonly real_path=/opt/homebrew/bin/starship

if [[ ! -x $real_path ]]; then
>&2 echo "Installing starship, please wait."
brew install starship
fi

exec $real_path "$@"
'';
})
];
})
]);
}
6 changes: 4 additions & 2 deletions modules/programs/tmux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ in

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

config = mkIf cfg.enable (mkMerge [
# add all plugins installed by themes
{ soxin.programs.tmux.plugins = cfg.theme.plugins; }
(optionalAttrs (mode == "NixOS" || mode == "home-manager") {
soxin.programs.tmux.plugins = cfg.theme.plugins;
rissson marked this conversation as resolved.
Show resolved Hide resolved
})

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