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 nixosConfigurations = lib.genAttrs
46 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
47 (hostName: nixosSystem {
50 # Required to avoid infinite recursion
51 # when `inputs` is used in `imports`.
55 (import (./hosts + "/${hostName}.nix"))
59 hosts = inputs.self.nixosConfigurations;
60 host = inputs.self.nixosConfigurations.${hostName}._module.args;
62 nixpkgs.overlays = import nixpkgs/overlays.nix;
63 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "hplip" "geogebra" ];
65 (import nixos/modules.nix)
66 (import nixos/options.nix)
67 inputs.nixpkgs.nixosModules.notDetected
69 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
70 nix.package = pkgs.nixFlakes;
71 nix.extraOptions = "experimental-features = nix-command flakes";
72 #nixpkgs.overlays = import nixpkgs/overlays.nix;
74 system.nixos.versionSuffix = ".${
75 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
76 inputs.self.shortRev or "dirty"}";
77 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
79 # Let 'nixos-version --json' know about the Git revision of this flake.
80 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
82 system.configurationRevision =
85 else throw "Refusing to build from a dirty Git tree!";
88 inputs.home-manager.nixosModules.home-manager
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;