nixos/flake.nix

199 lines
6.6 KiB
Nix
Raw Normal View History

2021-05-19 23:08:18 +02:00
{
description = "Malte Tammena's system configuration";
2021-10-13 17:38:24 +02:00
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";
2021-10-13 17:38:24 +02:00
nixpkgs.url = "nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware";
custom-udev-rules.url = "github:MalteT/custom-udev-rules";
2022-06-05 14:16:32 +02:00
nix-colors.url = "github:Misterio77/nix-colors";
2021-12-26 21:49:18 +01:00
nixpkgs-wayland = {
url = "github:nix-community/nixpkgs-wayland";
};
jovian-nixos = {
2024-01-01 14:44:25 +01:00
url = "github:Jovian-Experiments/Jovian-NixOS";
inputs.nixpkgs.follows = "nixpkgs";
};
2021-12-26 21:49:18 +01:00
mensa = {
2023-04-15 00:43:20 +02:00
url = "github:MalteT/mensa/main";
2021-12-26 21:49:18 +01:00
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";
};
2022-12-22 12:33:49 +01:00
hyprland = {
url = "github:hyprwm/Hyprland";
inputs.nixpkgs.follows = "nixpkgs";
2022-12-22 12:33:49 +01:00
};
hyprland-contrib = {
url = "github:hyprwm/contrib";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-03-06 14:42:26 +01:00
qmk-udev-rules = {
url = "github:qmk/qmk_firmware";
flake = false;
};
2021-07-21 09:10:17 +02:00
};
2021-05-19 23:08:18 +02:00
2022-05-08 21:42:05 +02:00
nixConfig = {
# Only usefull if you're part of my VPN
2022-06-18 15:02:00 +02:00
extra-substituters = ["http://cache.home"];
2022-05-08 21:42:05 +02:00
};
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;
})
(import ./overlays/qmk-udev-rules.nix)
];
# Modules useful to most of my systems
modulesSharedByAllSystems = [
inputs.sops-nix.nixosModules.sops
inputs.self.nixosModules.nixUnstable
inputs.home-manager.nixosModules.home-manager
./modules/base-system.nix
];
# The list of all hosts known to me
listOfHosts = let
hostDir = builtins.readDir ./hosts;
in
2024-01-15 15:59:54 +01:00
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
];
# Available systems, only x86 for now
systems = ["x86_64-linux"];
perSystem = {
pkgs,
self',
2023-11-12 22:31:12 +01:00
config,
...
}: {
# Configure treefmt
treefmt.projectRootFile = "flake.nix";
treefmt.programs = {
alejandra.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
2023-01-15 16:52:17 +01:00
};
# 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;
2023-09-10 00:34:14 +02:00
value = pkgs.callPackage ./pkgs/${file} {inherit inputs;};
};
in
builtins.listToAttrs (builtins.map toPackage pkgFiles);
# Create a useable devshell for me
2023-11-12 22:31:12 +01:00
devShells.default = pkgs.mkShell {
name = "dev";
2023-11-12 22:31:12 +01:00
shellHook = ''
${config.pre-commit.installationScript}
echo 1>&2 "Welcome to the development shell!"
'';
packages = [
pkgs.nil
pkgs.pre-commit
2023-11-18 11:21:14 +01:00
pkgs.ssh-to-age
self'.packages.rebuild
self'.packages.personal-cache
self'.packages.all-hosts
self'.packages.option
self'.packages.test-config
2022-12-01 15:33:12 +01:00
];
};
2021-12-26 20:44:36 +01:00
};
# Useful modules and all those from ./modules
flake.nixosModules =
{
homeManagerConfig = _: {
home-manager.verbose = true;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = {inherit (inputs) nix-colors;};
};
nixUnstable = {pkgs, ...}: {
nix.registry.nixpkgs.flake = inputs.nixpkgs;
nix.package = pkgs.nixUnstable;
nix.extraOptions = ''
experimental-features = nix-command flakes
'';
};
}
// (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;};
2024-01-15 15:59:54 +01:00
modules = modulesSharedByAllSystems ++ [{nixpkgs.overlays = overlaysSharedByAll;} ./hosts/${name}/default.nix];
};
};
in
builtins.listToAttrs (builtins.map genSystem listOfHosts);
# 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);
2021-12-22 21:37:23 +01:00
};
};
2021-05-19 23:08:18 +02:00
}