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-02-12 12:40:09 +01:00
|
|
|
cache = {
|
|
|
|
selfHosted = my.mkDisableOption "self-hosted cache";
|
|
|
|
};
|
|
|
|
|
2024-02-12 12:39:13 +01:00
|
|
|
inputs = {
|
|
|
|
link = my.mkDisableOption "link inputs to `/etc/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-02-12 12:40:09 +01: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="
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
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 {
|
2023-03-30 11:58:46 +02:00
|
|
|
home.sessionVariables.NIX_PATH = "${config.xdg.configHome}/nix/inputs\${NIX_PATH:+:$NIX_PATH}";
|
|
|
|
})
|
2023-02-21 18:24:18 +01:00
|
|
|
]);
|
|
|
|
}
|