blob: ec942a097aae0da48f4d1b8d41d1ad51f9a43c05 [file] [log] [blame]
Skyler Grey0409e462022-08-19 23:40:48 +01001{
2 description = "Minion's NixOS configuration (since 2022-08-19)";
Skyler Greybcb2cb72022-08-21 07:24:35 +01003 inputs = {
4 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
Skyler Grey2f9904e2022-09-05 03:18:02 +01005 nixpkgs-minion.url = "github:Minion3665/nixpkgs";
Skyler Greybcc63992023-01-25 21:43:55 +00006 nixpkgs-coc-spellchecker.url = "github:Minion3665/nixpkgs/coc-spell-checker-staging";
Skyler Greyd01ca9c2022-11-02 08:08:32 +00007 nixpkgs-staging-next.url = "github:NixOS/nixpkgs/staging-next";
Skyler Greybcb2cb72022-08-21 07:24:35 +01008 flake-utils.url = "github:numtide/flake-utils";
Skyler Grey6be25172022-10-30 22:58:55 +00009 flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
Skyler Grey2a7ca382022-09-01 23:15:31 +010010 vscode-extensions.url = "github:AmeerTaweel/nix-vscode-marketplace";
Skyler Greybcb2cb72022-08-21 07:24:35 +010011 registry = {
12 url = "github:nixos/flake-registry";
13 flake = false;
14 };
Skyler Greyf8f06532022-11-04 10:58:38 +000015 home-manager.url = "github:nix-community/home-manager";
Skyler Greybcb2cb72022-08-21 07:24:35 +010016 sops-nix.url = "github:Mic92/sops-nix";
17 impermanence.url = "github:nix-community/impermanence";
Skyler Grey2a7ca382022-09-01 23:15:31 +010018 gtimelog = {
19 url = "git+https://gitlab.collabora.com/collabora/gtimelog.git";
20 flake = false;
21 };
Skyler Grey934f1422022-09-04 11:50:04 +010022 fzf-tab = {
23 url = "github:Aloxaf/fzf-tab";
24 flake = false;
25 };
Skyler Greya589ea12022-10-31 00:03:57 +000026 omnisharp-language-server = {
27 url = "github:coc-extensions/coc-omnisharp";
28 flake = false;
29 };
30 kmonad = {
31 url = "github:kmonad/kmonad?dir=nix";
32 inputs.nixpkgs.follows = "nixpkgs";
33 };
Skyler Grey61635852022-10-31 00:27:04 +000034 fenix.url = "github:nix-community/fenix";
Skyler Greyd01ca9c2022-11-02 08:08:32 +000035 prismlauncher.url = "github:Scrumplex/nixpkgs/update-prismlauncher-5.1";
Skyler Greybcb2cb72022-08-21 07:24:35 +010036
Skyler Grey61635852022-10-31 00:27:04 +000037 fenix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey6be25172022-10-30 22:58:55 +000038 flake-utils-plus.inputs.flake-utils.follows = "flake-utils";
Skyler Greybcb2cb72022-08-21 07:24:35 +010039 home-manager.inputs.nixpkgs.follows = "nixpkgs";
40 sops-nix.inputs.nixpkgs.follows = "nixpkgs";
Skyler Grey7dfe5c62022-08-20 21:41:30 +010041 };
Skyler Grey0409e462022-08-19 23:40:48 +010042
Skyler Grey252927a2022-10-18 22:18:15 +010043 outputs = inputs:
44 let
45 inherit (inputs) self nixpkgs flake-utils;
46 in
47 flake-utils.lib.eachDefaultSystem (system:
48 let
49 pkgs = import nixpkgs {
Skyler Grey7dfe5c62022-08-20 21:41:30 +010050 inherit system;
Skyler Greybcc63992023-01-25 21:43:55 +000051 overlays = import ./overlays nixpkgs.lib (inputs // {
52 inherit inputs
53 username;
54 });
Skyler Grey7dfe5c62022-08-20 21:41:30 +010055 };
Skyler Grey252927a2022-10-18 22:18:15 +010056
57 utils = import ./utils nixpkgs.lib;
58
59 username = "minion";
60
61 isAttrType = type:
62 if builtins.elem type.name [ "submodule" ]
63 then true
64 else if type ? nestedTypes.elemType
65 then isAttrType type.nestedTypes.elemType
66 else false;
67
68 normalizeOptions = options:
69 if
70 nixpkgs.lib.traceSeqN 2
71 {
72 inherit options;
73 type = builtins.typeOf options;
74 }
75 builtins.typeOf
76 options
77 == "set"
78 then
79 nixpkgs.lib.mapAttrs
80 (
81 name: value:
82 if
83 nixpkgs.lib.traceSeqN 3
84 {
85 inherit name value;
86 hasGetSubOpts = value ? getSubOptions;
87 hasType = value ? type;
88 isAttrType = value ? type && isAttrType value.type;
89 typeName = value.type.name or "unnamed";
90 type = builtins.typeOf value;
91 }
92 (builtins.typeOf value)
93 == "set"
94 then
95 nixpkgs.lib.traceVal
96 (normalizeOptions (
97 if value ? type && isAttrType value.type
98 then nixpkgs.lib.traceVal (value.type.getSubOptions [ ])
99 else nixpkgs.lib.traceVal value
100 ))
101 else value
102 )
103 options
104 else options;
Skyler Greybcc63992023-01-25 21:43:55 +0000105
106 evalTrace = config: trace:
107 let
108 lib = nixpkgs.lib;
109 splitTrace = lib.splitString "." trace;
110 traceHead = builtins.head splitTrace;
111 traceTail = builtins.tail splitTrace;
112 resolvedTrace =
113 (
114 if traceHead == "home"
115 then [ "home-manager" "users" username ]
116 else lib.errorIfNot (traceHead == "config") [ ]
117 )
118 ++ traceTail;
119 in
120 (
121 lib.pipe resolvedTrace [
122 (lib.foldl
123 ({ value
124 , error
125 ,
126 }: key:
127 if builtins.hasAttr key value
128 then {
129 value = value.${key};
130 inherit error;
131 }
132 else {
133 value = { };
134 error = true;
135 })
136 {
137 value = { };
138 error = false;
139 })
140 (data: lib.warnIf data.error "trace@${moduleName}/${trace} is invalid; the key does not exist" data)
141 ({ value
142 , error
143 ,
144 }: {
145 value = builtins.toJSON value;
146 inherit error;
147 })
148 ({ value
149 , error
150 ,
151 }: {
152 value = "trace@${moduleName}/${trace}: ${value}";
153 inherit error;
154 })
155 ({ value
156 , error
157 ,
158 }:
159 lib.traceIf (!error) value null)
160 ]
161 );
Skyler Grey252927a2022-10-18 22:18:15 +0100162 in
163 {
164 packages.nixosConfigurations = {
Skyler Greybcc63992023-01-25 21:43:55 +0000165 default = nixpkgs.lib.traceValFn
166 (nixosSystem: map (evalTrace nixosSystem.config) nixosSystem.config.internal.traces) nixpkgs.lib.nixosSystem
167 {
168 inherit system;
Skyler Grey252927a2022-10-18 22:18:15 +0100169
Skyler Greybcc63992023-01-25 21:43:55 +0000170 modules = [
171 (nixpkgs.lib.pipe ./modules [
172 utils.nixFilesIn
173 (utils.interpretNonstandardModule (args:
174 args
175 // {
176 home = args.config.home-manager.users.${username};
177 home-options =
178 nixpkgs.lib.traceVal (normalizeOptions
179 (args.options.home-manager.users.type.getSubOptions [ ]));
180 inherit system utils;
181 }))
182 ])
183 {
184 minion = import ./config.nix;
185 }
186 ];
Skyler Grey252927a2022-10-18 22:18:15 +0100187
Skyler Greybcc63992023-01-25 21:43:55 +0000188 specialArgs = inputs // { inherit inputs username; };
189 };
Skyler Grey252927a2022-10-18 22:18:15 +0100190 };
191 devShell = pkgs.mkShell {
192 nativeBuildInputs = with pkgs; [ nodePackages.prettier nixpkgs-fmt ];
193 buildInputs = [ ];
194 };
195 formatter = pkgs.nixpkgs-fmt;
196 });
Skyler Grey0409e462022-08-19 23:40:48 +0100197}