Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Jan 31, 2025
1 parent cb20712 commit 0c5e5dc
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 45 deletions.
66 changes: 50 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,56 @@ rec {
};

nixConfig = {
extra-experimental-features = [ "nix-command" "flakes" ];
extra-substituters =
[ "https://nix-community.cachix.org" "https://devenv.cachix.org" ];
extra-experimental-features = [
"nix-command"
"flakes"
];
extra-substituters = [
"https://nix-community.cachix.org"
"https://devenv.cachix.org"
];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
];
};

outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager
, davids-dotfiles-private, poetry2nix, flake-utils, ... }:
outputs =
inputs@{
self,
nix-darwin,
nixpkgs,
home-manager,
davids-dotfiles-private,
poetry2nix,
flake-utils,
...
}:
let
mkDarwin = { host, arch, ... }:
mkDarwin =
{ host, arch, ... }:
nix-darwin.lib.darwinSystem rec {
system = "${arch}-darwin";
specialArgs = let
hostPlatform = nixpkgs.legacyPackages.${system}.stdenv.hostPlatform;
in { inherit home-manager hostPlatform system nixConfig; };
specialArgs =
let
hostPlatform = nixpkgs.legacyPackages.${system}.stdenv.hostPlatform;
in
{
inherit
home-manager
hostPlatform
system
nixConfig
;
};
modules = [
home-manager.darwinModules.home-manager
(import ./hosts/${host} (inputs // outputs))
{ home-manager = { extraSpecialArgs = specialArgs; }; }
{
home-manager = {
extraSpecialArgs = specialArgs;
};
}
];
};
outputs = {
Expand All @@ -48,11 +76,16 @@ rec {
systemModules = lib.importDir ./modules/system (inputs // outputs);
homeModules = lib.importDir ./modules/home (inputs // outputs);
users = lib.importDir ./users (inputs // outputs);
packages = (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
packages = lib.callPackageDirWith ./pkgs (inputs // pkgs);
in packages));
packages = (
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
packages = lib.callPackageDirWith ./pkgs (inputs // pkgs);
in
packages
)
);
};
darwinConfigurations = {
Jellyfish = mkDarwin {
Expand All @@ -65,5 +98,6 @@ rec {
};
};
};
in outputs;
in
outputs;
}
76 changes: 49 additions & 27 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,45 +1,67 @@
{ lib, ... }:
with lib; rec {
with lib;
rec {
# List immediate subdirectories of a directory
subDirs = d:
foldlAttrs
(a: k: v: a // (if v == "directory" then { ${k} = d + "/${k}"; } else { }))
{ } (builtins.readDir d);
subDirs =
d:
foldlAttrs (
a: k: v:
a // (if v == "directory" then { ${k} = d + "/${k}"; } else { })
) { } (builtins.readDir d);

# Annotate a region of text for simpler identification of origin
textRegion = { name, content, comment-char ? "#", }: ''
${comment-char} +begin ${name}
${content}
${comment-char} +end ${name}
'';
textRegion =
{
name,
content,
comment-char ? "#",
}:
''
${comment-char} +begin ${name}
${content}
${comment-char} +end ${name}
'';

# Return the list of importable names in a directory.
# Importable name is either
# - a regular file with the nix extension
# - or a directory containing default.nix.
importables = root:
let children = builtins.readDir root;
in (builtins.attrNames (lib.attrsets.filterAttrs (n: t:
(t == "regular" && (builtins.match ".+\\.nix$" n) != null)
|| (t == "directory" && builtins.pathExists (root + "/${n}/default.nix")))
children));
importables =
root:
let
children = builtins.readDir root;
in
(builtins.attrNames (
lib.attrsets.filterAttrs (
n: t:
(t == "regular" && (builtins.match ".+\\.nix$" n) != null)
|| (t == "directory" && builtins.pathExists (root + "/${n}/default.nix"))
) children
));

# Import each importable in the dir and return as an attrset keyed by their names.
importDir = d: arg:
builtins.foldl' (a: name: a // { ${name} = import "${d}/${name}" arg; }) { }
(importables d);
# Import each importable in the dir and return as an attrset keyed by their names.
importDir =
d: arg:
builtins.foldl' (a: name: a // { ${name} = import "${d}/${name}" arg; }) { } (importables d);

# Like callPackageWith but for a while directory.
# The directory should contain nix files, or directories containing default.nix files that define packages.
# The packages are imported with their file basename as the attribute name.
callPackageDirWith = root: ins:
callPackageDirWith =
root: ins:
let
callPkg = lib.callPackageWith all;
outs = builtins.listToAttrs (builtins.map (f: {
name = let m = (builtins.match "(.+)\\.nix$" f);
in if m != null then builtins.head m else f;
value = callPkg (root + ("/" + f)) { };
}) (importables root));
outs = builtins.listToAttrs (
builtins.map (f: {
name =
let
m = (builtins.match "(.+)\\.nix$" f);
in
if m != null then builtins.head m else f;
value = callPkg (root + ("/" + f)) { };
}) (importables root)
);
all = ins // outs;
in outs;
in
outs;
}
10 changes: 8 additions & 2 deletions users/dszakallas/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{ self, davids-dotfiles, davids-dotfiles-private, ... }:
{ pkgs, system, ... }: {
{
self,
davids-dotfiles,
davids-dotfiles-private,
...
}:
{ pkgs, system, ... }:
{
users.users.dszakallas = {
name = "dszakallas";
home = "/Users/dszakallas";
Expand Down

0 comments on commit 0c5e5dc

Please sign in to comment.