From 0c5e5dc5cbe0a18757c47144b808705ef6e41292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szak=C3=A1llas?= Date: Fri, 31 Jan 2025 18:53:36 +0100 Subject: [PATCH] reformat --- flake.nix | 66 +++++++++++++++++++++++-------- lib/default.nix | 76 +++++++++++++++++++++++------------- users/dszakallas/default.nix | 10 ++++- 3 files changed, 107 insertions(+), 45 deletions(-) diff --git a/flake.nix b/flake.nix index a15242a..3ccca05 100644 --- a/flake.nix +++ b/flake.nix @@ -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 = { @@ -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 { @@ -65,5 +98,6 @@ rec { }; }; }; - in outputs; + in + outputs; } diff --git a/lib/default.nix b/lib/default.nix index 1c8a561..880d802 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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; } diff --git a/users/dszakallas/default.nix b/users/dszakallas/default.nix index e993f96..e1e1caf 100644 --- a/users/dszakallas/default.nix +++ b/users/dszakallas/default.nix @@ -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";