system/machines/modules/nix.nix

52 lines
1.2 KiB
Nix

{ lib, config, ... }:
let
inherit (builtins) elem;
cfg = config.local.nix;
in
{
options.local.nix = with lib; {
enableMyRegistry = mkOption {
type = types.bool;
default = false;
description = "Enable my custom nix registry";
};
allowUnfreePackages = mkOption {
type = types.listOf types.str;
default = [ ];
};
};
config = {
nixpkgs.config.allowUnfreePredicate = lib.mkIf
(cfg.allowUnfreePackages != [ ])
(pkg: elem (lib.getName pkg) cfg.allowUnfreePackages);
nix = {
settings = {
auto-optimise-store = true;
trusted-users = [ "root" ];
experimental-features = [ "nix-command" "flakes" ];
# To protect nix-shell against garbage collection
# Source: https://github.com/nix-community/nix-direnv#installation
keep-derivations = true;
keep-outputs = true;
};
registry = lib.mkIf cfg.enableMyRegistry (
let
gitple = "https://git.pleshevski.ru";
mkRegistry = id: url: {
from = { type = "indirect"; inherit id; };
to = { type = "git"; inherit url; };
};
in
{ templates = mkRegistry "tmpl" "${gitple}/mynix/templates"; }
);
};
};
}