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 nixpkgs.url = "github:NixOS/nixpkgs/32096899af23d49010bd8cf6a91695888d9d9e73";
8 pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
9 pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
11 nix-doom-emacs.url = "github:vlaci/nix-doom-emacs";
12 nix-doom-emacs.inputs.nixpkgs.follows = "nixpkgs";
13 nix-doom-emacs.inputs.home-manager.follows = "home-manager";
14 nix-doom-emacs.inputs.flake-utils.follows = "flake-utils";
15 nix-doom-emacs.inputs.emacs-overlay.follows = "emacs-overlay";
16 emacs-overlay.url = "github:nix-community/emacs-overlay/master";
18 #pass = { type = "path"; path = "./pass"; flake = false; };
23 remoteNixpkgsPatches = import nixpkgs/patches.nix;
24 localNixpkgsPatches = [
26 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
27 nixpkgsPath = originPkgs.applyPatches {
28 name = "nixpkgs-patched";
29 src = inputs.nixpkgs.outPath;
30 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
32 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
33 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
34 sort | sha256sum | cut -c -7)
35 echo "-patch-$patch" >.version-suffix
38 lib = inputs.nixpkgs.lib;
39 profile = "/nix/var/nix/profiles/system";
40 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
42 #pkgs = inputs.nixpkgs.legacyPackages.${system};
43 pkgs = pkgsForSystem system;
45 pkgsForSystem = system: import nixpkgsPath {
48 allowUnfree = true; # For hplip
50 overlays = import nixpkgs/overlays.nix;
52 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
53 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
56 nixosConfigurations = lib.genAttrs
57 (builtins.attrNames (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./hosts)))
58 (hostName: nixosSystem {
59 system = "x86_64-linux";
60 pkgs = pkgsForSystem "x86_64-linux";
62 inherit hostName inputs;
66 config._module.args = {
67 inherit hostName inputs;
68 hosts = inputs.self.nixosConfigurations;
71 (import nixos/modules.nix)
72 (import nixos/options.nix)
73 (import (./hosts + "/${hostName}.nix"))
74 inputs.nixpkgs.nixosModules.notDetected
75 inputs.home-manager.nixosModules.home-manager
77 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
78 nix.package = pkgs.nixFlakes;
79 nix.extraOptions = "experimental-features = nix-command flakes";
80 #nixpkgs.overlays = import nixpkgs/overlays.nix;
82 system.nixos.versionSuffix = ".${
83 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
84 inputs.self.shortRev or "dirty"}";
85 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
87 # Let 'nixos-version --json' know about the Git revision of this flake.
88 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
90 system.configurationRevision =
93 else throw "Refusing to build from a dirty Git tree!";
97 home-manager.useGlobalPkgs = true;
98 home-manager.useUserPackages = true;
99 home-manager.verbose = true;
100 home-manager.backupFileExtension = null;
101 home-manager.extraSpecialArgs = {
102 inherit hostName inputs;
107 # nix -L develop or direnv allow
108 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
110 inherit pkgs inputs system nixpkgsPath;
111 inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
113 # nix -L run .#oignon.switch
114 apps = forAllSystems ({ pkgs, system, ... }:
117 (hostName: { config, ... }:
119 build = config.system.build;
120 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
121 scriptApp = scriptName: ps: script: {
123 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
124 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
131 # Example: nix run .#aubergine.switch
132 "switch" = scriptApp "switch" [ ] ''
135 chmod -R g-rwx,o-rwx **/*.gpg
136 trap 'git reset **/*.gpg' EXIT
137 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
139 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
140 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
142 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
144 ssh ${target} set -x ';' \
145 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
146 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
147 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
149 ${profile}/bin/switch-to-configuration switch
152 ${build.toplevel}/bin/switch-to-configuration test
154 ssh ${target} -o ControlPath=none set -x ';' \
155 systemctl stop nixos-fallback.service ';' \
156 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
157 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
158 nix-env --delete-generations 7d --profile ${profile}
161 inputs.self.nixosConfigurations);
163 checks = forAllSystems (args: with args; {
164 pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
167 nixpkgs-fmt.enable = true;