nixos configs
1{ inputs, ... }:
2
3with inputs.nixpkgs.lib;
4let
5 strToPath =
6 x: path: if builtins.typeOf x == "string" then builtins.toPath ("${toString path}/${x}") else x;
7 strToFile =
8 x: path: if builtins.typeOf x == "string" then builtins.toPath ("${toString path}/${x}.nix") else x;
9in
10rec {
11 mkUserHome =
12 { config }:
13 { lib, pkgs, ... }:
14 {
15 imports = [
16 (import ../home/common)
17 (import ../home/modules)
18 (import ../home/profiles)
19 (import config) # eg. home/hosts/darktower.nix
20 ];
21
22 # For compatibility with nix-shell, nix-build, etc.
23 home.file.".nixpkgs".source = inputs.nixpkgs;
24 home.sessionVariables."NIX_PATH" = "nixpkgs=$HOME/.nixpkgs\${NIX_PATH:+:}$NIX_PATH";
25
26 # dix diff after home-manager activation
27 # TODO also shows diff if nothing changed..
28 home.activation.report-changes = lib.hm.dag.entryAfter [ "installPackages" ] ''
29 PATH=$PATH:${
30 lib.makeBinPath [
31 pkgs.dix
32 pkgs.nix
33 ]
34 }
35 if [[ -d ~/.local/state/nix/profiles ]]; then
36 dix $(find ~/.local/state/nix/profiles -name "home-manager-*-link" -type l | sort -V | tail -2) || echo "No previous home-manager generation found"
37 fi
38 '';
39
40 # set in host? fallback
41 home.stateVersion = "24.05";
42 };
43
44 intoHomeManager =
45 name:
46 {
47 config ? name,
48 user ? "iff",
49 system ? "x86_64-linux",
50 }:
51 let
52 pkgs = inputs.self.pkgsBySystem."${system}";
53 username = user;
54 homeDirectory = if pkgs.stdenv.isDarwin then "/Users/${username}" else "/home/${username}";
55 in
56 nameValuePair name (
57 inputs.home-manager.lib.homeManagerConfiguration {
58 inherit pkgs;
59 modules = [
60 {
61 home = { inherit username homeDirectory; };
62
63 imports =
64 let
65 userConf = strToFile config ../home/hosts;
66 home = mkUserHome { config = userConf; };
67 in
68 [ home ];
69
70 nix = {
71 settings = {
72 substituters = [
73 "https://cache.nixos.org"
74 "https://iff-dotfiles.cachix.org"
75 # "https://cachix.cachix.org"
76 # "https://nix-community.cachix.org"
77 ];
78 trusted-public-keys = [
79 "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
80 "iff-dotfiles.cachix.org-1:9PzCJ44z3MuyvrvjkbbMWCDl5Rrf9nt3OZHq446Wn58="
81 # "cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM="
82 # "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
83 ];
84 };
85 package = pkgs.nixVersions.stable;
86 extraOptions = "experimental-features = nix-command flakes";
87 };
88
89 nixpkgs = {
90 overlays = [ ];
91 };
92 }
93 ];
94 extraSpecialArgs =
95 let
96 self = inputs.self;
97 in
98 {
99 inherit inputs name self;
100 };
101 }
102 );
103
104 intoNixOs =
105 name:
106 {
107 config ? name,
108 user ? "iff",
109 system ? "x86_64-linux",
110 }:
111 nameValuePair name (
112 let
113 pkgs = inputs.self.pkgsBySystem."${system}";
114 in
115 nixosSystem {
116 modules = [
117 (
118 { name, ... }:
119 {
120 networking.hostName = name;
121 }
122 )
123 (
124 { inputs, ... }:
125 {
126 nixpkgs = {
127 inherit pkgs;
128 hostPlatform = system;
129 overlays = [
130 # Waybar overlay for experimental features (used by hyprland/sway profiles)
131 (final: prev: {
132 waybar = prev.waybar.overrideAttrs (oldAttrs: {
133 mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
134 });
135 })
136 ];
137 };
138
139 environment.etc.nixpkgs.source = inputs.nixpkgs;
140 nix.nixPath = [ "nixpkgs=/etc/nixpkgs" ];
141 }
142 )
143 (
144 { pkgs, ... }:
145 {
146 nix = {
147 package = pkgs.nixVersions.latest;
148 extraOptions = "experimental-features = nix-command flakes";
149 };
150 }
151 )
152 (
153 { inputs, ... }:
154 {
155 # re-expose self and nixpkgs as flakes.
156 nix.registry = {
157 self.flake = inputs.self;
158 nixpkgs = {
159 from = {
160 id = "nixpkgs";
161 type = "indirect";
162 };
163 flake = inputs.nixpkgs;
164 };
165 };
166 }
167 )
168 (
169 { ... }:
170 {
171 system.stateVersion = "24.05";
172 }
173 )
174 (inputs.home-manager.nixosModules.home-manager)
175 ({
176 home-manager = {
177 useGlobalPkgs = true;
178 extraSpecialArgs =
179 let
180 self = inputs.self;
181 in
182 # NOTE: Cannot pass name to home-manager as it passes `name` in to set the `hmModule`
183 {
184 inherit inputs self user;
185 };
186 };
187 })
188 (import ../system/nixos/profiles)
189 (import (strToPath config ../system/nixos/hosts))
190 ];
191 specialArgs =
192 let
193 self = inputs.self;
194 in
195 {
196 inherit
197 inputs
198 name
199 self
200 user
201 ;
202 };
203 }
204 );
205}