]> Git — Sourcephile - julm/julm-nix.git/blob - flake.nix
systemd-creds: move to creds-{setup,encrypt,decrypt}.sh
[julm/julm-nix.git] / flake.nix
1 {
2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/495b19d5b3e62b4ec7e846bdfb6ef3d9c3b83492";
3 inputs.flake-utils.url = "github:numtide/flake-utils";
4 inputs.home-manager.url = "github:nix-community/home-manager";
5 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
6 inputs.doom-emacs.url = "github:hlissner/doom-emacs";
7 inputs.doom-emacs.flake = false;
8 inputs.nix-doom-emacs.url = "github:vlaci/nix-doom-emacs";
9 inputs.nix-doom-emacs.inputs.nixpkgs.follows = "nixpkgs";
10 inputs.nix-doom-emacs.inputs.home-manager.follows = "home-manager";
11 inputs.nix-doom-emacs.inputs.flake-utils.follows = "flake-utils";
12 inputs.nix-doom-emacs.inputs.emacs-overlay.follows = "emacs-overlay";
13 inputs.emacs-overlay.url = "github:nix-community/emacs-overlay/master";
14 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
15
16 outputs = inputs: let
17 remoteNixpkgsPatches = import nixpkgs/patches.nix;
18 localNixpkgsPatches = [
19 ];
20 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
21 nixpkgsPath = originPkgs.applyPatches {
22 name = "nixpkgs-patched";
23 src = inputs.nixpkgs.outPath;
24 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
25 postPatch = ''
26 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
27 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
28 sort | sha256sum | cut -c -7)
29 echo "-patch-$patch" >.version-suffix
30 '';
31 };
32 lib = originPkgs.lib;
33 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
34 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
35 in {
36 nixosConfigurations = lib.genAttrs
37 (builtins.attrNames (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./hosts)))
38 (hostName: nixosSystem rec {
39 system = "x86_64-linux";
40 specialArgs = {
41 inherit hostName inputs;
42 };
43 pkgs = import nixpkgsPath {
44 inherit system;
45 config.allowUnfree = true; # For hplip
46 overlays = import nixpkgs/overlays.nix;
47 };
48 modules = [
49 {
50 config._module.args = {
51 inherit hostName inputs;
52 hosts = inputs.self.nixosConfigurations;
53 };
54 }
55 (import nixos/options.nix)
56 (import (./hosts + "/${hostName}.nix"))
57 inputs.nixpkgs.nixosModules.notDetected
58 inputs.home-manager.nixosModules.home-manager
59 ({ pkgs, ... }: {
60 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
61 nix.package = pkgs.nixFlakes;
62 nix.extraOptions = "experimental-features = nix-command flakes";
63 #nixpkgs.overlays = import nixpkgs/overlays.nix;
64 /*
65 system.nixos.versionSuffix = ".${
66 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
67 inputs.self.shortRev or "dirty"}";
68 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
69 */
70 # Let 'nixos-version --json' know about the Git revision of this flake.
71 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
72 /*
73 system.configurationRevision =
74 if inputs.self ? rev
75 then inputs.self.rev
76 else throw "Refusing to build from a dirty Git tree!";
77 */
78 })
79 {
80 home-manager.useGlobalPkgs = true;
81 home-manager.useUserPackages = true;
82 home-manager.verbose = true;
83 home-manager.backupFileExtension = null;
84 home-manager.extraSpecialArgs = {
85 inherit hostName inputs;
86 };
87 }
88 ];
89 });
90 } //
91 inputs.flake-utils.lib.eachDefaultSystem (system:
92 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
93 let
94 pkgs = import nixpkgsPath {
95 inherit system;
96 config = {}; # Make the config pure, ignoring user's config.
97 overlays = import nixpkgs/overlays.nix;
98 }; in {
99 devShell = import ./shell.nix { inherit pkgs inputs system; };
100 apps = builtins.mapAttrs (hostName: { config, ... }: let
101 build = config.system.build;
102 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
103 profile = "/nix/var/nix/profiles/system";
104 in rec {
105 # Example: nix run .#aubergine.switch
106 "switch" = {
107 type = "app";
108 program = (pkgs.writeShellScript "switch" (''
109 set -eux
110 set -o pipefail
111 shopt -s globstar
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
115
116 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
117 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
118 nix copy --to ssh://${target}${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
119 ssh ${target} systemctl start nixos-fallback.service ';' \
120 nix-env --profile ${profile} --set '${build.toplevel}' '&&' \
121 ${profile}/bin/switch-to-configuration test
122 ssh ${target} -o ControlPath=none \
123 systemctl stop nixos-fallback.service ';' \
124 ${profile}/bin/switch-to-configuration boot '&&' \
125 nix-env --delete-generations 7d --profile ${profile}
126 ''
127 )).outPath;
128 };
129 }) inputs.self.nixosConfigurations;
130 }
131 );
132 }