From 4ab322f08d43c2068ae13baac9d9728db2975935 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sat, 27 Dec 2025 14:34:50 +0800 Subject: [PATCH] refactor: pkgs --- flake.nix | 2 +- flake/hosts.nix | 4 +--- pkgs/default.nix => flake/pkgs.nix | 31 +++++++++++------------------- lib/umport.nix | 25 +++++++++++------------- modules/core/nix.nix | 3 +-- 5 files changed, 25 insertions(+), 40 deletions(-) rename pkgs/default.nix => flake/pkgs.nix (71%) diff --git a/flake.nix b/flake.nix index 40004e7..7da276d 100644 --- a/flake.nix +++ b/flake.nix @@ -114,8 +114,8 @@ imports = [ ./flake/hosts.nix + ./flake/pkgs.nix ./treefmt.nix - ./pkgs ./overlays ]; diff --git a/flake/hosts.nix b/flake/hosts.nix index b035823..804492b 100644 --- a/flake/hosts.nix +++ b/flake/hosts.nix @@ -10,9 +10,7 @@ let vars = import ../vars.nix; pkgsModule = { - nixpkgs = pkgsParams // { - inherit (config.nixpkgs.hostPlatform) system; - }; + nixpkgs = pkgsParams; }; hmModule = { home-manager = { diff --git a/pkgs/default.nix b/flake/pkgs.nix similarity index 71% rename from pkgs/default.nix rename to flake/pkgs.nix index 5f51ac6..ad6c657 100644 --- a/pkgs/default.nix +++ b/flake/pkgs.nix @@ -24,19 +24,16 @@ flake.setNixPath = false; }; }; + perSystem = { system, pkgs, ... }: - let - in { _module.args.pkgs = import inputs.nixpkgs (pkgsParams // { inherit system; }); - legacyPackages = pkgs; - packages = lib.genAttrs (builtins.attrNames (config.flake.overlays.additions pkgs pkgs)) ( pkg: pkgs.${pkg} ); @@ -44,21 +41,15 @@ flake.overlays.additions = final: prev: - let - paths = [ - # keep-sorted start - ./fcitx5-lightly - ./jj-starship.nix - ./mono-gtk-theme.nix - ./ttf-wps-fonts.nix - ./wps-office-fonts.nix - # keep-sorted end + with lib.haumea; + load { + src = ../pkgs; + loader = [ + { + matches = str: builtins.match ".*\\.nix" str != null; + loader = _: path: final.callPackage path { }; + } ]; - in - builtins.listToAttrs ( - map (path: { - name = builtins.elemAt (lib.splitString "." (builtins.baseNameOf path)) 0; - value = final.callPackage path { }; - }) paths - ); + transformer = transformers.liftDefault; + }; } diff --git a/lib/umport.nix b/lib/umport.nix index 2f4f58f..54680c5 100644 --- a/lib/umport.nix +++ b/lib/umport.nix @@ -28,20 +28,17 @@ let || extraExcludePredicate path; in unique ( - (filter - (file: pathIsRegularFile file && hasSuffix ".nix" (builtins.toString file) && !isExcluded file) - ( - concatMap ( - path: - if recursive then - toList path - else - mapAttrsToList ( - name: type: path + (if type == "directory" then "/${name}/default.nix" else "/${name}") - ) (builtins.readDir path) - ) (unique (if path == null then paths else [ path ] ++ paths)) - ) - ) + (filter (file: pathIsRegularFile file && hasSuffix ".nix" (toString file) && !isExcluded file) ( + concatMap ( + path: + if recursive then + toList path + else + mapAttrsToList ( + name: type: path + (if type == "directory" then "/${name}/default.nix" else "/${name}") + ) (builtins.readDir path) + ) (unique (if path == null then paths else [ path ] ++ paths)) + )) ++ (if recursive then concatMap (path: toList path) (unique include) else unique include) ); in diff --git a/modules/core/nix.nix b/modules/core/nix.nix index 66fd0bd..d7c3efe 100644 --- a/modules/core/nix.nix +++ b/modules/core/nix.nix @@ -38,8 +38,7 @@ in }) config.nix.registry; nix.settings = { - # Enable flakes and new 'nix' command - experimental-features = "nix-command flakes"; + experimental-features = "nix-command flakes pipe-operators"; substituters = [ "https://mirrors.sjtug.sjtu.edu.cn/nix-channels/store" "https://mirror.sjtu.edu.cn/nix-channels/store"