-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
139 lines (116 loc) · 4.31 KB
/
flake.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
description = "HanStolpo's NixOS systems flake";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11;
nixpkgs-unstable.url = github:NixOS/nixpkgs/nixos-unstable;
kmonad = {
url = "github:kmonad/kmonad?dir=nix";
inputs.nixpkgs.follows = "nixpkgs";
};
haswaynav = {
url = "github:hanstolpo/haswaynav";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixpkgs-unstable, kmonad, haswaynav, ... }:
let
# helper to apply a function to all entries in a directory
# loading `name/default.nix`, similar to what import would do,
# if the entry is a directory
mapImports = dir: fn: with builtins; with nixpkgs.lib;
let
noNulls = filterAttrs (_: v: v != null);
applyFn = n: v:
let path = "${toString dir}/${n}"; in
if v == "directory" && pathExists "${path}/default.nix"
then nameValuePair n (fn path)
else if v == "regular" &&
hasSuffix ".nix" n
then nameValuePair (removeSuffix ".nix" n) (fn path)
else nameValuePair "" null
;
in
noNulls (mapAttrs' applyFn (readDir dir));
in
rec {
# all my custom overlays
overlays = {
# we make the unstable packages available to the other overlays / modules
pkgs-unstable =
final: prev: {
pkgs-unstable = import nixpkgs-unstable {
system = final.system;
config.allowUnfree = true;
};
};
} // mapImports ./overlays import;
# expose any custom packages from our overlays to make developing on them easier
# e.g. you can `nix build ./#<custom_package_name>` to build the derivation
packages.x86_64-linux =
let
pkgs = import nixpkgs {
system = "x86_64-linux";
config.allowUnfree = true;
overlays = builtins.attrValues self.overlays;
};
in
{
inherit (pkgs) d2 tala realvnc-viewer tree-sitter mdsync swayJournald;
inherit (pkgs.tree-sitter-grammars) tree-sitter-d2;
};
# check that our custom packages can still be built
checks.x86_64-linux = packages.x86_64-linux;
# my configurations are broken up into modules which the different hosts enable / configure as desired.
nixosModules = mapImports ./modules import;
# the nixos system configurations that can be extended
# from another flake
nixosSystems =
let
hostCommonSetup = { pkgs, ... }: {
# Let 'nixos-version --json' know about the Git revision of this flake.
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
nixpkgs = {
config.allowUnfree = true;
overlays = builtins.attrValues self.overlays ++ [ haswaynav.overlays.default kmonad.overlays.default ];
};
nix = {
registry.nixpkgs.flake = nixpkgs;
settings = {
sandbox = "relaxed";
};
extraOptions = ''
experimental-features = nix-command flakes recursive-nix
allow-import-from-derivation = true
# some defaults as suggested here: https://jackson.dev/post/nix-reasonable-defaults/
# Almost always set
connect-timeout = 5
log-lines = 25
min-free = 128000000
max-free = 1000000000
# Set if understood
experimental-features = nix-command flakes
fallback = true
warn-dirty = false
auto-optimise-store = true
# Set for developers
keep-outputs = true
'';
};
};
mkHost = host: {
system = "x86_64-linux";
modules =
builtins.attrValues self.nixosModules ++
[
kmonad.nixosModules.default
hostCommonSetup
(import host)
];
};
in
mapImports ./hosts mkHost;
# The configurations for each one of my hosts
nixosConfigurations =
nixpkgs.lib.mapAttrs (_: s: nixpkgs.lib.nixosSystem s) nixosSystems;
};
}