nix-config/modules/home/nix/default.nix
Bruno BELANYI b2a199c9a0
All checks were successful
ci/woodpecker/push/check Pipeline was successful
home: nix: fix cache configuration
Copy-paste is bad kids, the home-manager module does *not* do the same
as NixOS.

I was rebuilding the world, since this was overriding the official Hydra
cache...
2024-02-15 17:09:56 +00:00

103 lines
2.5 KiB
Nix

# Nix related settings
{ config, inputs, lib, pkgs, ... }:
let
cfg = config.my.home.nix;
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;
}
(lib.optionalAttrs cfg.inputs.overrideNixpkgs {
# ... And with `nix run nixpkgs#<whatever>`
nixpkgs = inputs.nixpkgs;
})
];
in
{
options.my.home.nix = with lib; {
enable = my.mkDisableOption "nix configuration";
cache = {
selfHosted = my.mkDisableOption "self-hosted cache";
};
inputs = {
link = my.mkDisableOption "link inputs to `/etc/nix/inputs/`";
addToRegistry = my.mkDisableOption "add inputs and self to registry";
addToNixPath = my.mkDisableOption "add inputs and self to nix path";
overrideNixpkgs = my.mkDisableOption "point nixpkgs to pinned system version";
};
};
config = lib.mkIf cfg.enable (lib.mkMerge [
{
assertions = [
{
assertion = cfg.inputs.addToNixPath -> cfg.inputs.link;
message = ''
enabling `my.home.nix.addToNixPath` needs to have
`my.home.nix.linkInputs = true`
'';
}
];
}
{
nix = {
package = lib.mkDefault pkgs.nix; # NixOS module sets it unconditionally
settings = {
experimental-features = [ "nix-command" "flakes" ];
};
};
}
(lib.mkIf cfg.cache.selfHosted {
nix = {
settings = {
extra-substituters = [
"https://cache.belanyi.fr/"
];
extra-trusted-public-keys = [
"cache.belanyi.fr:LPhrTqufwfxTceg1nRWueDWf7/2zSVY9K00pq2UI7tw="
];
};
};
})
(lib.mkIf cfg.inputs.addToRegistry {
nix.registry =
let
makeEntry = v: { flake = v; };
makeEntries = lib.mapAttrs (lib.const makeEntry);
in
makeEntries channels;
})
(lib.mkIf cfg.inputs.link {
xdg.configFile =
let
makeLink = n: v: {
name = "nix/inputs/${n}";
value = { source = v.outPath; };
};
makeLinks = lib.mapAttrs' makeLink;
in
makeLinks channels;
})
(lib.mkIf cfg.inputs.addToNixPath {
home.sessionVariables.NIX_PATH = "${config.xdg.configHome}/nix/inputs\${NIX_PATH:+:$NIX_PATH}";
})
]);
}