2023-02-21 18:24:18 +01:00
|
|
|
# Nix related settings
|
2023-05-03 18:54:23 +02:00
|
|
|
{ config, inputs, lib, pkgs, ... }:
|
2023-02-21 18:24:18 +01:00
|
|
|
let
|
|
|
|
cfg = config.my.home.nix;
|
2023-02-25 02:32:09 +01:00
|
|
|
|
|
|
|
channels = lib.my.merge [
|
|
|
|
{
|
|
|
|
# Allow me to use my custom package using `nix run self#pkg`
|
|
|
|
self = inputs.self;
|
|
|
|
# Add NUR to run some packages that are only present there
|
|
|
|
nur = inputs.nur;
|
|
|
|
# Use pinned nixpkgs when using `nix run pkgs#<whatever>`
|
|
|
|
pkgs = inputs.nixpkgs;
|
|
|
|
}
|
2024-02-12 12:39:13 +01:00
|
|
|
(lib.optionalAttrs cfg.inputs.overrideNixpkgs {
|
2023-02-25 02:32:09 +01:00
|
|
|
# ... And with `nix run nixpkgs#<whatever>`
|
|
|
|
nixpkgs = inputs.nixpkgs;
|
|
|
|
})
|
|
|
|
];
|
2023-02-21 18:24:18 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.home.nix = with lib; {
|
|
|
|
enable = my.mkDisableOption "nix configuration";
|
|
|
|
|
2024-10-21 12:07:21 +02:00
|
|
|
gc = {
|
|
|
|
enable = my.mkDisableOption "nix GC configuration";
|
|
|
|
};
|
|
|
|
|
2024-02-12 12:40:09 +01:00
|
|
|
cache = {
|
|
|
|
selfHosted = my.mkDisableOption "self-hosted cache";
|
|
|
|
};
|
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
inputs = {
|
2024-05-24 16:08:10 +02:00
|
|
|
link = my.mkDisableOption "link inputs to `$XDG_CONFIG_HOME/nix/inputs/`";
|
2023-02-25 02:41:25 +01:00
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
addToRegistry = my.mkDisableOption "add inputs and self to registry";
|
2023-02-21 18:24:18 +01:00
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
addToNixPath = my.mkDisableOption "add inputs and self to nix path";
|
2023-03-30 11:58:46 +02:00
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
overrideNixpkgs = my.mkDisableOption "point nixpkgs to pinned system version";
|
|
|
|
};
|
2023-02-21 18:24:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
2023-03-30 11:58:46 +02:00
|
|
|
{
|
|
|
|
assertions = [
|
|
|
|
{
|
2024-02-12 12:39:13 +01:00
|
|
|
assertion = cfg.inputs.addToNixPath -> cfg.inputs.link;
|
2023-03-30 11:58:46 +02:00
|
|
|
message = ''
|
|
|
|
enabling `my.home.nix.addToNixPath` needs to have
|
|
|
|
`my.home.nix.linkInputs = true`
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-02-21 18:24:18 +01:00
|
|
|
{
|
|
|
|
nix = {
|
2023-02-25 02:30:28 +01:00
|
|
|
package = lib.mkDefault pkgs.nix; # NixOS module sets it unconditionally
|
2023-02-21 18:24:18 +01:00
|
|
|
|
|
|
|
settings = {
|
|
|
|
experimental-features = [ "nix-command" "flakes" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-10-21 12:07:21 +02:00
|
|
|
(lib.mkIf cfg.gc.enable {
|
|
|
|
nix.gc = {
|
|
|
|
automatic = true;
|
|
|
|
|
|
|
|
# Every week, with some wiggle room
|
|
|
|
frequency = "weekly";
|
|
|
|
randomizedDelaySec = "10min";
|
|
|
|
|
|
|
|
# Use a persistent timer for e.g: laptops
|
|
|
|
persistent = true;
|
|
|
|
|
|
|
|
# Delete old profiles automatically after 15 days
|
|
|
|
options = "--delete-older-than 15d";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-02-12 12:40:09 +01:00
|
|
|
(lib.mkIf cfg.cache.selfHosted {
|
|
|
|
nix = {
|
|
|
|
settings = {
|
2024-02-15 17:58:54 +01:00
|
|
|
extra-substituters = [
|
2024-02-12 12:40:09 +01:00
|
|
|
"https://cache.belanyi.fr/"
|
|
|
|
];
|
|
|
|
|
2024-02-15 17:58:54 +01:00
|
|
|
extra-trusted-public-keys = [
|
2024-02-12 12:40:09 +01:00
|
|
|
"cache.belanyi.fr:LPhrTqufwfxTceg1nRWueDWf7/2zSVY9K00pq2UI7tw="
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
(lib.mkIf cfg.inputs.addToRegistry {
|
2023-02-25 02:32:09 +01:00
|
|
|
nix.registry =
|
|
|
|
let
|
|
|
|
makeEntry = v: { flake = v; };
|
|
|
|
makeEntries = lib.mapAttrs (lib.const makeEntry);
|
|
|
|
in
|
|
|
|
makeEntries channels;
|
2023-02-21 18:24:18 +01:00
|
|
|
})
|
2023-02-25 02:41:25 +01:00
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
(lib.mkIf cfg.inputs.link {
|
2023-02-25 02:41:25 +01:00
|
|
|
xdg.configFile =
|
|
|
|
let
|
|
|
|
makeLink = n: v: {
|
|
|
|
name = "nix/inputs/${n}";
|
|
|
|
value = { source = v.outPath; };
|
|
|
|
};
|
|
|
|
makeLinks = lib.mapAttrs' makeLink;
|
|
|
|
in
|
|
|
|
makeLinks channels;
|
|
|
|
})
|
2023-03-30 11:58:46 +02:00
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
(lib.mkIf cfg.inputs.addToNixPath {
|
2024-06-18 11:21:42 +02:00
|
|
|
nix.nixPath = [ "${config.xdg.configHome}/nix/inputs" ];
|
2023-03-30 11:58:46 +02:00
|
|
|
})
|
2023-02-21 18:24:18 +01:00
|
|
|
]);
|
|
|
|
}
|