First Try

This commit is contained in:
Olaf Kolkman
2025-05-06 19:41:26 +02:00
commit fbd41a72f1
58 changed files with 7011 additions and 0 deletions

11
modules/darwin/README.md Normal file
View File

@ -0,0 +1,11 @@
## Layout
```
.
├── dock # MacOS dock configuration
├── casks.nix # List of homebrew casks
├── default.nix # Defines module, system-level config
├── files.nix # Non-Nix, static configuration files (now immutable!)
├── home-manager.nix # Defines user programs
├── packages.nix # List of packages to install for MacOS
```

26
modules/darwin/casks.nix Normal file
View File

@ -0,0 +1,26 @@
_:
[
# Development Tools
"homebrew/cask/docker"
"visual-studio-code"
# Communication Tools
"discord"
"notion"
"slack"
"telegram"
"zoom"
# Utility Tools
"syncthing"
# Entertainment Tools
"vlc"
# Productivity Tools
"raycast"
# Browsers
"google-chrome"
]

View File

@ -0,0 +1,70 @@
{ config, pkgs, lib, ... }:
# Original source: https://gist.github.com/antifuchs/10138c4d838a63c0a05e725ccd7bccdd
with lib;
let
cfg = config.local.dock;
inherit (pkgs) stdenv dockutil;
in
{
options = {
local.dock.enable = mkOption {
description = "Enable dock";
default = stdenv.isDarwin;
example = false;
};
local.dock.entries = mkOption
{
description = "Entries on the Dock";
type = with types; listOf (submodule {
options = {
path = lib.mkOption { type = str; };
section = lib.mkOption {
type = str;
default = "apps";
};
options = lib.mkOption {
type = str;
default = "";
};
};
});
readOnly = true;
};
};
config =
mkIf cfg.enable
(
let
normalize = path: if hasSuffix ".app" path then path + "/" else path;
entryURI = path: "file://" + (builtins.replaceStrings
[" " "!" "\"" "#" "$" "%" "&" "'" "(" ")"]
["%20" "%21" "%22" "%23" "%24" "%25" "%26" "%27" "%28" "%29"]
(normalize path)
);
wantURIs = concatMapStrings
(entry: "${entryURI entry.path}\n")
cfg.entries;
createEntries = concatMapStrings
(entry: "${dockutil}/bin/dockutil --no-restart --add '${entry.path}' --section ${entry.section} ${entry.options}\n")
cfg.entries;
in
{
system.activationScripts.postUserActivation.text = ''
echo >&2 "Setting up the Dock..."
haveURIs="$(${dockutil}/bin/dockutil --list | ${pkgs.coreutils}/bin/cut -f2)"
if ! diff -wu <(echo -n "$haveURIs") <(echo -n '${wantURIs}') >&2 ; then
echo >&2 "Resetting Dock."
${dockutil}/bin/dockutil --no-restart --remove all
${createEntries}
killall Dock
else
echo >&2 "Dock setup complete."
fi
'';
}
);
}

34
modules/darwin/files.nix Normal file
View File

@ -0,0 +1,34 @@
{ user, config, pkgs, ... }:
let
xdg_configHome = "${config.users.users.${user}.home}/.config";
xdg_dataHome = "${config.users.users.${user}.home}/.local/share";
xdg_stateHome = "${config.users.users.${user}.home}/.local/state"; in
{
# Raycast script so that "Run Emacs" is available and uses Emacs daemon
"${xdg_dataHome}/bin/emacsclient" = {
executable = true;
text = ''
#!/bin/zsh
#
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Run Emacs
# @raycast.mode silent
#
# Optional parameters:
# @raycast.packageName Emacs
# @raycast.icon ${xdg_dataHome}/img/icons/Emacs.icns
# @raycast.iconDark ${xdg_dataHome}/img/icons/Emacs.icns
if [[ $1 = "-t" ]]; then
# Terminal mode
${pkgs.emacs}/bin/emacsclient -t $@
else
# GUI mode
${pkgs.emacs}/bin/emacsclient -c -n $@
fi
'';
};
}

View File

@ -0,0 +1,103 @@
{ config, pkgs, lib, home-manager, ... }:
let
user = "%USER%";
# Define the content of your file as a derivation
myEmacsLauncher = pkgs.writeScript "emacs-launcher.command" ''
#!/bin/sh
emacsclient -c -n &
'';
sharedFiles = import ../shared/files.nix { inherit config pkgs; };
additionalFiles = import ./files.nix { inherit user config pkgs; };
in
{
imports = [
./dock
];
# It me
users.users.${user} = {
name = "${user}";
home = "/Users/${user}";
isHidden = false;
shell = pkgs.zsh;
};
homebrew = {
enable = true;
casks = pkgs.callPackage ./casks.nix {};
# onActivation.cleanup = "uninstall";
# These app IDs are from using the mas CLI app
# mas = mac app store
# https://github.com/mas-cli/mas
#
# $ nix shell nixpkgs#mas
# $ mas search <app name>
#
# If you have previously added these apps to your Mac App Store profile (but not installed them on this system),
# you may receive an error message "Redownload Unavailable with This Apple ID".
# This message is safe to ignore. (https://github.com/dustinlyons/nixos-config/issues/83)
masApps = {
"1password" = 1333542190;
"wireguard" = 1451685025;
};
};
# Enable home-manager
home-manager = {
useGlobalPkgs = true;
users.${user} = { pkgs, config, lib, ... }:{
home = {
enableNixpkgsReleaseCheck = false;
packages = pkgs.callPackage ./packages.nix {};
file = lib.mkMerge [
sharedFiles
additionalFiles
{ "emacs-launcher.command".source = myEmacsLauncher; }
];
stateVersion = "23.11";
};
programs = {} // import ../shared/home-manager.nix { inherit config pkgs lib; };
# Marked broken Oct 20, 2022 check later to remove this
# https://github.com/nix-community/home-manager/issues/3344
manual.manpages.enable = false;
};
};
# Fully declarative dock using the latest from Nix Store
local = {
dock = {
enable = true;
entries = [
{ path = "/Applications/Slack.app/"; }
{ path = "/System/Applications/Messages.app/"; }
{ path = "/System/Applications/Facetime.app/"; }
{ path = "${pkgs.alacritty}/Applications/Alacritty.app/"; }
{ path = "/System/Applications/Music.app/"; }
{ path = "/System/Applications/News.app/"; }
{ path = "/System/Applications/Photos.app/"; }
{ path = "/System/Applications/Photo Booth.app/"; }
{ path = "/System/Applications/TV.app/"; }
{ path = "/System/Applications/Home.app/"; }
{
path = toString myEmacsLauncher;
section = "others";
}
{
path = "${config.users.users.${user}.home}/.local/share/";
section = "others";
options = "--sort name --view grid --display folder";
}
{
path = "${config.users.users.${user}.home}/.local/share/downloads";
section = "others";
options = "--sort name --view grid --display stack";
}
];
};
};
}

View File

@ -0,0 +1,7 @@
{ pkgs }:
with pkgs;
let shared-packages = import ../shared/packages.nix { inherit pkgs; }; in
shared-packages ++ [
dockutil
]

View File

@ -0,0 +1,37 @@
{ config, pkgs, agenix, secrets, ... }:
let user = "%USER%"; in
{
age.identityPaths = [
"/Users/${user}/.ssh/id_ed25519"
];
# Your secrets go here
#
# Note: the installWithSecrets command you ran to boostrap the machine actually copies over
# a Github key pair. However, if you want to store the keypair in your nix-secrets repo
# instead, you can reference the age files and specify the symlink path here. Then add your
# public key in shared/files.nix.
#
# If you change the key name, you'll need to update the SSH configuration in shared/home-manager.nix
# so Github reads it correctly.
#
# age.secrets."github-ssh-key" = {
# symlink = true;
# path = "/Users/${user}/.ssh/id_github";
# file = "${secrets}/github-ssh-key.age";
# mode = "600";
# owner = "${user}";
# group = "staff";
# };
# age.secrets."github-signing-key" = {
# symlink = false;
# path = "/Users/${user}/.ssh/pgp_github.key";
# file = "${secrets}/github-signing-key.age";
# mode = "600";
# owner = "${user}";
# };
}