Skip to content

Commit

Permalink
Add support for macOS (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: risson <[email protected]>
  • Loading branch information
kalbasit and rissson authored Aug 30, 2023
1 parent 81239e3 commit 60c6117
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 93 deletions.
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
32 changes: 16 additions & 16 deletions lib/home-manager-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ let

in
home-manager.lib.homeManagerConfiguration (recursiveUpdate
{
extraSpecialArgs = {
inherit inputs soxin soxincfg;

mode = "home-manager";
}
# include the home-manager special arguments.
// hmSpecialArgs;

extraModules =
# include the home-manager modules
hmModules
# include Soxin module
++ (singleton soxin.nixosModules.soxin)
# include SoxinCFG module
++ (singleton soxincfg.nixosModules.soxincfg);
{
extraSpecialArgs = {
inherit inputs soxin soxincfg;

mode = "home-manager";
}
# include the home-manager special arguments.
// hmSpecialArgs;

extraModules =
# include the home-manager modules
hmModules
# include Soxin module
++ (singleton soxin.nixosModules.soxin)
# include SoxinCFG module
++ (singleton soxincfg.nixosModules.soxincfg);
}
otherArguments)
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 ? { }

# Shared overlays between channels, gets applied to all `channels.<name>.input`
, sharedOverlays ? [ ]

Expand Down Expand Up @@ -95,43 +102,125 @@ let
"extraGlobalModules"
"extraHomeManagerModules"
"extraNixosModules"
"extraNixDarwinModules"
"globalSpecialArgs"
"hmSpecialArgs"
"nixosSpecialArgs"
"nixDarwinSpecialArgs"
"outputsBuilder"
"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.
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;

# 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 @@ -236,22 +325,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;

Expand All @@ -264,15 +348,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 @@ -292,7 +378,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;
}
})
]);
}
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;
})

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

0 comments on commit 60c6117

Please sign in to comment.