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/32096899af23d49010bd8cf6a91695888d9d9e73";
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 inherit (inputs.nixpkgs) lib;
32 profile = "/nix/var/nix/profiles/system";
33 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
35 #pkgs = inputs.nixpkgs.legacyPackages.${system};
36 pkgs = pkgsForSystem system;
38 pkgsForSystem = system: import nixpkgsPath {
41 allowUnfree = true; # For hplip
43 overlays = import nixpkgs/overlays.nix;
45 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
46 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
49 nixosConfigurations = lib.genAttrs
50 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir ./hosts)))
51 (hostName: nixosSystem {
52 system = "x86_64-linux";
53 pkgs = pkgsForSystem "x86_64-linux";
55 inherit hostName inputs;
59 config._module.args = {
60 inherit hostName inputs;
61 hosts = inputs.self.nixosConfigurations;
64 (import nixos/modules.nix)
65 (import nixos/options.nix)
66 (import (./hosts + "/${hostName}.nix"))
67 inputs.nixpkgs.nixosModules.notDetected
68 inputs.home-manager.nixosModules.home-manager
70 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
71 nix.package = pkgs.nixFlakes;
72 nix.extraOptions = "experimental-features = nix-command flakes";
73 #nixpkgs.overlays = import nixpkgs/overlays.nix;
75 system.nixos.versionSuffix = ".${
76 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
77 inputs.self.shortRev or "dirty"}";
78 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
80 # Let 'nixos-version --json' know about the Git revision of this flake.
81 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
83 system.configurationRevision =
86 else throw "Refusing to build from a dirty Git tree!";
90 home-manager.useGlobalPkgs = true;
91 home-manager.useUserPackages = true;
92 home-manager.verbose = true;
93 home-manager.backupFileExtension = null;
94 home-manager.extraSpecialArgs = {
95 inherit hostName inputs;
100 # nix -L develop or direnv allow
101 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
103 inherit pkgs inputs system nixpkgsPath;
104 inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
106 # nix -L run .#oignon.switch
107 apps = forAllSystems ({ pkgs, system, ... }:
110 (hostName: { config, ... }:
112 inherit (config.system) build;
113 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
114 scriptApp = scriptName: ps: script: {
116 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
117 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
124 # Example: nix run .#aubergine.switch
125 "switch" = scriptApp "switch" [ ] ''
128 chmod -R g-rwx,o-rwx **/*.gpg
129 trap 'git reset **/*.gpg' EXIT
130 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
132 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
133 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
135 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
137 ssh ${target} set -x ';' \
138 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
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 inputs.self.nixosConfigurations);
156 checks = forAllSystems (args: with args; {
157 pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
160 nixpkgs-fmt.enable = true;
165 formatter = forAllSystems ({ pkgs, ... }:
166 inputs.nix-formatter-pack.lib.mkFormatter {
170 deadnix.enable = true;
171 nixpkgs-fmt.enable = true;
172 statix.enable = true;