Skip to content

Commit

Permalink
feat(darwinProfiles): add homebrew
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 11, 2023
1 parent d238cab commit b83be2d
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 2 deletions.
1 change: 0 additions & 1 deletion docs/org/nixosProfiles.org
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
inputs,
}:
let
inherit (inputs) dmerge;
srvosCustom =
(omnibus.pops.srvos.addExporters [
(POP.extendPop flops.haumea.pops.exporter (
Expand Down
3 changes: 3 additions & 0 deletions lib/exporter/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ in
nixosModules = outputs.loadNixOSModules;
nixosProfiles = outputs.loadNixOSProfiles;

darwinModules = outputs.loadDarwinModules;
darwinProfiles = outputs.loadDarwinProfiles;

homeProfiles = outputs.loadHomeProfiles;
homeModules = outputs.loadHomeModules;
}
11 changes: 11 additions & 0 deletions lib/exporter/pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ in
type = "nixosProfiles";
};
};

loadDarwinProfiles = self.loadNixOSProfiles.addLoadExtender {
load = {
src = inputs.self.outPath + "/nixos/darwinProfiles";
};
};

loadDarwinModules = self.loadNixOSModules.addLoadExtender {
load.src = inputs.self.outPath + "/nixos/darwinModules";
};

srvos = flops.haumea.pops.default.setInit {
src = self.loadInputs.outputs.srvos + "/nixos";
type = "nixosProfiles";
Expand Down
2 changes: 2 additions & 0 deletions local/cells/repo/configs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ with inputs.std.inputs.dmerge; {
"nixosProfiles"
"homeProfiles"
"homeModules"
"darwinModules"
"darwinProfiles"
".*."
];
};
Expand Down
21 changes: 21 additions & 0 deletions local/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 local/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

inputs.std.follows = "std-ext/std";
inputs.nixpkgs.follows = "std-ext/nixpkgs";
inputs.darwin.url = "github:LnL7/nix-darwin";
inputs.darwin.inputs.nixpkgs.follows = "nixpkgs";

inputs.std-ext.url = "github:gtrunsec/std-ext";
inputs.std-ext.inputs.org-roam-book-template.follows = "";
inputs.call-flake.url = "github:divnix/call-flake";
Expand Down
84 changes: 84 additions & 0 deletions nixos/darwinModules/homebrew/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
let
casks = lib.subtractLists cfg.__profiles__.casks.removePackagesFromProfiles (
lib.optionals cfg.__profiles__.readers [
"koodo-reader"
"skim"
]
++ (lib.optionals cfg.__profiles__.shell [ "wez/wezterm/wezterm-nightly" ])
++ (lib.optionals cfg.__profiles__.chat [
"telegram-desktop"
"signal-desktop"
"element-desktop"
])
++ (lib.optionals cfg.__profiles__.security [ "secretive" ])
++ (lib.optionals cfg.__profiles__.containers [ "docker" ])
++ (lib.optionals cfg.__profiles__.chinese [ "squirrel" ])
++ (lib.optionals cfg.__profiles__.customization [ "bartender" ])
++ (lib.optionals cfg.__profiles__.fonts [
"font-fantasque-sans-mono"
"font-fontawesome"
])
);
brews = lib.subtractLists cfg.__profiles__.brews.removePackagesFromProfiles (
lib.optionals cfg.__profiles__.emacs [ "emacs-plus@29" ]
++ (lib.optionals cfg.__profiles__.fonts [
"fontconfig"
"rxvt-unicode"
])
);
in
{
options.__profiles__ = with lib; {
default = lib.mkOption {
type = types.bool;
default = true;
description = "Whether to enable default profile";
};
readers = mkEnableOption (lib.mdDoc "Whether to enable readers profile");
shell = mkEnableOption (lib.mdDoc "Whether to enable shell profile");
chat = mkEnableOption (lib.mdDoc "Whether to enable chat profile");
security = mkEnableOption (lib.mdDoc "Whether to enable security profile");
containers = mkEnableOption (lib.mdDoc "Whether to enable containers profile");
chinese = mkEnableOption (lib.mdDoc "Whether to enable chinese profile");
fonts = mkEnableOption (lib.mdDoc "Whether to enable fonts profile");
emacs = mkEnableOption (lib.mdDoc "Whether to enable emacs profile");
customization = mkEnableOption (
lib.mdDoc "Whether to enable customization profile"
);

casks = {
removePackagesFromProfiles = mkOption {
type = types.listOf types.str;
default = [ ];
description = "List of packages to remove from cask profiles";
};
};
brews = {
removePackagesFromProfiles = mkOption {
type = types.listOf types.str;
default = [ ];
description = "List of packages to remove from brew profiles";
};
};
};

config =
with lib;
mkMerge [
{ inherit casks brews; }
(mkIf cfg.__profiles__.default {
taps = [
"homebrew/bundle"
"homebrew/core"
];
})
(mkIf (cfg.casks != [ ]) {
taps = [
"homebrew/cask"
"homebrew/cask-versions"
];
})
(mkIf cfg.__profiles__.fonts { taps = [ "homebrew/cask-fonts" ]; })
(mkIf cfg.__profiles__.emacs { taps = [ "d12frosted/emacs-plus" ]; })
];
}
48 changes: 48 additions & 0 deletions nixos/darwinProfiles/presets/homebrew.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
omnibus,
pkgs,
lib,
}:
let
inherit (pkgs.stdenv.hostPlatform) isAarch64;
brewPrefix = if isAarch64 then "/opt/homebrew" else "/usr/local";
in
{
imports = [ omnibus.darwinModules.homebrew ];

# credit: https://github.com/montchr/dotfield/blob/dd5e577d91b1af7f13909f5dc4343717a718ff02/darwin/profiles/core/default.nix
homebrew = {
enable = true;
# onActivation.cleanup = "zap";
onActivation.upgrade = true;
# Use the nix-darwin brewfile when invoking `brew bundle` imperatively.
global.brewfile = true;
global.lockfiles = false;
__profiles__ = {
readers = true;
shell = true;
casks.removePackagesFromProfiles = [ ];
brews.removePackagesFromProfiles = [ ];
};
};
# <https://github.com/LnL7/nix-darwin/issues/596>
#
# $ brew shellenv
# export HOMEBREW_PREFIX="/opt/homebrew";
# export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
# export HOMEBREW_REPOSITORY="/opt/homebrew";
# export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
# export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
# export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";
environment.systemPath = lib.mkBefore [
"${brewPrefix}/bin"
"${brewPrefix}/sbin"
];
environment.variables = {
HOMEBREW_PREFIX = brewPrefix;
HOMEBREW_CELLAR = "${brewPrefix}/Cellar";
HOMEBREW_REPOSITORY = brewPrefix;
MANPATH = "${brewPrefix}/share/man:$MANPATH";
INFOPATH = "${brewPrefix}/share/info:$INFOPATH";
};
}
1 change: 0 additions & 1 deletion nixos/nixosProfiles/cloud.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
inputs,
}:
let
inherit (inputs) dmerge;
srvosCustom =
(omnibus.pops.srvos.addExporters [
(POP.extendPop flops.haumea.pops.exporter (
Expand Down
35 changes: 35 additions & 0 deletions tests/_snapshots/darwin
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pretty
{
darwinFontProfile = [
{
args = null;
brewfileLine = "cask \"koodo-reader\"";
greedy = null;
name = "koodo-reader";
}
{
args = null;
brewfileLine = "cask \"skim\"";
greedy = null;
name = "skim";
}
{
args = null;
brewfileLine = "cask \"wez/wezterm/wezterm-nightly\"";
greedy = null;
name = "wez/wezterm/wezterm-nightly";
}
{
args = null;
brewfileLine = "cask \"font-fantasque-sans-mono\"";
greedy = null;
name = "font-fantasque-sans-mono";
}
{
args = null;
brewfileLine = "cask \"font-fontawesome\"";
greedy = null;
name = "font-fontawesome";
}
];
}
18 changes: 18 additions & 0 deletions tests/darwin/expr.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
super,
trace,
lib,
root,
omnibus,
}:
let
exporter = root.nixos.pops.layouts.default;
in
{
darwinFontProfile =
(exporter.layouts.darwinConfiguration [
omnibus.darwinProfiles.presets.homebrew
{ homebrew.__profiles__.fonts = true; }
]).config.homebrew.casks;
}
// lib.optionalAttrs trace { }
1 change: 1 addition & 0 deletions tests/darwin/format.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"pretty"
7 changes: 7 additions & 0 deletions tests/nixos/__fixture/layouts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ in
module
];
};

darwinConfiguration =
module:
darwin.lib.darwinSystem {
system = "aarch64-darwin";
modules = lib.flatten [ module ];
};
}
1 change: 1 addition & 0 deletions tests/nixos/_pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
inputs = {
data = root.data;
nixpkgs = inputs'.nixpkgs;
darwin = inputs'.darwin;
};
};
})

0 comments on commit b83be2d

Please sign in to comment.