nixos/flake.nix

214 lines
7 KiB
Nix

{
description = "Malte Tammena's system configuration";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
devshell.url = "github:numtide/devshell";
treefmt-nix.url = "github:numtide/treefmt-nix";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
nixpkgs.url = "nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware";
custom-udev-rules.url = "github:MalteT/custom-udev-rules";
nix-wallpaper = {
url = "github:lunik1/nix-wallpaper";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs-wayland = {
url = "github:nix-community/nixpkgs-wayland";
};
jovian-nixos = {
url = "github:Jovian-Experiments/Jovian-NixOS";
inputs.nixpkgs.follows = "nixpkgs";
};
mensa = {
url = "github:MalteT/mensa/main";
inputs.nixpkgs.follows = "nixpkgs";
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
fend = {
url = "github:MalteT/fend/flake";
inputs.nixpkgs.follows = "nixpkgs";
};
hydra = {
url = "github:NixOS/hydra";
};
hyprland = {
type = "git";
url = "https://github.com/hyprwm/Hyprland";
submodules = true;
inputs.nixpkgs.follows = "nixpkgs";
};
hyprland-contrib = {
url = "github:hyprwm/contrib";
inputs.nixpkgs.follows = "nixpkgs";
};
qmk-udev-rules = {
url = "github:qmk/qmk_firmware";
flake = false;
};
nix-topology = {
url = "github:oddlama/nix-topology";
inputs.nixpkgs.follows = "nixpkgs";
};
};
nixConfig = {
# Only usefull if you're part of my VPN
extra-substituters = ["http://cache.home"];
};
outputs = inputs @ {flake-parts, ...}: let
# Overlays useful to most of my systems
overlaysSharedByAll = [
inputs.hyprland-contrib.overlays.default
(_: super: {
# Add my mensa tool
inherit (inputs.mensa.packages.x86_64-linux) mensa;
# TODO: Replace with upstream
inherit (inputs.fend.packages.x86_64-linux) fend;
hydra = inputs.hydra.packages.x86_64-linux.default;
# TODO: Remove once hydra fixes these removed aliases
inherit (super.perlPackages) buildPerlPackage;
netcat-openbsd = super.libressl.nc;
nix-wallpaper = inputs.nix-wallpaper.packages.x86_64-linux.default;
})
(import ./overlays/qmk-udev-rules.nix)
];
# Modules useful to most of my systems
modulesSharedByAllSystems = [
inputs.sops-nix.nixosModules.sops
inputs.home-manager.nixosModules.home-manager
inputs.nix-topology.nixosModules.default
./modules/base-system.nix
];
# The list of all hosts known to me
listOfHosts = let
hostDir = builtins.readDir ./hosts;
in
builtins.attrNames hostDir;
in
flake-parts.lib.mkFlake {inherit inputs;} {
# Flake-parts modules to use
imports = [
inputs.devshell.flakeModule
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
inputs.nix-topology.flakeModule
];
# Available systems, only x86 for now
systems = ["x86_64-linux"];
perSystem = {
pkgs,
self',
config,
system,
...
}: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [inputs.nix-topology.overlays.default];
};
# Configure treefmt
treefmt.projectRootFile = "flake.nix";
treefmt.programs = {
alejandra.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
};
# Configure pre-commit checks
pre-commit.settings.hooks.deadnix.enable = true;
pre-commit.settings.hooks.treefmt.enable = true;
pre-commit.settings.hooks.shellcheck.enable = true;
pre-commit.settings.hooks.markdownlint.enable = true;
# Load all packages from ./pkgs
packages = let
pkgFiles = builtins.attrNames (builtins.readDir ./pkgs);
toPackage = file: {
name = builtins.replaceStrings [".nix"] [""] file;
value = pkgs.callPackage ./pkgs/${file} {inherit inputs;};
};
in
builtins.listToAttrs (builtins.map toPackage pkgFiles);
# Create a useable devshell for me
devShells.default = pkgs.mkShell {
name = "dev";
shellHook = ''
${config.pre-commit.installationScript}
echo 1>&2 "Welcome to the development shell!"
'';
packages = [
pkgs.nil
pkgs.pre-commit
pkgs.ssh-to-age
self'.packages.rebuild
self'.packages.personal-cache
self'.packages.all-hosts
self'.packages.option
self'.packages.test-config
];
};
topology.modules = [./topology.nix {_module.args.inputs = inputs;}];
};
# Useful modules and all those from ./modules
flake.nixosModules =
{
homeManagerConfig = _: {
home-manager.verbose = true;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
};
}
// (let
removeSuffix = builtins.replaceStrings [".nix"] [""];
moduleFiles = builtins.attrNames (builtins.readDir ./modules);
listOfModules = builtins.map removeSuffix moduleFiles;
toModule = name: {
inherit name;
value = builtins.readFile ./modules/${name};
};
in
builtins.listToAttrs (builtins.map toModule listOfModules));
# All my system's configurations
flake.nixosConfigurations = let
genSystem = name: {
inherit name;
value = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {inherit inputs;};
modules = modulesSharedByAllSystems ++ [{nixpkgs.overlays = overlaysSharedByAll;} ./hosts/${name}/default.nix];
};
};
in
builtins.listToAttrs (builtins.map genSystem listOfHosts);
# Additional library functions
flake.lib = (builtins.import ./lib) {inherit (inputs.nixpkgs) lib;};
# Iso for USB
flake.packages.x86_64-linux.iso = inputs.self.nixosConfigurations.radix-balthica.config.system.build.isoImage;
# VM for testing
flake.packages.x86_64-linux.vm = inputs.self.nixosConfigurations.radix-balthica.config.system.build.vm;
# Copy most things to hydraJobs so hydra evaluates and builds them
flake.hydraJobs = {
inherit (inputs.self) packages devShells;
nixosConfigurations.x86_64-linux = builtins.listToAttrs (builtins.map (name: {
inherit name;
value = inputs.self.nixosConfigurations.${name}.config.system.build.toplevel;
})
listOfHosts);
topology.x86_64-linux = inputs.self.topology.x86_64-linux.config.output;
};
};
}