]> Git — Sourcephile - julm/julm-nix.git/blob - flake.nix
julm: oignon: install transmission-remote-gtk
[julm/julm-nix.git] / flake.nix
1 {
2 /*
3 nixConfig = {
4 extra-substituters = [
5 "https://nix-community.cachix.org"
6 ];
7 extra-trusted-public-keys = [
8 "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
9 ];
10 };
11 */
12
13 inputs = {
14 doom-emacs.flake = false;
15 doom-emacs.url = "github:hlissner/doom-emacs";
16 home-manager.inputs.nixpkgs.follows = "nixpkgs";
17 home-manager.url = "github:nix-community/home-manager/release-24.05";
18 nix-formatter-pack.inputs.nixpkgs.follows = "nixpkgs";
19 nix-formatter-pack.url = "github:Gerschtli/nix-formatter-pack";
20 nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
21 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
22 git-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
23 git-hooks.url = "github:cachix/git-hooks.nix";
24 };
25
26 outputs = inputs:
27 let
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
30 ];
31 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
32 nixpkgsPath = originPkgs.applyPatches {
33 name = "nixpkgs-patched";
34 src = inputs.nixpkgs.outPath;
35 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
36 postPatch = ''
37 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
38 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
39 sort | sha256sum | cut -c -7)
40 echo "-patch-$patch" >.version-suffix
41 '';
42 };
43 profile = "/nix/var/nix/profiles/system";
44 inherit (inputs.nixpkgs) lib;
45 overlays = system:
46 import nixpkgs/overlays.nix ++ [
47 ];
48 #nixosSystem = lib.nixosSystem;
49 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
50 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
51 inherit system;
52 #pkgs = inputs.nixpkgs.legacyPackages.${system};
53 pkgs = import nixpkgsPath {
54 inherit system;
55 overlays = overlays system;
56 };
57 });
58 self = with lib.fileset; toSource {
59 root = ./.;
60 fileset =
61 let exts = [ "clear" "conf" "cred" "crt" "css" "el" "hs" "json" "nix" "patch" "pem" "pub" "sh" "theme" "vim" ]; in
62 unions [
63 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
64 (fileFilter (file: lib.any file.hasExt exts) ./homes)
65 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
66 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
67 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
68 (fileFilter (file: lib.any file.hasExt exts) ./share)
69 (fileFilter (file: lib.any file.hasExt exts) ./users)
70 ./shell.nix
71 ];
72 };
73 in
74 rec {
75 # nix -L build .#hello
76 packages = forAllSystems ({ pkgs, ... }: pkgs);
77
78 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
79 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
80 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
81 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
82 nixosConfigurations = lib.genAttrs
83 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))))
84 (hostName: nixosSystem {
85 system = null;
86 specialArgs = {
87 # Required to avoid infinite recursion
88 # when `inputs` is used in `imports`.
89 inherit inputs;
90 };
91 modules = [
92 nixos/default.nix
93 (import (self + "/hosts/${hostName}.nix"))
94 ({ config, ... }: {
95 _module.args = {
96 inherit hostName;
97 hosts = nixosConfigurations;
98 host = nixosConfigurations.${hostName}._module.args;
99 };
100 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
101 nixpkgs.config.permittedInsecurePackages = [
102 # Still needed for chatty
103 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
104 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
105 "olm-3.2.16"
106 ];
107 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
108 "anydesk"
109 "cudatoolkit"
110 "geogebra"
111 "hplip"
112 "memtest86-efi"
113 "nvidia-settings"
114 "nvidia-x11"
115 ];
116 })
117 inputs.home-manager.nixosModules.home-manager
118 {
119 home-manager.useGlobalPkgs = true;
120 home-manager.useUserPackages = true;
121 home-manager.verbose = true;
122 #home-manager.force = true;
123 home-manager.backupFileExtension = "old";
124 home-manager.extraSpecialArgs = {
125 inherit hostName inputs;
126 };
127 }
128 ];
129 });
130
131 # nix -L develop or direnv allow
132 devShells = forAllSystems ({ pkgs, system, ... }:
133 {
134 default = pkgs.callPackage (self + "/shell.nix")
135 {
136 inherit pkgs inputs system nixpkgsPath;
137 inherit (checks.${system}.git-hooks-check) shellHook;
138 };
139 }
140 );
141
142 # nix -L run .#oignon.switch
143 apps = forAllSystems ({ pkgs, system, ... }:
144 with builtins;
145 mapAttrs
146 (hostName: { config, ... }:
147 let
148 inherit (config.system) build;
149 scriptApp = scriptName: ps: script: {
150 type = "app";
151 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
152 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
153 set -eux
154 ${script}
155 '').outPath;
156 };
157 in
158 {
159 # Example: nix run .#aubergine.switch
160 "switch" = scriptApp "switch" [ ] ''
161 shopt -s globstar
162
163 chmod -R g-rwx,o-rwx **/*.gpg
164 trap 'git reset **/*.gpg' EXIT
165 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
166
167 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
168 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
169
170 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
171
172 if ssh ${config.install.target} set -x ';' \
173 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
174 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
175 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
176 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
177 sleep $((10 * 60))
178 ${profile}/bin/switch-to-configuration switch
179 systemctl reboot
180 '\'''' '&&' \
181 ${build.toplevel}/bin/switch-to-configuration test
182 then
183 ssh ${config.install.target} -o ControlPath=none set -x ';' \
184 systemctl stop nixos-fallback.service ';' \
185 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
186 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
187 nix-env --delete-generations 7d --profile ${profile}
188 else
189 tput rev
190 echo WARNING: switch-to-configuration was not registered at boot
191 tput sgr0
192 ssh ${config.install.target} -o ControlPath=none set -x ';' \
193 systemctl stop nixos-fallback.service
194 false
195 fi
196 '';
197 })
198 nixosConfigurations);
199
200 # nix flake check
201 checks = forAllSystems (args: with args; {
202 git-hooks-check = inputs.git-hooks.lib.${system}.run {
203 src = self;
204 hooks = {
205 nixpkgs-fmt.enable = true;
206 };
207 };
208 });
209
210 # nix fmt
211 formatter = forAllSystems ({ pkgs, ... }:
212 inputs.nix-formatter-pack.lib.mkFormatter {
213 inherit pkgs;
214 config = {
215 tools = {
216 deadnix.enable = true;
217 nixpkgs-fmt.enable = true;
218 statix.enable = true;
219 };
220 };
221 }
222 );
223 };
224 }