summary refs log tree commit diff
path: root/compat/flake-compat.nix
blob: ac56432bdf938395abbccc131cc08541801802f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
with builtins;
let
  lock = fromJSON (readFile ../flake.lock);
  
  flake-compat = builtins.fetchGit (with lock.nodes.flake-compat.locked; {
    inherit rev;
    url = "https://github.com/${owner}/${repo}.git";
  });

in
{ src, ... }: import flake-compat { inherit src; }
olor: #87CEEB } /* Literal.String.Delimiter */ .highlight .sd { color: #87CEEB } /* Literal.String.Doc */ .highlight .s2 { color: #87CEEB } /* Literal.String.Double */ .highlight .se { color: #87CEEB } /* Literal.String.Escape */ .highlight .sh { color: #87CEEB } /* Literal.String.Heredoc */ .highlight .si { color: #87CEEB } /* Literal.String.Interpol */ .highlight .sx { color: #87CEEB } /* Literal.String.Other */ .highlight .sr { color: #87CEEB } /* Literal.String.Regex */ .highlight .s1 { color: #87CEEB } /* Literal.String.Single */ .highlight .ss { color: #87CEEB } /* Literal.String.Symbol */ .highlight .bp { color: #DDD } /* Name.Builtin.Pseudo */ .highlight .fm { color: #FF0 } /* Name.Function.Magic */ .highlight .vc { color: #EEDD82 } /* Name.Variable.Class */ .highlight .vg { color: #EEDD82 } /* Name.Variable.Global */ .highlight .vi { color: #EEDD82 } /* Name.Variable.Instance */ .highlight .vm { color: #EEDD82 } /* Name.Variable.Magic */ .highlight .il { color: #F0F } /* Literal.Number.Integer.Long */
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";

    nixos-hardware.url = "github:NixOS/nixos-hardware";

    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    agenix = {
      url = "github:ryantm/agenix";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        home-manager.follows = "home-manager";
      };
    };

    flake-compat.url = "github:edolstra/flake-compat";

    oisd = {
      url = "github:sjhgvr/oisd";
      flake = false;
    };
  };

  outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager, agenix, ... }:
  let
    tailnetName = "serval-moth";

    systems = {
      x86 = "x86_64-linux";
      arm = "aarch64-linux";
    };

    mkMachines = let
      mkMachine = m: {
        inherit (m) name system;
        tailscale = {
          inherit (m.tailscale) ip;
          domain = "${m.name}.${tailnetName}.ts.net";
        };
      };

    in machines: map (m: mkMachine m) machines;

    mkMachineIdentities = ms: current:
      lib.genAttrs (lib.catAttrs "name" ms) (m: current.name == m);

    machines = with systems; mkMachines [
      { name = "corsac"; system = x86; tailscale.ip = "100.64.100.100"; }
      { name = "lapin"; system = arm; tailscale.ip = "100.83.254.27"; }
      { name = "renard"; system = x86; tailscale.ip = "100.75.17.75"; }
      { name = "fourmi"; system = arm; tailscale.ip = "100.99.119.83"; }
    ];

    overlays = [ agenix.overlays.default ];

    packageSetsForSystem = system: let
      pkgsInputs =
        i: { inherit system; config = import ./config.nix; } // i;
    in rec {
      pkgs = import nixpkgs (pkgsInputs { inherit overlays; });

      unstablePkgs = import nixpkgs-unstable (pkgsInputs { });

      auxiliaryPkgs = import ./pkgs (pkgsInputs { inherit pkgs unstablePkgs; });
    };

    inherit (nixpkgs) lib;
  in {
    nixosConfigurations = lib.mergeAttrsList (map (machine: {
      ${machine.name} = nixpkgs.lib.nixosSystem {
        inherit (machine) system;

        specialArgs = inputs // (packageSetsForSystem machine.system) // {
          inherit machines;
          me = machine // { is = mkMachineIdentities machines machine; };
          keys = import ./secrets/keys.nix;
          util = import ./util.nix { inherit lib; };
        };

        modules = [
          ./machines/${machine.name}

          home-manager.nixosModules.home-manager {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.mel = import ./machines/${machine.name}/home.nix;
          }

          agenix.nixosModules.default
        ];
      };
    }) machines);

    # compatibility wrapper for nixos-option
    legacyPackages = lib.genAttrs (lib.attrValues systems)
      (system: with packageSetsForSystem system; pkgs.recurseIntoAttrs pkgs);
  };
}