diff options
| author | Seth Flynn <[email protected]> | 2025-01-28 07:23:40 -0500 |
|---|---|---|
| committer | Seth Flynn <[email protected]> | 2025-01-28 07:58:44 -0500 |
| commit | 943dc8b295ca1a333c15a5c0fe5bd90cb5a980af (patch) | |
| tree | a23ac93782732e4d239c2aa9c5b1539717e463cc | |
| parent | 988962c3fda908905892ebd452f1b85680ed2b99 (diff) | |
treewide: simplify package calling logic
| -rw-r--r-- | default.nix | 21 | ||||
| -rw-r--r-- | flake.nix | 68 |
2 files changed, 31 insertions, 58 deletions
diff --git a/default.nix b/default.nix index 25178be..2aebc73 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,7 @@ let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + { pkgs ? import nixpkgs { config = { }; @@ -15,20 +16,14 @@ in ), system ? builtins.currentSystem, }: + let inherit (pkgs) lib; - packageDirectory = ./pkgs; - scope = lib.makeScope pkgs.newScope ( - final: - lib.packagesFromDirectoryRecursive { - inherit (final) callPackage; - directory = packageDirectory; - } - ); - - # Filter extraneous attributes from the scope, based on the files in our package directory - packageFileNames = builtins.attrNames (builtins.readDir packageDirectory); - packages = lib.getAttrs packageFileNames scope; + getchpkgs = lib.packagesFromDirectoryRecursive { + callPackage = lib.callPackageWith (pkgs // getchpkgs); + directory = ./pkgs; + }; in -packages + +getchpkgs @@ -9,38 +9,21 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; outputs = - { - self, - nixpkgs, - }: + { self, nixpkgs }: + let inherit (nixpkgs) lib; # Support all systems exported by Nixpkgs systems = lib.systems.flakeExposed; # But separate our primarily supported systems - tier1Systems = with lib.platforms; lib.intersectLists (aarch64 ++ aarch64) (darwin ++ linux); + tier1Systems = with lib.platforms; lib.intersectLists (aarch64 ++ x86_64) (darwin ++ linux); forAllSystems = lib.genAttrs systems; forTier1Systems = lib.genAttrs tier1Systems; nixpkgsFor = nixpkgs.legacyPackages; - - mkModule = - { - name, - type, - imports, - ... - }@args: - { - _file = "${self.outPath}/flake.nix#${type}Modules.${name}"; - inherit imports; - } - // lib.removeAttrs args [ - "name" - "type" - ]; in + { checks = forTier1Systems ( system: @@ -60,39 +43,34 @@ packages = forAllSystems ( system: + let pkgs = nixpkgsFor.${system}; - isAvailable = lib.meta.availableOn { inherit system; }; - pkgs' = lib.filterAttrs (lib.const isAvailable) (import ./default.nix { inherit pkgs; }); + getchpkgs = import ./default.nix { inherit pkgs; }; + + getchpkgs' = lib.filterAttrs (lib.const ( + deriv: + let + isCross = deriv.stdenv.buildPlatform != deriv.stdenv.hostPlatform; + availableOnHost = lib.meta.availableOn pkgs.stdenv.hostPlatform deriv; + # `nix flake check` doesn't like broken packages + isBroken = deriv.meta.broken or false; + in + isCross || availableOnHost && (!isBroken) + )) getchpkgs; in - pkgs' // { default = pkgs'.treefetch or pkgs.emptyFile; } + + getchpkgs' // { default = getchpkgs'.treefetch or pkgs.emptyFile; } ); flakeModules = { - checks = mkModule { - name = "checks"; - type = "flake"; - imports = [ ./modules/flake/checks.nix ]; - key = "${self.outPath}/flake.nix#flakeModules.checks"; - _class = "flake"; - }; - - configs = mkModule { - name = "configs"; - type = "flake"; - imports = [ ./modules/flake/configs.nix ]; - key = "${self.outPath}/flake.nix#flakeModules.configs"; - _class = "flake"; - }; + checks = self + "./modules/flake/checks.nix"; + configs = self + "./modules/flake/configs.nix"; }; homeModules = { - riff = mkModule { - name = "riff"; - type = "home"; - imports = [ ./modules/home/riff.nix ]; - }; + riff = self + "/modules/home/riff.nix"; }; formatter = forTier1Systems (system: nixpkgsFor.${system}.nixfmt-rfc-style); @@ -100,7 +78,7 @@ templates = let toTemplate = name: description: { - path = ./templates + "/${name}"; + path = self + "/templates/${name}"; inherit description; }; in |
