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;
|
|
|
|
}
|
|
|
|
(lib.optionalAttrs cfg.overrideNixpkgs {
|
|
|
|
# ... 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";
|
|
|
|
|
2023-02-20 22:26:51 +01:00
|
|
|
linkInputs = my.mkDisableOption "link inputs to `/etc/nix/inputs/`";
|
|
|
|
|
2021-05-29 20:28:27 +02:00
|
|
|
addToRegistry = my.mkDisableOption "add inputs and self to registry";
|
2021-12-22 23:47:27 +01:00
|
|
|
|
|
|
|
addToNixPath = my.mkDisableOption "add inputs and self to nix path";
|
2023-02-11 12:03:32 +01: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 = [
|
|
|
|
{
|
|
|
|
assertion = cfg.addToNixPath -> cfg.linkInputs;
|
|
|
|
message = ''
|
|
|
|
enabling `my.system.nix.addToNixPath` needs to have
|
|
|
|
`my.system.nix.linkInputs = true`
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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" ];
|
|
|
|
};
|
2021-05-29 20:28:27 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
(lib.mkIf cfg.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-02-20 22:26:51 +01:00
|
|
|
(lib.mkIf cfg.linkInputs {
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-12-22 23:47:27 +01:00
|
|
|
(lib.mkIf cfg.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
|
|
|
}
|