refactor some nix code with pipe

This commit is contained in:
ulic-youthlic 2025-03-14 06:55:26 +08:00
parent 07546c9567
commit 36f623a93a
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
4 changed files with 72 additions and 69 deletions

View file

@ -184,7 +184,7 @@
imports = [ imports = [
inputs.home-manager.flakeModules.home-manager inputs.home-manager.flakeModules.home-manager
]; ];
perSystem = ( perSystem =
{ pkgs, system, ... }@args: { pkgs, system, ... }@args:
{ {
_module.args.pkgs = import inputs.nixpkgs { _module.args.pkgs = import inputs.nixpkgs {
@ -199,8 +199,7 @@
inherit inputs; inherit inputs;
} }
); );
} };
);
flake = flake =
{ {
nix.settings = { nix.settings = {
@ -233,16 +232,11 @@
nixosConfigurations = nixosConfigurations =
let let
nixosConfigDir = ./nixos/configurations; nixosConfigDir = ./nixos/configurations;
in makeNixConfiguration =
nixpkgs.lib.genAttrs
(map (f: nixpkgs.lib.removeSuffix ".nix" f) (builtins.attrNames (builtins.readDir nixosConfigDir)))
(
hostName: hostName:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
modules = modules =
[ [ outputs.nixosModules.default ]
outputs.nixosModules.default
]
++ [ ++ [
( (
let let
@ -252,11 +246,18 @@
if builtins.pathExists dirPath then dirPath else filePath if builtins.pathExists dirPath then dirPath else filePath
) )
]; ];
specialArgs = { specialArgs = { inherit inputs outputs rootPath; };
inherit inputs outputs rootPath; };
}; in
} nixosConfigDir
); |> builtins.readDir
|> builtins.attrNames
|> map (f: nixpkgs.lib.removeSuffix ".nix" f)
|> map (name: {
inherit name;
value = makeNixConfiguration name;
})
|> builtins.listToAttrs;
} }
// ( // (
let let
@ -313,25 +314,22 @@
extra = import ./home/extra; extra = import ./home/extra;
} }
// ( // (
let ./home
allEntries = builtins.readDir ./home; |> builtins.readDir
allUsers = nixpkgs.lib.filterAttrs ( |> nixpkgs.lib.filterAttrs (key: value: value == "directory")
key: value: |> nixpkgs.lib.filterAttrs (
value == "directory" key: value:
&& ( !builtins.elem key [
!builtins.elem key [ "modules"
"modules" "extra"
"extra" ]
]
)
) allEntries;
in
builtins.listToAttrs (
map (name: {
name = name;
value = import "${toString ./home}/${name}/modules";
}) (builtins.attrNames allUsers)
) )
|> builtins.attrNames
|> map (name: {
name = name;
value = import "${toString ./home}/${name}/modules";
})
|> builtins.listToAttrs
); );
} }
) )
@ -361,19 +359,18 @@
}; };
in in
{ {
deploy.nodes = nixpkgs.lib.foldr (a: b: a // b) { } ( deploy.nodes =
map [
( "Cape"
hostName: "Akun"
mkDeployNode { ]
inherit hostName; |> map (
} hostName:
) mkDeployNode {
[ inherit hostName;
"Cape" }
"Akun" )
] |> nixpkgs.lib.foldr (a: b: a // b) { };
);
} }
); );
}; };

View file

@ -2,14 +2,14 @@
final: prev: final: prev:
let let
inherit (prev) lib; inherit (prev) lib;
overlay-files = [
./spotify.nix
./niri.nix
./ghostty.nix
./juicity.nix
./dae.nix
./jujutsu.nix
];
overlay-list = map (file: import file args) overlay-files;
in in
(lib.composeManyExtensions overlay-list) final prev [
./spotify.nix
./niri.nix
./ghostty.nix
./juicity.nix
./dae.nix
./jujutsu.nix
]
|> map (file: import file args)
|> (overlays: (lib.composeManyExtensions overlays) final prev)

View file

@ -38,7 +38,7 @@ let
delve delve
lldb lldb
rust-analyzer rust-analyzer
nil # nil
haskell-language-server haskell-language-server
neocmakelsp neocmakelsp
] ]

View file

@ -61,20 +61,26 @@ let
runHook postFixup runHook postFixup
''; '';
}; };
grammars = lib.filterAttrs (key: _: lib.hasPrefix "tree-sitter-" key) srcs; grammars = srcs |> lib.filterAttrs (key: _: lib.hasPrefix "tree-sitter-" key);
queries = lib.mapAttrsToList (_: value: '' queries =
mkdir -p $out/${value.name} grammars
|> lib.mapAttrsToList (
_: value: ''
mkdir -p $out/${value.name}
ln -s ${value.src}/queries/* $out/${value.name}/ ln -s ${value.src}/queries/* $out/${value.name}/
'') grammars; ''
builtGrammars = builtins.mapAttrs (_: v: { );
inherit (v) name; grammarLinks =
value = buildGrammar v; grammars
}) grammars; |> builtins.mapAttrs (
grammarLinks = lib.mapAttrsToList ( _: v: {
_: value: "ln -s ${value.value}/${value.name}.so $out/${value.name}.so" inherit (v) name;
) builtGrammars; value = buildGrammar v;
}
)
|> lib.mapAttrsToList (_: value: "ln -s ${value.value}/${value.name}.so $out/${value.name}.so");
grammarDir = runCommandNoCCLocal "helix-grammars" { } '' grammarDir = runCommandNoCCLocal "helix-grammars" { } ''
mkdir -p $out mkdir -p $out