summaryrefslogtreecommitdiff
path: root/flake.nix
blob: 4b5b63ee45d2b672c520291a251c9456c6ab2cb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
  nixConfig = {
    extra-substituters = "https://nix-community.cachix.org";
    extra-trusted-public-keys = "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=";
  };

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.nixos-hardware.url = "github:NixOS/nixos-hardware/master";
  inputs.emacs-overlay.url = "github:nix-community/emacs-overlay";
  inputs.agenix.url = "github:ryantm/agenix";
  inputs.agenix.inputs.nixpkgs.follows = "nixpkgs";
  inputs.jovian.url = "github:Jovian-Experiments/Jovian-NixOS";
  inputs.mujmap.url = "github:elizagamedev/mujmap";

  outputs =
    { self, nixpkgs, nixpkgs-unstable, nixos-hardware, emacs-overlay, agenix, jovian, mujmap }:
    let
      systems = ["x86_64-linux"];
      lib = nixpkgs.lib;
      forAllSystems = lib.genAttrs systems;

      registry-module = { ... }: {
        nix.registry.nixpkgs.flake = nixpkgs;
        nix.registry.nixpkgs-unstable.flake = nixpkgs-unstable;
      };

      orbekk-modules = let
        moduleFiles = lib.attrNames
        (lib.filterAttrs (n: v: lib.hasSuffix ".nix" n && v == "regular")
        (builtins.readDir ./modules));

        moduleNames = map (lib.removeSuffix ".nix") moduleFiles;

        mkModule = name: {
          inherit name;
          value = import (./. + "/modules/${name}.nix");
        };
      in lib.listToAttrs (map mkModule moduleNames);

    in rec {
      nixosModules = orbekk-modules // { inherit registry-module; };

      overlays = {
        #emacs-overlay = emacs-overlay.overlay;

        extraPackages = final: prev: {
          agenix = agenix.packages.${final.system}.default;
          mujmap = mujmap.packages.${final.system}.default;
          unstable = import nixpkgs-unstable {
            system = final.system;
            config.allowUnfree = true;
          };
        };
      };

      nixosConfigurations = let
          mkConfig = { hostName, module ? (./. + "/machines/${hostName}.nix")
          , system ? "x86_64-linux" }: {
            name = hostName;
            value = lib.nixosSystem {
              inherit system;

              modules = (lib.attrValues self.nixosModules) ++ [
                registry-module
                module
                nixpkgs.nixosModules.notDetected
                agenix.nixosModules.default
                ({ config, pkgs, ... }: {
                  # Let 'nixos-version --json' know about the Git revision
                  # of this flake.
                  system.configurationRevision = let
                    lastModified = pkgs.lib.substring 0 8
                    (self.lastModifiedDate or self.lastModified or "19700101");
                  in "${lastModified}.${self.shortRev or "dirty"}";

                  nixpkgs.overlays = builtins.attrValues overlays;
                })
              ] ++ lib.optional (hostName == "dex") jovian.nixosModules.jovian;
            };
          };
          myMachines = [
            {
              hostName = "pincer";
              module = ./machines/x1-pincer.nix;
            }
            { hostName = "dragon"; }
            { hostName = "firelink"; }
            { hostName = "tiny1"; }
            { hostName = "dex"; }
          ];
        in builtins.listToAttrs (map mkConfig myMachines);
    };
}