]> Git — Sourcephile - julm/julm-nix.git/blob - flake.nix
yt-dlp: disable live
[julm/julm-nix.git] / flake.nix
1 {
2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/495b19d5b3e62b4ec7e846bdfb6ef3d9c3b83492";
3 inputs.home-manager.url = "github:nix-community/home-manager";
4 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
5 inputs.doom-emacs.url = "github:hlissner/doom-emacs";
6 inputs.doom-emacs.flake = false;
7 /*
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 */
15 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
16
17 outputs = inputs: let
18 remoteNixpkgsPatches = import nixpkgs/patches.nix;
19 localNixpkgsPatches = [
20 ];
21 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
22 nixpkgsPath = originPkgs.applyPatches {
23 name = "nixpkgs-patched";
24 src = inputs.nixpkgs.outPath;
25 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
26 postPatch = ''
27 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
28 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
29 sort | sha256sum | cut -c -7)
30 echo "-patch-$patch" >.version-suffix
31 '';
32 };
33 lib = inputs.nixpkgs.lib;
34 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
35 inherit system;
36 #pkgs = inputs.nixpkgs.legacyPackages.${system};
37 pkgs = import nixpkgsPath {
38 inherit system;
39 config = {
40 allowUnfree = true; # For hplip
41 };
42 overlays = import nixpkgs/overlays.nix;
43 };
44 });
45 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
46 #nixosSystem = inputs.nixpkgs.lib.nixosSystem;
47 in {
48 nixosConfigurations = lib.genAttrs
49 (builtins.attrNames (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./hosts)))
50 (hostName: nixosSystem {
51 system = "x86_64-linux";
52 pkgs = import nixpkgsPath {
53 system = "x86_64-linux";
54 config = {
55 allowUnfree = true; # For hplip
56 };
57 overlays = import nixpkgs/overlays.nix;
58 };
59 specialArgs = {
60 inherit hostName inputs;
61 };
62 modules = [
63 {
64 config._module.args = {
65 inherit hostName inputs;
66 hosts = inputs.self.nixosConfigurations;
67 };
68 }
69 (import nixos/modules.nix)
70 (import nixos/options.nix)
71 (import (./hosts + "/${hostName}.nix"))
72 inputs.nixpkgs.nixosModules.notDetected
73 inputs.home-manager.nixosModules.home-manager
74 ({ pkgs, ... }: {
75 nix.registry.nixpkgs = lib.mkDefault { flake = inputs.nixpkgs; };
76 nix.package = pkgs.nixFlakes;
77 nix.extraOptions = "experimental-features = nix-command flakes";
78 #nixpkgs.overlays = import nixpkgs/overlays.nix;
79 /*
80 system.nixos.versionSuffix = ".${
81 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
82 inputs.self.shortRev or "dirty"}";
83 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
84 */
85 # Let 'nixos-version --json' know about the Git revision of this flake.
86 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
87 /*
88 system.configurationRevision =
89 if inputs.self ? rev
90 then inputs.self.rev
91 else throw "Refusing to build from a dirty Git tree!";
92 */
93 })
94 {
95 home-manager.useGlobalPkgs = true;
96 home-manager.useUserPackages = true;
97 home-manager.verbose = true;
98 home-manager.backupFileExtension = null;
99 home-manager.extraSpecialArgs = {
100 inherit hostName inputs;
101 };
102 }
103 ];
104 });
105 # nix -L develop or direnv allow
106 devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
107 {
108 inherit pkgs inputs system nixpkgsPath;
109 #inherit (checks.${system}.pre-commit-check) shellHook;
110 });
111 # nix -L run .#oignon.switch
112 apps = forAllSystems ({ pkgs, system, ... }:
113 with builtins;
114 mapAttrs (hostName: { config, ... }:
115 let
116 build = config.system.build;
117 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
118 profile = "/nix/var/nix/profiles/system";
119 nixos-fallback = { delay ? 5 * 60 }: pkgs.writeShellScript "nixos-fallback" ''
120 PATH=${with pkgs; lib.makeBinPath [ coreutils config.nix.package systemd ]}
121 set -eux
122 fallback=$(realpath -e -- ${profile})
123 sleep ${lib.escapeShellArg (toString delay)}
124 nix-env --profile ${profile} --set "$fallback"
125 $fallback/bin/switch-to-configuration switch
126 systemctl reboot
127 '';
128 in rec {
129 # Example: nix run .#aubergine.switch
130 "switch" = {
131 type = "app";
132 program = (pkgs.writeShellScript "switch" (''
133 set -eux
134 set -o pipefail
135 shopt -s globstar
136 chmod -R g-rwx,o-rwx **/*.gpg
137 trap 'git reset **/*.gpg' EXIT
138 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
139
140 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
141 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}
143 ssh ${target} \
144 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
145 systemd-run -u nixos-fallback ${nixos-fallback {}} ';' \
146 ${profile}/bin/switch-to-configuration test
147 ssh ${target} -o ControlPath=none \
148 systemctl stop nixos-fallback.service ';' \
149 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
150 ${profile}/bin/switch-to-configuration boot '&&' \
151 nix-env --delete-generations 7d --profile ${profile}
152 ''
153 )).outPath;
154 };
155 }) inputs.self.nixosConfigurations);
156 };
157 }