Skip to content

Commit

Permalink
feat: restructure again wooo
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-gelinas committed Oct 19, 2024
1 parent ad5be68 commit 8438ed5
Show file tree
Hide file tree
Showing 40 changed files with 450 additions and 569 deletions.
287 changes: 50 additions & 237 deletions flake.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
parts = import ./parts;
in
{
debug = true;

imports = [ (import "${flake-parts}/all-modules.nix") ] ++ builtins.attrValues parts;

systems = [
Expand Down Expand Up @@ -57,15 +59,13 @@
# Dependencies
#========================================================

disko.url = "github:nix-community/disko";
fenix.url = "github:nix-community/fenix";
fonts.url = "git+ssh://[email protected]/remi-gelinas/fonts";
ghostty.url = "git+ssh://[email protected]/ghostty-org/ghostty";
lix-module.url = "git+https://git.lix.systems/lix-project/nixos-module?ref=refs/tags/2.91.0";
neovim.url = "github:nix-community/neovim-nightly-overlay";
nixd.url = "github:nix-community/nixd/2.2.3";
nixpkgs-master.url = "github:NixOS/nixpkgs";
nixpkgs-unfree.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs-unfree.url = "github:numtide/nixpkgs-unfree";
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
stylix.url = "github:danth/stylix";
zls.url = "github:zigtools/zls/0.13.0";
Expand Down
93 changes: 93 additions & 0 deletions lib/modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{ lib }:
let
inherit (builtins) readDir listToAttrs;
inherit (lib)
pipe
attrNames
concatMap
filter
filterAttrs
;

inherit (import ./sharding.nix { inherit lib; }) isValidShard;

self = {
# Aggregates all valid sharded modules under a base path
getShardedModulesInPath =
base:
let
childPaths = filter: path: attrNames (filterAttrs filter (readDir path));
childDirs = childPaths (_: type: type == "directory");
childFiles = childPaths (_: type: type == "regular");

modulesInShard =
{ base, shard }:
let
modules = childDirs (base + "/${shard}");
in
map (module: { inherit base module shard; }) modules;

filesInModule =
{
base,
module,
shard,
}:
let
moduleBase = base + "/${shard}/${module}";
files = childFiles moduleBase;
in
assert isValidShard shard module;
map (file: {
inherit
base
module
shard
file
;
}) files;

shards = map (shard: { inherit base shard; }) (childDirs base);
in
pipe shards [
(concatMap modulesInShard)
(concatMap filesInModule)
];

# Applies a filter to all sharded module files
# Meant to be used in a pipeline with the result of getShardedModulesInPath
filterShardedModuleFiles =
modules: f:
pipe modules [
(filter f)
(map (
{
base,
module,
shard,
file,
}:
{
name = module;
value = base + "/${shard}/${module}/${file}";
}
))
listToAttrs
];

# Convenience method to get dependency modules according to my standard
# For home-manager, NixOS, and nix-darwin module trees
getSystemModulesInPath =
base:
let
inherit (lib) hasPrefix;
moduleFiles = self.getShardedModulesInPath base;
in
{
darwin = self.filterShardedModuleFiles moduleFiles ({ file, ... }: hasPrefix "darwin-" file);
home = self.filterShardedModuleFiles moduleFiles ({ file, ... }: hasPrefix "home-" file);
nixos = self.filterShardedModuleFiles moduleFiles ({ file, ... }: hasPrefix "nixos-" file);
};
};
in
self
4 changes: 2 additions & 2 deletions utils.nix → lib/sharding.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib }:
{ lib, ... }:
let
inherit (lib) toLower substring;
in
{
# Used for package and module by-name assertions
isShardedCorrectly = shard: obj: shard == toLower (substring 0 2 obj);
isValidShard = shard: obj: shard == toLower (substring 0 2 obj);
}
5 changes: 0 additions & 5 deletions modules/by-name/ba/bat/home-module.nix

This file was deleted.

15 changes: 0 additions & 15 deletions modules/by-name/fi/fish/darwin-module.nix

This file was deleted.

24 changes: 0 additions & 24 deletions modules/by-name/gh/ghostty/home-module.nix

This file was deleted.

22 changes: 0 additions & 22 deletions modules/by-name/ho/home-manager/darwin-module.nix

This file was deleted.

27 changes: 2 additions & 25 deletions modules/by-name/ho/homebrew/darwin-module.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
{ config, pkgs, ... }:
{ pkgs, ... }:
{
environment.shellInit = ''
eval "$(${
if pkgs.stdenv.isAarch64 then
config.nix-homebrew.defaultArm64Prefix
else
config.nix-homebrew.defaultIntelPrefix
}/bin/brew shellenv)"
'';

# https://docs.brew.sh/Shell-Completion#configuring-completions-in-fish
# For some reason if the Fish completions are added at the end of `fish_complete_path` they don't
# seem to work, but they do work if added at the start.
programs.fish.interactiveShellInit = ''
if test -d (brew --prefix)"/share/fish/completions"
set -p fish_complete_path (brew --prefix)/share/fish/completions
end
if test -d (brew --prefix)"/share/fish/vendor_completions.d"
set -p fish_complete_path (brew --prefix)/share/fish/vendor_completions.d
end
'';

# nix-darwin Homebrew module
homebrew = {
enable = true;

Expand Down Expand Up @@ -51,9 +28,9 @@
};
};

# nix-homebrew config
nix-homebrew = {
enable = true;

enableRosetta = pkgs.stdenv.hostPlatform.isAarch64;
};
}
39 changes: 0 additions & 39 deletions modules/by-name/pa/packages/home-module.nix

This file was deleted.

9 changes: 0 additions & 9 deletions modules/by-name/sk/sketchybar/darwin-module.nix

This file was deleted.

6 changes: 0 additions & 6 deletions modules/by-name/th/thefuck/home-module.nix

This file was deleted.

82 changes: 1 addition & 81 deletions modules/top-level/all-modules.nix
Original file line number Diff line number Diff line change
@@ -1,81 +1 @@
{ lib }:
let
utils = import ../../utils.nix { inherit lib; };

inherit (builtins) readDir listToAttrs;
inherit (utils) isShardedCorrectly;
inherit (lib)
pipe
attrNames
concatMap
filter
filterAttrs
hasPrefix
;

getShardedModulesInPath =
base:
let
childPaths = filter: path: attrNames (filterAttrs filter (readDir path));
childDirs = childPaths (_: type: type == "directory");
childFiles = childPaths (_: type: type == "regular");

modulesInShard =
{ base, shard }:
let
modules = childDirs (base + "/${shard}");
in
map (module: { inherit base module shard; }) modules;

filesInModule =
{
base,
module,
shard,
}:
let
moduleBase = base + "/${shard}/${module}";
files = childFiles moduleBase;
in
assert isShardedCorrectly shard module;
map (file: {
inherit
base
module
shard
file
;
}) files;

shards = map (shard: { inherit base shard; }) (childDirs base);
in
pipe shards [
(concatMap modulesInShard)
(concatMap filesInModule)
];

getShardedModuleFiles = getShardedModulesInPath ../by-name;

filterShardedModuleFiles =
f:
pipe getShardedModuleFiles [
(filter f)
(map (
{
base,
module,
shard,
file,
}:
{
name = module;
value = base + "/${shard}/${module}/${file}";
}
))
listToAttrs
];
in
{
darwin = filterShardedModuleFiles ({ file, ... }: hasPrefix "darwin-" file);
home = filterShardedModuleFiles ({ file, ... }: hasPrefix "home-" file);
}
{ lib }: (import ../../lib/modules.nix { inherit lib; }).getSystemModulesInPath ../by-name
4 changes: 2 additions & 2 deletions parts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
overlays = ./overlays.nix;
devShells = ./devshells.nix;
darwinConfigurations = ./darwin-configurations.nix;
nixosConfigurations = ./nixos-configurations.nix;
homeManagerConfigurations = ./home-manager-configurations.nix;
githubActions = ./github-actions.nix;
darwinModules = ./modules/nix-darwin.nix;
homeManagerModules = ./modules/home-manager.nix;
}
Loading

0 comments on commit 8438ed5

Please sign in to comment.