3 doom-emacs.flake = false;
4 doom-emacs.url = "github:hlissner/doom-emacs";
5 home-manager.inputs.nixpkgs.follows = "nixpkgs";
6 home-manager.url = "github:nix-community/home-manager";
7 nix-formatter-pack.inputs.nixpkgs.follows = "nixpkgs";
8 nix-formatter-pack.url = "github:Gerschtli/nix-formatter-pack";
9 nixpkgs.url = "github:NixOS/nixpkgs/fdebb81f45a1ba2c4afca5fd9f526e1653ad0949";
10 pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
11 pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
16 remoteNixpkgsPatches = import nixpkgs/patches.nix;
17 localNixpkgsPatches = [
19 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
20 nixpkgsPath = originPkgs.applyPatches {
21 name = "nixpkgs-patched";
22 src = inputs.nixpkgs.outPath;
23 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
25 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
26 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
27 sort | sha256sum | cut -c -7)
28 echo "-patch-$patch" >.version-suffix
31 profile = "/nix/var/nix/profiles/system";
32 inherit (inputs.nixpkgs) lib;
33 #nixosSystem = lib.nixosSystem;
34 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
35 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
37 #pkgs = inputs.nixpkgs.legacyPackages.${system};
38 pkgs = import nixpkgsPath {
40 overlays = import nixpkgs/overlays.nix;
45 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
46 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
47 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
48 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.rulese
49 nixosConfigurations = lib.genAttrs
50 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
51 (hostName: nixosSystem {
54 # Required to avoid infinite recursion
55 # when `inputs` is used in `imports`.
60 (import (./hosts + "/${hostName}.nix"))
64 hosts = inputs.self.nixosConfigurations;
65 host = inputs.self.nixosConfigurations.${hostName}._module.args;
67 nixpkgs.overlays = import nixpkgs/overlays.nix;
68 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "hplip" "geogebra" ];
70 inputs.home-manager.nixosModules.home-manager
72 home-manager.useGlobalPkgs = true;
73 home-manager.useUserPackages = true;
74 home-manager.verbose = true;
75 home-manager.backupFileExtension = null;
76 home-manager.extraSpecialArgs = {
77 inherit hostName inputs;
83 # nix -L develop or direnv allow
84 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
86 inherit pkgs inputs system nixpkgsPath;
87 inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
90 # nix -L run .#oignon.switch
91 apps = forAllSystems ({ pkgs, system, ... }:
94 (hostName: { config, ... }:
96 inherit (config.system) build;
97 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
98 scriptApp = scriptName: ps: script: {
100 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
101 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
108 # Example: nix run .#aubergine.switch
109 "switch" = scriptApp "switch" [ ] ''
112 chmod -R g-rwx,o-rwx **/*.gpg
113 trap 'git reset **/*.gpg' EXIT
114 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
116 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
117 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
119 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
121 ssh ${target} set -x ';' \
122 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
123 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
124 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
126 ${profile}/bin/switch-to-configuration switch
129 ${build.toplevel}/bin/switch-to-configuration test
131 ssh ${target} -o ControlPath=none set -x ';' \
132 systemctl stop nixos-fallback.service ';' \
133 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
134 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
135 nix-env --delete-generations 7d --profile ${profile}
138 inputs.self.nixosConfigurations);
141 checks = forAllSystems (args: with args; {
142 pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
145 nixpkgs-fmt.enable = true;
151 formatter = forAllSystems ({ pkgs, ... }:
152 inputs.nix-formatter-pack.lib.mkFormatter {
156 deadnix.enable = true;
157 nixpkgs-fmt.enable = true;
158 statix.enable = true;