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 darwin support #43

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

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

9 changes: 8 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
futils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, home-manager, futils } @ inputs:
outputs = { self, nixpkgs, darwin, home-manager, futils } @ inputs:
let
inherit (nixpkgs) lib;
inherit (lib) recursiveUpdate;
Expand Down Expand Up @@ -42,6 +46,9 @@

nixosModules = (import ./modules) // { soxin = import ./modules/soxin.nix; };
nixosModule = self.nixosModules.soxin;
/* For now they are the same. */
darwinModules = self.nixosModules;
darwinModule = self.darwinModules.soxin;

defaultTemplate = {
path = ./template;
Expand Down
93 changes: 93 additions & 0 deletions lib/darwin-system.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{ self, lib, darwin, home-manager }:

with lib;

{
# The global modules are included in both Darwin and home-manager.
globalModules ? [ ]

# Darwin specific modules.
, darwinModules ? [ ]

# Home-manager specific modules.
, hmModules ? [ ]

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

# Darwin specific extra arguments.
, darwinSpecialArgs ? { }

# Home-manager specific extra arguments.
, hmSpecialArgs ? { }

, ...
} @ args:
let
args' = removeAttrs args [
"globalModules"
"darwinModules"
"hmModules"

"globalSpecialArgs"
"darwinSpecialArgs"
"hmSpecialArgs"
];
in
darwin.lib.darwinSystem (recursiveUpdate args' {
specialArgs = {
# send home-manager down to the Darwin modules
inherit home-manager;

# the mode allows us to tell at what level we are within the modules.
mode = "Darwin";

# send soxin down to NixOS.
soxin = self;
}
# include the global special arguments.
// globalSpecialArgs
# include the NixOS special arguments.
// darwinSpecialArgs;

modules =
# include the global modules
globalModules
# include the Darwin modules
++ darwinModules
# include Soxin modules
++ (singleton self.darwinModule)
# include home-manager modules
++ (singleton home-manager.darwinModules.home-manager)
# configure Nix registry so users can find soxin
++ singleton { nix.registry.soxin.flake = self; }
# configure home-manager
++ (singleton {
# tell home-manager to use the global (as in Darwin 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 = {
# send home-manager down to the home-manager modules
inherit home-manager;

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

home-manager.sharedModules =
# include the global modules
globalModules
# include the home-manager modules
++ hmModules
# include Soxin module
++ (singleton self.nixosModule);
});
})
3 changes: 2 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib, self, home-manager, ... }:
{ lib, self, darwin, home-manager, ... }:

rec {
darwinSystem = import ./darwin-system.nix { inherit self lib darwin home-manager; };
homeManagerConfiguration = import ./home-manager-configuration.nix { inherit self lib home-manager; };
mkSoxinModule = import ./mk-soxin-module.nix { inherit lib modules; };
modules = import ./modules { inherit lib; };
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;
}
})
]);
}