/
default.nix
60 lines (55 loc) · 1.92 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
Nix-the-package-manager configuration.
Pins a couple of commonly used flake registry points as "ns" for stable and "nu" for unstable. This is useful to prevent extra nixpkgs downloads when running one-off commands in `nix run`
Development packages will be pulled into the package set. The set (environment.systemPackages or home.packages) is picked depending on whether this module is run in home-manager or NixOS context.
*/
# TODO: move to flake-modules so 'inHomeManager' is not exposed to caller
{
nixpkgs-stable,
nixpkgs-unstable,
inHomeManager ? false,
inputs,
}:
{
pkgs,
config,
lib,
...
}:
let
outer = if inHomeManager then "home" else "environment";
inner = if inHomeManager then "packages" else "systemPackages";
inherit (lib) mapAttrs' nameValuePair filterAttrs;
in
{
# Allow unfree packages across the board
nixpkgs.config.allowUnfree = true;
nix = {
extraOptions = ''
# Quicker timeout for inaccessible binary caches
connect-timeout = 5
# Enable flakes
experimental-features = nix-command flakes
# Do not warn on dirty git repo
warn-dirty = false
# Automatically optimize store
auto-optimise-store = true
'';
registry =
{
ns.flake = nixpkgs-stable;
nu.flake = nixpkgs-unstable;
}
# Since my systems have a single global flake that governs them, I can pin all its inputs in the local registry for fast reuse in flake.lock.
# Usage example:
# in another flake.nix
# inputs.devshell.url = "pinned-devshell"
# inputs.nixpkgs.url = "pinned-nixpkgs"
# ...
// lib.pipe inputs [
(filterAttrs (_: v: (v ? _type && v._type == "flake"))) # Filter only flakes in inputs
(mapAttrs' (a: v: nameValuePair ("pinned-" + a) { flake = v; })) # Turn them into proper entries in registry
];
};
${outer}.${inner} = builtins.attrValues { inherit (pkgs) nix-melt nix-top; };
}