5 "https://nix-community.cachix.org"
7 extra-trusted-public-keys = [
8 "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
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-23.11";
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-23.11";
21 pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
22 pre-commit-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
23 pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
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;
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
43 profile = "/nix/var/nix/profiles/system";
44 inherit (inputs.nixpkgs) lib;
45 #nixosSystem = lib.nixosSystem;
46 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
47 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
49 #pkgs = inputs.nixpkgs.legacyPackages.${system};
50 pkgs = import nixpkgsPath {
52 overlays = import nixpkgs/overlays.nix;
57 # nix -L build .#hello
58 packages = forAllSystems ({ pkgs, ... }: pkgs);
60 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
61 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
62 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
63 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.rulese
64 nixosConfigurations = lib.genAttrs
65 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
66 (hostName: nixosSystem {
69 # Required to avoid infinite recursion
70 # when `inputs` is used in `imports`.
75 (import (./hosts + "/${hostName}.nix"))
79 hosts = inputs.self.nixosConfigurations;
80 host = inputs.self.nixosConfigurations.${hostName}._module.args;
82 nixpkgs.overlays = import nixpkgs/overlays.nix;
83 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "cudatoolkit" "geogebra" "hplip" "memtest86-efi" "nvidia-x11" "nvidia-settings" ];
85 inputs.home-manager.nixosModules.home-manager
87 home-manager.useGlobalPkgs = true;
88 home-manager.useUserPackages = true;
89 home-manager.verbose = true;
90 home-manager.backupFileExtension = null;
91 home-manager.extraSpecialArgs = {
92 inherit hostName inputs;
98 # nix -L develop or direnv allow
99 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
101 inherit pkgs inputs system nixpkgsPath;
102 inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
105 # nix -L run .#oignon.switch
106 apps = forAllSystems ({ pkgs, system, ... }:
109 (hostName: { config, ... }:
111 inherit (config.system) build;
112 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
113 scriptApp = scriptName: ps: script: {
115 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
116 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
123 # Example: nix run .#aubergine.switch
124 "switch" = scriptApp "switch" [ ] ''
127 chmod -R g-rwx,o-rwx **/*.gpg
128 trap 'git reset **/*.gpg' EXIT
129 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
131 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
132 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
134 nix copy --to "ssh://${target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
136 if ssh ${target} set -x ';' \
137 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
138 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
139 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
140 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
142 ${profile}/bin/switch-to-configuration switch
145 ${build.toplevel}/bin/switch-to-configuration test
147 ssh ${target} -o ControlPath=none set -x ';' \
148 systemctl stop nixos-fallback.service ';' \
149 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
150 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
151 nix-env --delete-generations 7d --profile ${profile}
154 echo WARNING: switch-to-configuration was not registered at boot
156 ssh ${target} -o ControlPath=none set -x ';' \
157 systemctl stop nixos-fallback.service
162 inputs.self.nixosConfigurations);
165 checks = forAllSystems (args: with args; {
166 pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
169 nixpkgs-fmt.enable = true;
175 formatter = forAllSystems ({ pkgs, ... }:
176 inputs.nix-formatter-pack.lib.mkFormatter {
180 deadnix.enable = true;
181 nixpkgs-fmt.enable = true;
182 statix.enable = true;