Drop flake parts

Use native nix functions to speed up and reduce complexity
This commit is contained in:
Primrose 2025-02-05 19:02:18 +01:00
parent 85e2bd6728
commit daefd1534f
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
15 changed files with 501 additions and 423 deletions

85
nix/lib/default.nix Normal file
View file

@ -0,0 +1,85 @@
inputs:
let
inherit (inputs.nixpkgs) lib;
in
{
mkNixOS =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
inputs.nixpkgs.lib.nixosSystem {
specialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
};
mkDarwin =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
inputs.nix-darwin.lib.darwinSystem {
specialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
};
mkHomeManager =
sharedModules:
{
hostname,
system,
modules ? [ ],
}:
let
pkgs = import inputs.nixpkgs { };
in
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit hostname;
};
modules = sharedModules { inherit hostname system; } ++ modules;
};
many = func: builtins.mapAttrs (hostname: cfgs: func (cfgs // { inherit hostname; }));
maybePathOrDefault =
path: default:
if
lib.pathExists # Test directory/default.nix or just the file
(if lib.pathIsDirectory path then (lib.path.append path "default.nix") else path)
then
path
else
default;
mergeAttrsWith =
f: xs: ys:
builtins.foldl' (
acc: n: acc // (if acc ? ${n} then { ${n} = f xs.${n} ys.${n}; } else { ${n} = ys.${n}; })
) xs (builtins.attrNames ys);
modulesFromDir =
path:
lib.pipe (builtins.readDir path) [
(lib.filterAttrs (moduleName: _: moduleName != "default.nix"))
(lib.mapAttrs' (
moduleName: _: {
name = lib.strings.removeSuffix ".nix" moduleName;
value = lib.path.append path moduleName;
}
))
];
mkNerdFont = import ./mkNerdFont.nix;
}

63
nix/lib/mkNerdFont.nix Normal file
View file

@ -0,0 +1,63 @@
{
lib,
nerd-font-patcher,
parallel,
stdenvNoCC,
}:
{
font,
extraArgs ? [ ],
useDefaultsArgs ? true,
}:
stdenvNoCC.mkDerivation {
/*
Credits:
https://github.com/NixOS/nixpkgs/issues/44329#issuecomment-1231189572
https://github.com/NixOS/nixpkgs/issues/44329#issuecomment-1544597422
long font names is not problematic:
https://github.com/ryanoasis/nerd-fonts/issues/1018#issuecomment-1953555781
*/
name = "${font.name}-NerdFont";
src = font;
nativeBuildInputs = [
nerd-font-patcher
parallel
];
buildPhase =
let
args =
(lib.optionals useDefaultsArgs [
"--careful"
"--complete"
"--quiet"
"--no-progressbars"
])
++ extraArgs;
in
''
mkdir -p nerd-font
find \( -name \*.ttf -o -name \*.otf \) | parallel nerd-font-patcher {} \
--outputdir nerd-font ${builtins.concatStringsSep " " args}
'';
installPhase = ''
exists() { [ -e "$1" ]; }
truetype="$out/share/fonts/truetype"
opentype="$out/share/fonts/opentype"
if exists nerd-font/*.ttf ; then
mkdir -p "$truetype"
cp nerd-font/*.ttf "$truetype"
fi
if exists nerd-font/*.otf ; then
mkdir -p "$opentype"
cp nerd-font/*.otf "$opentype"
fi
'';
}