Files
dotfiles/nixos/flake.nix

432 lines
14 KiB
Nix
Raw Normal View History

2021-07-11 04:19:34 -06:00
{
inputs = {
nixpkgs = {
2025-05-07 09:32:11 -06:00
url = "github:NixOS/nixpkgs/nixos-unstable";
};
2024-11-20 16:06:11 -07:00
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
2025-11-25 19:45:56 -08:00
systems = {url = "github:nix-systems/default";};
2024-11-20 16:06:11 -07:00
git-ignore-nix = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
2024-12-09 16:21:13 -07:00
url = "github:nix-community/home-manager/master";
2021-07-17 15:47:04 -06:00
inputs.nixpkgs.follows = "nixpkgs";
2021-07-11 04:19:34 -06:00
};
2025-11-25 19:45:56 -08:00
nixos-hardware = {url = "github:colonelpanic8/nixos-hardware/my-master";};
2024-11-20 16:06:11 -07:00
2025-11-25 19:45:56 -08:00
nixos-wsl = {url = "github:nix-community/NixOS-WSL";};
2024-11-20 16:06:11 -07:00
2025-11-25 19:45:56 -08:00
agenix = {url = "github:ryantm/agenix";};
2024-11-20 16:06:11 -07:00
railbird-secrets = {
url = "git+ssh://gitea@dev.railbird.ai:1123/railbird/secrets-flake.git";
};
2025-11-25 19:45:56 -08:00
# railbird-secrets = {
# url = "git+ssh://gitea@dev.railbird.ai:1123/railbird/secrets-flake.git";
# };
2024-11-20 16:06:11 -07:00
xmonad = {
url = "github:xmonad/xmonad";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
git-ignore-nix.follows = "git-ignore-nix";
};
2021-07-11 04:19:34 -06:00
};
2024-11-20 16:06:11 -07:00
xmonad-contrib = {
url = "github:IvanMalison/xmonad-contrib/withMyChanges";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
git-ignore-nix.follows = "git-ignore-nix";
2024-11-20 16:06:11 -07:00
xmonad.follows = "xmonad";
};
2021-07-11 04:19:34 -06:00
};
taffybar = {
url = "github:taffybar/taffybar/old-master";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
imalison-taffybar = {
url = "path:../dotfiles/config/taffybar";
# inputs = {
# nixpkgs.follows = "nixpkgs";
# flake-utils.follows = "flake-utils";
# xmonad.follows = "xmonad";
# taffybar.follows = "taffybar";
# };
2021-07-13 03:37:03 -06:00
};
2021-07-19 19:38:04 -06:00
notifications-tray-icon = {
url = "github:IvanMalison/notifications-tray-icon";
inputs.flake-utils.follows = "flake-utils";
inputs.git-ignore-nix.follows = "git-ignore-nix";
inputs.nixpkgs.follows = "nixpkgs";
2021-07-19 19:38:04 -06:00
};
gtk-sni-tray = {
url = "github:taffybar/gtk-sni-tray";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
git-ignore-nix.follows = "git-ignore-nix";
status-notifier-item.follows = "status-notifier-item";
};
};
status-notifier-item = {
url = "github:taffybar/status-notifier-item";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
git-ignore-nix.follows = "git-ignore-nix";
};
};
gtk-strut = {
url = "github:taffybar/gtk-strut";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
git-ignore-nix.follows = "git-ignore-nix";
};
};
2023-12-13 11:30:46 -07:00
vscode-server.url = "github:nix-community/nixos-vscode-server";
2025-11-25 19:45:56 -08:00
nixified-ai = {url = "github:nixified-ai/flake";};
2024-11-20 16:06:11 -07:00
nixtheplanet.url = "github:matthewcroughan/nixtheplanet";
org-agenda-api = {
url = "github:colonelpanic8/org-agenda-api";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-07-11 04:19:34 -06:00
};
2025-11-25 19:45:56 -08:00
outputs = inputs @ {
self,
nixpkgs,
nixos-hardware,
home-manager,
taffybar,
xmonad,
nixtheplanet,
xmonad-contrib,
notifications-tray-icon,
nix,
agenix,
imalison-taffybar,
...
}: let
# Nixpkgs PR patches - just specify PR number and hash
nixpkgsPRPatches = [
{
2025-12-19 15:03:12 -08:00
pr = 434160; # git-sync-rs package
hash = "sha256-zjzjmC1XJmwfHr/YXFyYsqUFR5MHSoxWWyxIR35YNbM=";
}
# claude-code
# {
# pr = 464698;
# hash = "sha256-Pe9G6b/rI0874mM7FIOSEKiaubk95NcFhTQ7paAeLTU=";
# }
# {
# pr = 464816;
# hash = "sha256-bKEoRy4dzP5TyRBjYskwEzr7tj8/ez/Y1XHiQgu5q5I=";
# }
];
# Custom patches that don't fit the PR template
2025-12-19 15:03:12 -08:00
nixpkgsCustomPatches = [
];
2025-12-19 15:03:12 -08:00
# Home-manager PR patches - just specify PR number and hash
homeManagerPRPatches = [
# Example:
# {
# pr = 1234;
# hash = "sha256-...";
# }
];
# Custom home-manager patches that don't fit the PR template
homeManagerCustomPatches = [
{
url = "https://github.com/colonelpanic8/home-manager/commit/92f4b7aa5254f8bcddc9ef86e04ea5314410d10b.patch";
hash = "sha256-RQl5daVpCqQi05l9QfTEz2PpQxmsv/HYnXrgXbqbwWk=";
}
];
# Convert PR patches to full patch format for nixpkgs
nixpkgsPrPatchesToPatches = prPatches:
map (p: {
url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/${toString p.pr}.patch";
hash = p.hash;
})
prPatches;
2025-12-19 15:03:12 -08:00
# Convert PR patches to full patch format for home-manager
homeManagerPrPatchesToPatches = prPatches:
map (p: {
url = "https://patch-diff.githubusercontent.com/raw/nix-community/home-manager/pull/${toString p.pr}.patch";
hash = p.hash;
})
prPatches;
# Combine all nixpkgs patches
allNixpkgsPatches = (nixpkgsPrPatchesToPatches nixpkgsPRPatches) ++ nixpkgsCustomPatches;
# Combine all home-manager patches
allHomeManagerPatches = (homeManagerPrPatchesToPatches homeManagerPRPatches) ++ homeManagerCustomPatches;
machinesFilepath = ./machines;
machineFilenames = builtins.attrNames (builtins.readDir machinesFilepath);
2021-08-20 19:28:51 -06:00
machineNameFromFilename = filename: builtins.head (builtins.split "\\." filename);
machineNames = map machineNameFromFilename machineFilenames;
2021-08-20 19:28:51 -06:00
mkConfigurationParams = filename: {
name = machineNameFromFilename filename;
value = {
modules = [
2025-11-25 19:45:56 -08:00
(machinesFilepath + ("/" + filename))
agenix.nixosModules.default
nixtheplanet.nixosModules.macos-ventura
inputs.org-agenda-api.nixosModules.default
];
2021-08-20 19:28:51 -06:00
};
};
2021-08-20 19:28:51 -06:00
defaultConfigurationParams =
builtins.listToAttrs (map mkConfigurationParams machineFilenames);
2023-06-28 21:43:55 -06:00
customParams = {
biskcomp = {
system = "aarch64-linux";
2021-08-20 19:28:51 -06:00
};
2023-06-28 21:43:55 -06:00
air-gapped-pi = {
system = "aarch64-linux";
};
};
2025-11-25 19:45:56 -08:00
mkConfig = {
system ? "x86_64-linux",
baseModules ? [],
modules ? [],
specialArgs ? {},
...
}: let
# Bootstrap nixpkgs for this specific system
bootstrapPkgs = import nixpkgs {
inherit system;
config = {};
overlays = [];
};
# Apply patches to nixpkgs source
patchedSource = bootstrapPkgs.applyPatches {
name = "nixpkgs-patched";
src = nixpkgs;
2025-12-19 15:03:12 -08:00
patches = map bootstrapPkgs.fetchpatch allNixpkgsPatches;
2025-11-25 19:45:56 -08:00
prePatch = ''
mkdir -p pkgs/by-name/an/antigravity
'';
};
# Get eval-config from patched source
evalConfig = import "${patchedSource}/nixos/lib/eval-config.nix";
2025-12-19 15:03:12 -08:00
# Apply patches to home-manager source (only if there are patches)
patchedHomeManagerSource =
if allHomeManagerPatches == []
then home-manager
else
bootstrapPkgs.applyPatches {
name = "home-manager-patched";
src = home-manager;
patches = map bootstrapPkgs.fetchpatch allHomeManagerPatches;
};
# Import the patched home-manager flake
patchedHomeManager =
if allHomeManagerPatches == []
then home-manager
else import "${patchedHomeManagerSource}/flake.nix";
# Get the NixOS module from the patched source
patchedHomeManagerModule =
if allHomeManagerPatches == []
then home-manager.nixosModules.home-manager
else import "${patchedHomeManagerSource}/nixos";
# Create a modified inputs with patched home-manager
patchedInputs = inputs // {
home-manager = inputs.home-manager // {
nixosModules = inputs.home-manager.nixosModules // {
home-manager = patchedHomeManagerModule;
};
# Also provide the patched source path for any direct imports
outPath = patchedHomeManagerSource.outPath or "${patchedHomeManagerSource}";
};
};
in
2025-11-25 19:45:56 -08:00
evalConfig {
inherit system;
modules = baseModules ++ modules;
specialArgs =
rec {
2025-12-19 15:03:12 -08:00
inputs = patchedInputs;
inherit machineNames;
2025-11-25 19:45:56 -08:00
makeEnable = (import ./make-enable.nix) nixpkgs.lib;
keys = import ./keys.nix;
usersInfo = (import ./users.nix) {
pkgs = {zsh = "zsh";};
2025-12-19 15:03:12 -08:00
inherit keys system;
inputs = patchedInputs;
2025-11-25 19:45:56 -08:00
};
realUsers = (
builtins.attrNames
(nixpkgs.lib.filterAttrs
(_: value: (builtins.elem "isNormalUser" (builtins.attrNames value)) && value.isNormalUser)
usersInfo.users.users)
);
mapAllKeysToValue = keys: value: builtins.listToAttrs (map (name: {inherit name value;}) keys);
forEachUser = mapAllKeysToValue realUsers;
}
// specialArgs;
};
in {
nixConfig = {
substituters = [
"https://cache.nixos.org/"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
];
extra-substituters = [
"http://192.168.1.26:5050"
2025-10-03 12:29:29 -07:00
"https://cache.flox.dev"
];
extra-trusted-public-keys = [
"1896Folsom.duckdns.org:U2FTjvP95qwAJo0oGpvmUChJCgi5zQoG1YisoI08Qoo="
2025-10-03 12:29:29 -07:00
"flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs="
];
};
2025-11-25 19:45:56 -08:00
nixosConfigurations =
builtins.mapAttrs (
machineName: params: let
machineParams =
if builtins.hasAttr machineName customParams
then (builtins.getAttr machineName customParams)
else {};
in
mkConfig (params // machineParams)
)
defaultConfigurationParams;
}
//
# Per-system packages (using flake-utils)
inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
# Path to org-config.org in the dotfiles
orgConfigOrg = ../dotfiles/emacs.d/org-config.org;
# Tangle org-config.org and create a loader for the container
orgAgendaCustomConfig = pkgs.runCommand "org-agenda-custom-config" {
buildInputs = [ pkgs.emacs-nox ];
} ''
mkdir -p $out
mkdir -p work
# Copy org file to writable location (tangle writes to same directory)
cp ${orgConfigOrg} work/org-config.org
# Tangle org-config.org
emacs --batch \
--eval '(require (quote org))' \
--eval '(org-babel-tangle-file "work/org-config.org")'
# Copy all tangled files to output
for f in work/org-config-*.el; do
if [ -f "$f" ]; then
cp "$f" $out/
fi
done
# Create a loader that sets up paths and loads files in order
cat > $out/custom-config.el << 'ELISP'
;;; custom-config.el --- Container config loader -*- lexical-binding: t; -*-
;; Set org directory for container
(defvar imalison:org-dir "/data/org")
(defvar imalison:shared-org-dir nil)
;; Helper function used by org-config
(defun imalison:join-paths (&rest paths)
"Join PATHS together into a single path."
(let ((result (car paths)))
(dolist (p (cdr paths))
(setq result (expand-file-name p result)))
result))
;; Load tangled config files in order
(let ((config-dir (file-name-directory load-file-name)))
(when (file-exists-p (expand-file-name "org-config-preface.el" config-dir))
(load (expand-file-name "org-config-preface.el" config-dir)))
;; org-config-custom.el uses customize format (var value), convert to setq
(when (file-exists-p (expand-file-name "org-config-custom.el" config-dir))
(with-temp-buffer
(insert-file-contents (expand-file-name "org-config-custom.el" config-dir))
(goto-char (point-min))
(condition-case nil
(while t
(let ((form (read (current-buffer))))
(when (and (listp form) (symbolp (car form)))
(set (car form) (eval (cadr form))))))
(end-of-file nil))))
(when (file-exists-p (expand-file-name "org-config-config.el" config-dir))
(load (expand-file-name "org-config-config.el" config-dir))))
;; Capture templates for API
(setq org-agenda-api-capture-templates
`(("gtd-todo"
:name "GTD Todo"
:template ("t" "Todo" entry (file ,(imalison:join-paths imalison:org-dir "inbox.org"))
"* INBOX %^{Title}\n:PROPERTIES:\n:CREATED: %U\n:END:\n"
:immediate-finish t)
:prompts (("Title" :type string :required t)))
("scheduled-todo"
:name "Scheduled Todo"
:template ("s" "Scheduled" entry (file ,(imalison:join-paths imalison:org-dir "inbox.org"))
"* INBOX %^{Title}\nSCHEDULED: %^{When}t\n:PROPERTIES:\n:CREATED: %U\n:END:\n"
:immediate-finish t)
:prompts (("Title" :type string :required t)
("When" :type date :required t)))
("deadline-todo"
:name "Todo with Deadline"
:template ("d" "Deadline" entry (file ,(imalison:join-paths imalison:org-dir "inbox.org"))
"* INBOX %^{Title}\nDEADLINE: %^{When}t\n:PROPERTIES:\n:CREATED: %U\n:END:\n"
:immediate-finish t)
:prompts (("Title" :type string :required t)
("When" :type date :required t)))))
ELISP
'';
# Build customized org-agenda-api container
orgAgendaApiContainer = inputs.org-agenda-api.lib.${system}.mkContainer {
customElispFile = "${orgAgendaCustomConfig}/custom-config.el";
};
in {
packages = {
org-agenda-custom-config = orgAgendaCustomConfig;
org-agenda-api-container = orgAgendaApiContainer;
};
}
);
2021-07-11 04:19:34 -06:00
}