mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-25 17:53:17 +01:00
95b10ec3ef
Now that I've figured out how to dynamically import modules and use those modules as outputs, the next step is to ensure that these modules work as intended when being used by end users. NixOS offers a built-in testing solution that enables us to conveniently spin up virtual machines with a given configuration, then verify their correctness through python scripting. The lib.nix file in particular is based on Jörg Thalheim's very useful blog post that explains how to use the built-in testing functionality with Nix flakes, which isn't covered in official documentation. See: https://blog.thalheim.io/2023/01/08/how-to-use-nixos-testing-framework-with-flakes/
85 lines
2.7 KiB
Nix
85 lines
2.7 KiB
Nix
{
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
home-manager = {
|
|
url = "github:nix-community/home-manager";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
stylix = {
|
|
url = "github:danth/stylix";
|
|
inputs = {
|
|
nixpkgs.follows = "nixpkgs";
|
|
home-manager.follows = "home-manager";
|
|
};
|
|
};
|
|
|
|
sakaya = {
|
|
url = "github:donovanglover/sakaya";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, home-manager, stylix, ... } @ attrs: let
|
|
inherit (nixpkgs.lib) nixosSystem;
|
|
inherit (nixpkgs.legacyPackages.x86_64-linux) nixpkgs-fmt callPackage;
|
|
|
|
checkArgs = {
|
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
|
inherit self;
|
|
};
|
|
|
|
flakeOutputs = [ "overlays" "nixosModules" "homeManagerModules" "packages" ];
|
|
flakeDirectories = [ "overlays" "modules" "home" "packages" ];
|
|
packageDirectory = "packages";
|
|
in {
|
|
formatter.x86_64-linux = nixpkgs-fmt;
|
|
|
|
nixosConfigurations = {
|
|
nixos = nixosSystem {
|
|
system = "x86_64-linux";
|
|
specialArgs = attrs;
|
|
modules = [
|
|
home-manager.nixosModules.home-manager
|
|
stylix.nixosModules.stylix
|
|
./hardware/laptop.nix
|
|
{
|
|
environment.pathsToLink = [
|
|
"/share/backgrounds"
|
|
"/share/eww"
|
|
"/share/thumbnailers"
|
|
"/share/fonts"
|
|
];
|
|
|
|
nixpkgs.overlays = builtins.attrValues self.overlays;
|
|
imports = builtins.attrValues self.nixosModules;
|
|
home-manager.sharedModules = builtins.attrValues self.homeManagerModules;
|
|
environment.systemPackages = builtins.attrValues self.packages.x86_64-linux;
|
|
}
|
|
];
|
|
};
|
|
};
|
|
|
|
checks.x86_64-linux = {
|
|
hyprland = import ./tests/hyprland.nix checkArgs;
|
|
neovim = import ./tests/neovim.nix checkArgs;
|
|
};
|
|
} //
|
|
(builtins.listToAttrs
|
|
(builtins.map
|
|
(attributeName: {
|
|
name = attributeName;
|
|
value = let
|
|
directory = builtins.replaceStrings flakeOutputs flakeDirectories attributeName;
|
|
attributeValue = (builtins.listToAttrs
|
|
(builtins.map
|
|
(file: {
|
|
name = builtins.replaceStrings [ ".nix" ] [ "" ] file;
|
|
value = if directory == packageDirectory then callPackage ./${directory}/${file} { } else import ./${directory}/${file}; })
|
|
(builtins.attrNames (builtins.readDir ./${directory}))));
|
|
attributeSet = if directory == packageDirectory then { x86_64-linux = attributeValue; } else attributeValue;
|
|
in (attributeSet); })
|
|
(flakeOutputs)));
|
|
}
|