2021-02-06 15:35:38 +01:00
|
|
|
# Nix related settings
|
2021-12-22 23:47:27 +01:00
|
|
|
{ config, inputs, lib, options, pkgs, ... }:
|
2021-05-29 20:28:27 +02:00
|
|
|
let
|
|
|
|
cfg = config.my.system.nix;
|
2023-02-25 02:03:42 +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;
|
|
|
|
}
|
2023-05-01 19:43:29 +02:00
|
|
|
(lib.optionalAttrs cfg.inputs.overrideNixpkgs {
|
2023-02-25 02:03:42 +01:00
|
|
|
# ... And with `nix run nixpkgs#<whatever>`
|
|
|
|
nixpkgs = inputs.nixpkgs;
|
|
|
|
})
|
|
|
|
];
|
2021-05-29 20:28:27 +02:00
|
|
|
in
|
2021-02-06 15:35:38 +01:00
|
|
|
{
|
2021-05-29 20:28:27 +02:00
|
|
|
options.my.system.nix = with lib; {
|
|
|
|
enable = my.mkDisableOption "nix configuration";
|
|
|
|
|
2024-10-21 12:06:48 +02:00
|
|
|
gc = {
|
|
|
|
enable = my.mkDisableOption "nix GC configuration";
|
|
|
|
};
|
|
|
|
|
2023-05-01 20:08:31 +02:00
|
|
|
cache = {
|
|
|
|
selfHosted = my.mkDisableOption "self-hosted cache";
|
|
|
|
};
|
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
inputs = {
|
|
|
|
link = my.mkDisableOption "link inputs to `/etc/nix/inputs/`";
|
2023-02-20 22:26:51 +01:00
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
addToRegistry = my.mkDisableOption "add inputs and self to registry";
|
2021-12-22 23:47:27 +01:00
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
addToNixPath = my.mkDisableOption "add inputs and self to nix path";
|
2023-02-11 12:03:32 +01:00
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
overrideNixpkgs = my.mkDisableOption "point nixpkgs to pinned system version";
|
|
|
|
};
|
2021-02-06 15:35:38 +01:00
|
|
|
};
|
2021-05-29 20:28:27 +02:00
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
2023-02-23 22:00:30 +01:00
|
|
|
{
|
|
|
|
assertions = [
|
|
|
|
{
|
2023-05-01 19:43:29 +02:00
|
|
|
assertion = cfg.inputs.addToNixPath -> cfg.inputs.link;
|
2023-02-23 22:00:30 +01:00
|
|
|
message = ''
|
2023-05-01 19:43:29 +02:00
|
|
|
enabling `my.system.nix.inputs.addToNixPath` needs to have
|
|
|
|
`my.system.nix.inputs.link = true`
|
2023-02-23 22:00:30 +01:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-05-29 20:28:27 +02:00
|
|
|
{
|
|
|
|
nix = {
|
2022-09-29 21:58:48 +02:00
|
|
|
package = pkgs.nix;
|
2021-05-29 20:28:27 +02:00
|
|
|
|
2022-02-08 14:32:00 +01:00
|
|
|
settings = {
|
|
|
|
experimental-features = [ "nix-command" "flakes" ];
|
2024-03-01 21:48:44 +01:00
|
|
|
# Trusted users are equivalent to root, and might as well allow wheel
|
|
|
|
trusted-users = [ "root" "@wheel" ];
|
2022-02-08 14:32:00 +01:00
|
|
|
};
|
2021-05-29 20:28:27 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-10-21 12:06:48 +02:00
|
|
|
(lib.mkIf cfg.gc.enable {
|
|
|
|
nix.gc = {
|
|
|
|
automatic = true;
|
|
|
|
|
|
|
|
# Every week, with some wiggle room
|
|
|
|
dates = "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";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2023-05-01 20:08:31 +02:00
|
|
|
(lib.mkIf cfg.cache.selfHosted {
|
|
|
|
nix = {
|
|
|
|
settings = {
|
|
|
|
# The NixOS module adds the official Hydra cache by default
|
|
|
|
# No need to use `extra-*` options.
|
|
|
|
substituters = [
|
|
|
|
"https://cache.belanyi.fr/"
|
|
|
|
];
|
|
|
|
|
|
|
|
trusted-public-keys = [
|
|
|
|
"cache.belanyi.fr:LPhrTqufwfxTceg1nRWueDWf7/2zSVY9K00pq2UI7tw="
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
(lib.mkIf cfg.inputs.addToRegistry {
|
2023-02-25 02:03:42 +01:00
|
|
|
nix.registry =
|
|
|
|
let
|
|
|
|
makeEntry = v: { flake = v; };
|
|
|
|
makeEntries = lib.mapAttrs (lib.const makeEntry);
|
|
|
|
in
|
|
|
|
makeEntries channels;
|
2021-05-29 20:28:27 +02:00
|
|
|
})
|
2021-12-22 23:47:27 +01:00
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
(lib.mkIf cfg.inputs.link {
|
2023-02-20 22:26:51 +01:00
|
|
|
environment.etc =
|
|
|
|
let
|
|
|
|
makeLink = n: v: {
|
|
|
|
name = "nix/inputs/${n}";
|
|
|
|
value = { source = v.outPath; };
|
|
|
|
};
|
|
|
|
makeLinks = lib.mapAttrs' makeLink;
|
|
|
|
in
|
2023-02-24 10:25:38 +01:00
|
|
|
makeLinks channels;
|
2023-02-20 22:26:51 +01:00
|
|
|
})
|
|
|
|
|
2023-05-01 19:43:29 +02:00
|
|
|
(lib.mkIf cfg.inputs.addToNixPath {
|
2023-02-11 11:53:52 +01:00
|
|
|
nix.nixPath = [
|
2023-02-24 10:26:06 +01:00
|
|
|
"/etc/nix/inputs"
|
2023-02-11 12:03:32 +01:00
|
|
|
]
|
2023-02-11 11:53:52 +01:00
|
|
|
++ options.nix.nixPath.default;
|
2021-12-22 23:47:27 +01:00
|
|
|
})
|
2021-05-29 20:28:27 +02:00
|
|
|
]);
|
2021-02-06 15:35:38 +01:00
|
|
|
}
|