Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Jan 26, 2025
1 parent 18ceabb commit 41978ad
Show file tree
Hide file tree
Showing 79 changed files with 196 additions and 489 deletions.
3 changes: 1 addition & 2 deletions configurations/darwin/khanelimac/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
inputs,
lib,
root,
khanelinix-lib,
...
}:
Expand All @@ -24,7 +23,7 @@ in
sops = {
enable = true;
sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
defaultSopsFile = root + "/secrets/khanelimac/default.yaml";
defaultSopsFile = khanelinix-lib.getFile "secrets/khanelimac/default.yaml";
};
};

Expand Down
2 changes: 1 addition & 1 deletion configurations/home/bruddy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ in

# sops = {
# enable = true;
# defaultSopsFile = root + "/secrets/khanelinix/khaneliman/default.yaml";
# defaultSopsFile = khanelinix-lib.getFile "secrets/khanelinix/khaneliman/default.yaml";
# sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
# };
};
Expand Down
3 changes: 1 addition & 2 deletions configurations/home/khaneliman/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
config,
lib,
root,
khanelinix-lib,
...
}:
Expand Down Expand Up @@ -85,7 +84,7 @@ in
services = {
sops = {
enable = true;
defaultSopsFile = root + "/secrets/khanelimac/khaneliman/default.yaml";
defaultSopsFile = khanelinix-lib.getFile "secrets/khanelimac/khaneliman/default.yaml";
sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
};
};
Expand Down
3 changes: 1 addition & 2 deletions configurations/home/khaneliman@/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
lib,
pkgs,
root,
khanelinix-lib,
self,
system,
Expand Down Expand Up @@ -219,7 +218,7 @@ in

sops = {
enable = true;
defaultSopsFile = root + "/secrets/khanelinix/khaneliman/default.yaml";
defaultSopsFile = khanelinix-lib.getFile "secrets/khanelinix/khaneliman/default.yaml";
sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
};
};
Expand Down
3 changes: 1 addition & 2 deletions configurations/home/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
config,
lib,
osConfig,
root,
khanelinix-lib,
...
}:
Expand Down Expand Up @@ -50,7 +49,7 @@ in
services = {
sops = {
enable = true;
defaultSopsFile = root + "/secrets/CORE/nixos/default.yaml";
defaultSopsFile = khanelinix-lib.getFile "secrets/CORE/nixos/default.yaml";
sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
};
};
Expand Down
3 changes: 1 addition & 2 deletions configurations/nixos/khanelilab/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
config,
root,
khanelinix-lib,
...
}:
Expand Down Expand Up @@ -119,7 +118,7 @@ in
sops = {
enable = true;
sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
defaultSopsFile = root + "/secrets/khanelilab/default.yaml";
defaultSopsFile = khanelinix-lib.getFile "secrets/khanelilab/default.yaml";
};
};

Expand Down
42 changes: 21 additions & 21 deletions flake/configs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@
darwin = {
configurationsDirectory = ../configurations/darwin;
modulesDirectory = ../modules/darwin;
hosts = {
khanelimac.userHomeModules = [
"khaneliman"
];
};
# hosts = {
# khanelimac.userHomeModules = [
# "khaneliman"
# ];
# };
};

home = {
configurationsDirectory = ../configurations/home;
modulesDirectory = ../modules/home;
};
# home = {
# configurationsDirectory = ../configurations/home;
# modulesDirectory = ../modules/home;
# };

nixos = {
configurationsDirectory = ../configurations/nixos;
modulesDirectory = ../modules/nixos;
hosts = {
CORE-PW00LM92.userHomeModules = [
"nixos"
];
bruddynix.userHomeModules = [
"khaneliman"
"bruddy"
];
khanelinix.userHomeModules = [
"khaneliman"
];
};
# hosts = {
# CORE-PW00LM92.userHomeModules = [
# "nixos"
# ];
# bruddynix.userHomeModules = [
# "khaneliman"
# "bruddy"
# ];
# khanelinix.userHomeModules = [
# "khaneliman"
# ];
# };
};
};
}
1 change: 1 addition & 0 deletions flake/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
flake.lib = {
khanelinix = lib.makeOverridable (import ../lib) {
inherit lib self;
root = ../.;
};
};
}
5 changes: 2 additions & 3 deletions flake/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
let
children =
dir:
with builtins;
lib.pipe dir [
readDir
attrNames
builtins.readDir
builtins.attrNames
(map (name: dir + "/${name}"))
];
in
Expand Down
9 changes: 8 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
lib,
self,
root,
...
}:
lib.makeExtensible (
Expand All @@ -16,7 +17,7 @@ lib.makeExtensible (
deploy = call ./deploy/default.nix {
inherit (self) inputs;
};
file = call ./file/default.nix { };
file = call ./file/default.nix { inherit lib root; };
module = call ./module/default.nix { };
packages = call ./packages/default.nix { };
network = call ./network/default.nix {
Expand All @@ -38,5 +39,11 @@ lib.makeExtensible (
nested-default-attrs
nested-force-attrs
;

inherit (self'.file)
getDefaultNixFiles
getDefaultNixFilesRecursive
getFile
;
}
)
108 changes: 107 additions & 1 deletion lib/file/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,115 @@
_: {
{
lib,
root,
...
}:
let
inherit (builtins) readDir pathExists;
inherit (lib)
filterAttrs
mapAttrsToList
;

fileNameRegex = "(.*)\\.(.*)$";
in
rec {
fileWithText = file: text: ''
${builtins.readFile file}
${text}'';

fileWithText' = file: text: ''
${text}
${builtins.readFile file}'';

hasAnyFileExtension =
file:
let
match = builtins.match fileNameRegex (toString file);
in
match != null;

getFileExtension =
file:
if hasAnyFileExtension file then
let
match = builtins.match fileNameRegex (toString file);
in
lib.last match
else
"";

hasFileExtension =
extension: file: if hasAnyFileExtension file then extension == getFileExtension file else false;

# Convert a store path back to a source path
sourcePathFromStorePath =
path:
let
pathStr = toString path;
# Match the nix store path pattern and extract the path after the hash
match = builtins.match "/nix/store/[a-z0-9]+-source(.*)" pathStr;
in
if match != null then builtins.head match else pathStr;

# Convert a store path to a relative path by removing the root prefix
makeRelative =
path:
let
pathStr = toString path;
rootStr = toString root;
sourcePath = sourcePathFromStorePath pathStr;
in
if lib.hasPrefix rootStr sourcePath then lib.removePrefix "${rootStr}/" sourcePath else sourcePath;

getFile = path: "${root}/${path}";

safeReadDirectory = path: if pathExists path then readDir path else { };

getDirectories =
path:
let
entries = safeReadDirectory path;
filteredEntries = filterAttrs (_name: kind: kind == "directory") entries;
in
mapAttrsToList (name: _kind: "${path}/${name}") filteredEntries;

getFiles =
path:
let
entries = safeReadDirectory path;
filteredEntries = filterAttrs (_name: kind: kind == "regular") entries;
in
mapAttrsToList (name: _kind: makeRelative "${path}/${name}") filteredEntries;
getFilesRecursive =
path:
let
actualPath = sourcePathFromStorePath path;
entries = safeReadDirectory actualPath;
filteredEntries = filterAttrs (_: kind: (kind == "regular") || (kind == "directory")) entries;
mapFile =
name: kind:
let
path' = "${actualPath}/${name}";
in
if kind == "directory" then getFilesRecursive path' else makeRelative path';
in
lib.flatten (mapAttrsToList mapFile filteredEntries);

getNixFiles = path: builtins.filter (hasFileExtension "nix") (getFiles path);

getNixFilesRecursive = path: builtins.filter (hasFileExtension "nix") (getFilesRecursive path);

getDefaultNixFiles =
path: builtins.filter (name: builtins.baseNameOf name == "default.nix") (getFiles path);

getDefaultNixFilesRecursive =
path:
let
allFiles = getFilesRecursive path;
# Ignore the top-level default.nix
topLevelDefaultNix = "${makeRelative path}/default.nix";
in
builtins.filter (
name: (builtins.baseNameOf name == "default.nix") && (name != topLevelDefaultNix)
) allFiles;
}
7 changes: 0 additions & 7 deletions modules/darwin/archetypes/default.nix

This file was deleted.

20 changes: 7 additions & 13 deletions modules/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{ khanelinix-lib, ... }:
{
imports = [
./archetypes
./desktop
./home
./nix
./programs
./security
./services
./suites
./system
./tools
./user
];
imports = khanelinix-lib.getDefaultNixFilesRecursive ./.;

# FIXME: Should be inheriting pkgs with this already set
nixpkgs.config = {
allowUnfree = true;
};
}
6 changes: 0 additions & 6 deletions modules/darwin/desktop/addons/default.nix

This file was deleted.

5 changes: 0 additions & 5 deletions modules/darwin/desktop/bars/default.nix

This file was deleted.

7 changes: 0 additions & 7 deletions modules/darwin/desktop/default.nix

This file was deleted.

5 changes: 0 additions & 5 deletions modules/darwin/desktop/wms/default.nix

This file was deleted.

Loading

0 comments on commit 41978ad

Please sign in to comment.