From 1fa95e0d84607ae0f9f8577c167e90c973b8f3ae Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Mon, 5 Feb 2024 23:10:00 -0800 Subject: [PATCH] Add support for configuring legacyPackages --- API_GUIDE.md | 38 +++++++++++++++++++++++++++++++ builtinModules/legacyPackages.nix | 19 ++++++++++++++++ tests/default.nix | 16 +++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 builtinModules/legacyPackages.nix diff --git a/API_GUIDE.md b/API_GUIDE.md index 6a1126a..1844946 100644 --- a/API_GUIDE.md +++ b/API_GUIDE.md @@ -711,6 +711,44 @@ For example: } ``` +### legacyPackages + +``` +Type: Pkgs -> Pkgs +``` + +The `legacyPackages` option allows you to configure the flake's `legacyPackges` +output. It can be set to a function that takes the package set and returns the +package set to be used as the corresponding system's legacyPackages output. + +For example: + +```nix +{ + inputs = { + flakelight.url = "github:nix-community/flakelight"; + nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + }; + outputs = { flakelight, nixpkgs, ... }: + flakelight ./. { + legacyPackages = pkgs: nixpkgs.legacyPackages.${pkgs.system}; + }; +} +``` + +To export the package set used for calling package definitions and other options +that take functions passed the package set, you can do the following: + +```nix +{ + inputs.flakelight.url = "github:nix-community/flakelight"; + outputs = { flakelight, ... }: + flakelight ./. { + legacyPackages = pkgs: pkgs; + }; +} +``` + ### formatter ``` diff --git a/builtinModules/legacyPackages.nix b/builtinModules/legacyPackages.nix new file mode 100644 index 0000000..1169926 --- /dev/null +++ b/builtinModules/legacyPackages.nix @@ -0,0 +1,19 @@ +# flakelight -- Framework for simplifying flake setup +# Copyright (C) 2023 Archit Gupta +# SPDX-License-Identifier: MIT + +{ config, lib, genSystems, ... }: +let + inherit (lib) mkIf mkOption; + inherit (lib.types) functionTo nullOr pkgs; +in +{ + options.legacyPackages = mkOption { + type = nullOr (functionTo pkgs); + default = null; + }; + + config.outputs = mkIf (config.legacyPackages != null) { + legacyPackages = genSystems config.legacyPackages; + }; +} diff --git a/tests/default.nix b/tests/default.nix index ab93525..ba5489a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -287,6 +287,22 @@ in }) (f: (import f.packages.x86_64-linux.pkg2)); + legacyPackages-set-pkgs = test + (flakelight ./empty { + inputs = { inherit nixpkgs; }; + legacyPackages = pkgs: pkgs; + }) + (f: f.legacyPackages.x86_64-linux.hello + == nixpkgs.legacyPackages.x86_64-linux.hello); + + legacyPackages-set-nixpkgs = test + (flakelight ./empty { + inputs = { inherit nixpkgs; }; + legacyPackages = pkgs: nixpkgs.legacyPackages.${pkgs.system}; + }) + (f: f.legacyPackages.x86_64-linux.hello + == nixpkgs.legacyPackages.x86_64-linux.hello); + devShell = test (flakelight ./empty { devShell = {