mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-22 15:33:10 +01:00
543e3aaa4d
`nullOr`'s merge function requires definitions to all be null or all be non-null. It was being used where the intent was that null be used as a value representing unset, and as such the merge should return null if all definitions are null and ignore nulls otherwise. This adds a type with that merge semantics.
50 lines
1.5 KiB
Nix
50 lines
1.5 KiB
Nix
# flakelight -- Framework for simplifying flake setup
|
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
{ config, src, lib, inputs, outputs, flakelight, moduleArgs, ... }:
|
|
let
|
|
inherit (lib) isList mkOption mkOrder mapAttrs optionalAttrs;
|
|
inherit (lib.types) listOf oneOf str;
|
|
inherit (builtins) pathExists;
|
|
inherit (flakelight) selectAttr;
|
|
inherit (flakelight.types) nullable;
|
|
in
|
|
{
|
|
options = {
|
|
description = mkOption {
|
|
type = nullable str;
|
|
default =
|
|
if pathExists (src + /flake.nix)
|
|
then (import (src + /flake.nix)).description or null
|
|
else null;
|
|
};
|
|
|
|
license = mkOption {
|
|
type = nullable (oneOf [ str (listOf str) ]);
|
|
default = null;
|
|
};
|
|
};
|
|
|
|
config.withOverlays = mkOrder 10 (final: prev:
|
|
let inherit (prev.stdenv.hostPlatform) system; in {
|
|
inherit system moduleArgs src inputs outputs flakelight;
|
|
inputs' = mapAttrs (_: selectAttr system) inputs;
|
|
outputs' = selectAttr system outputs;
|
|
|
|
defaultMeta = {
|
|
platforms = config.systems;
|
|
} // optionalAttrs (config.description != null) {
|
|
inherit (config) description;
|
|
} // optionalAttrs (config.license != null) {
|
|
license =
|
|
let
|
|
getLicense = license: final.lib.licenses.${license} or
|
|
(final.lib.meta.getLicenseFromSpdxId license);
|
|
in
|
|
if isList config.license then map getLicense config.license
|
|
else getLicense config.license;
|
|
};
|
|
});
|
|
}
|