You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
server/nix/nixos-modules/autoUnfree.nix

92 lines
2.5 KiB
Nix

{
config,
lib,
pkgs,
...
3 months ago
}:
let
cfg = config.x-banananetwork.autoUnfree;
in
{
options = {
x-banananetwork.autoUnfree = {
enable = lib.mkEnableOption ''
automatically allowing unfree packages
based on other NixOS modules options.
This should make it easier to allow unfree packages,
being kind of a replacement of generelly enabling
option{nixpkgs.config.allowUnfree}.
Through this module aims to be more restrictive
as it only enables packages used by modules
which are enabled in the hosts configuration.
Be aware that this module may not support all modules installed in nixpkgs.
And be aware that this module blocks the option
option{nixpkgs.config.allowUnfreePredicate} for other uses.
Other modules can add support on their own
by using the option{x-banananetwork.autoUnfree.packages} option.
'';
packages = lib.mkOption {
description = ''
Lists all packages which should be allowed to be installed
despite of them being unfree.
Only works when option{x-banananetwork.autoUnfree.enable} is set to true.
This option is mainly intended to be used by other module developers
to add support for this on their own.
Users may also use this additionally allow packages on their own.
'';
type = lib.types.listOf lib.types.package;
default = [ ];
example = lib.literalExpression ''
3 months ago
with pkgs; [
vscode
] ++ with lib.lists; flatten [
# just as an example, this is already supported internally
(optional config.programs.steam.enable config.programs.steam.package)
]
'';
};
};
};
config = lib.mkIf cfg.enable {
3 months ago
nixpkgs.config = {
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) (map lib.getName cfg.packages);
};
# TODO add alternative for allowUnfreePredicate for users
x-banananetwork.autoUnfree.packages =
let
inherit (lib.lists) flatten optional optionals;
3 months ago
# supported (ordered by long option name)
steam = config.programs.steam;
in
flatten [
# programs
(optional steam.enable steam.package)
# TODO improve pulling in dependencies more accurate
(optionals steam.enable ([
pkgs.steam-run
pkgs.steamPackages.steam
pkgs.steamPackages.steam-runtime
]))
3 months ago
];
};
}