Files
nixfiles/flake.nix
T

188 lines
6.4 KiB
Nix
Raw Normal View History

2025-05-21 19:47:51 +01:00
{
description = "NixOS configuration";
inputs = {
2026-06-02 07:40:25 -07:00
# Pinned stable channel; the single source of truth for every host.
nixpkgs.url = "nixpkgs/nixos-26.05";
# Bleeding-edge channel, used only to pull individual packages via overlay.
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# Home-manager release matched to the stable nixpkgs; `follows` keeps a single nixpkgs eval.
home-manager.url = "github:nix-community/home-manager/release-26.05";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# WSL module for the EDaaS host; flake input avoids the impure <nixos-wsl> NIX_PATH lookup.
nixos-wsl.url = "github:nix-community/NixOS-WSL";
nixos-wsl.inputs.nixpkgs.follows = "nixpkgs";
# Apple Silicon (Asahi) support for the MacBook host.
nixos-apple-silicon.url = "github:nix-community/nixos-apple-silicon";
nixos-apple-silicon.inputs.nixpkgs.follows = "nixpkgs";
# Provides mkFlake: the systems/perSystem scaffolding used below.
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
2025-05-21 19:47:51 +01:00
};
2026-06-02 07:40:25 -07:00
outputs =
inputs@{
flake-parts,
nixpkgs,
nixpkgs-unstable,
home-manager,
nixos-wsl,
nixos-apple-silicon,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } (
{ lib, ... }:
let
# claude-code tracks nixpkgs-unstable regardless of the pinned nixpkgs.
overlays = [
(final: prev: {
claude-code =
(import nixpkgs-unstable {
inherit (prev.stdenv.hostPlatform) system;
config.allowUnfree = true;
}).claude-code;
})
];
# Unfree packages permitted to be built (replaces blanket allowUnfree).
unfreePackages = [
"claude-code"
"lens"
"lens-desktop"
];
# Shared scaffolding for every host: common user, overlays, home-manager.
baseModules = [
./emmathorpe/user.nix
{
nixpkgs.overlays = overlays;
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) unfreePackages;
nix.settings.experimental-features = [
"nix-command"
"flakes"
];
# Make `nix shell nixpkgs#...` and <nixpkgs> use the pinned nixpkgs.
nix.registry.nixpkgs.flake = nixpkgs;
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
}
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
# mkHost :: { system, username, fullName, modules, homeModules } -> nixosSystem
2026-06-02 07:40:25 -07:00
# Builds one machine by appending its host-specific modules to the shared
# baseModules. The user identity (username/fullName) is threaded through
# specialArgs so user.nix and the home modules stay host-agnostic, and the
# home-manager profile is keyed by the host's username.
2026-06-02 07:40:25 -07:00
mkHost =
{
system,
username,
fullName,
modules,
homeModules,
}:
2026-06-02 07:40:25 -07:00
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit inputs username fullName; };
modules =
baseModules
++ modules
++ [
{
home-manager.extraSpecialArgs = { inherit inputs username fullName; };
home-manager.users.${username}.imports = homeModules;
}
];
2026-06-02 07:40:25 -07:00
};
# Host table — declarative registry of every machine. To add a host:
# give it a name, its `system`, the owning user, and the module lists.
2026-06-02 07:40:25 -07:00
# mapAttrs below turns each entry into a nixosConfiguration of the same name.
hosts = {
emmathorpe-mbp = {
system = "aarch64-linux";
username = "lyrathorpe";
fullName = "Lyra Thorpe";
2026-06-02 07:40:25 -07:00
modules = [
./system/machine/MBP-Asahi/configuration.nix
nixos-apple-silicon.nixosModules.default
./emmathorpe/swaywm.nix
];
homeModules = [
./emmathorpe/home
./emmathorpe/home/desktop.nix
2026-06-02 07:40:25 -07:00
];
};
emmathorpe-x1c = {
system = "x86_64-linux";
username = "lyrathorpe";
fullName = "Lyra Thorpe";
2026-06-02 07:40:25 -07:00
modules = [
./system/machine/X1/configuration.nix
./emmathorpe/swaywm.nix
];
homeModules = [
./emmathorpe/home
./emmathorpe/home/desktop.nix
2026-06-02 07:40:25 -07:00
];
};
emmathorpe-edaas = {
system = "x86_64-linux";
username = "emmathorpe";
fullName = "Emma Thorpe";
2026-06-02 07:40:25 -07:00
modules = [
./system/machine/EDaaS/configuration.nix
2026-06-02 07:40:25 -07:00
nixos-wsl.nixosModules.default
./emmathorpe/swaywm.nix
];
homeModules = [
./emmathorpe/home
./system/modules/work/default.nix
2026-06-02 07:40:25 -07:00
];
};
};
in
{
systems = [
"x86_64-linux"
"aarch64-linux"
];
# perSystem is evaluated once per entry in `systems`; `pkgs` is the
# nixpkgs instance for that system. Outputs here become per-system
# attrsets automatically (e.g. devShells.<system>.default).
perSystem =
{ pkgs, ... }:
{
# `nix fmt` formatter for the repo.
formatter = pkgs.nixfmt;
# `nix develop` shell with the tooling needed to hack on this flake.
devShells.default = pkgs.mkShellNoCC {
packages = with pkgs; [
nixfmt
nil
git
];
};
checks.formatting =
pkgs.runCommandLocal "check-formatting" { nativeBuildInputs = [ pkgs.nixfmt ]; }
''
# Generated hardware-configuration.nix files are excluded.
nixfmt --check $(find ${./.} -name '*.nix' -not -name 'hardware-configuration.nix') && touch $out
'';
};
# Realise the host table: each `hosts` entry becomes a nixosConfiguration.
flake.nixosConfigurations = lib.mapAttrs (_name: mkHost) hosts;
}
);
2025-05-21 19:47:51 +01:00
}