dotfiles/flake.nix

101 lines
3.5 KiB
Nix

{
inputs = {
# Upstream deps
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware";
# Packages
home-manager.url = "github:nix-community/home-manager/master";
home-manager.inputs.nixpkgs.follows = "nixpkgs-stable";
# Private Deps
qois-infrastructure = {
url = "git+file:///etc/nixos/qois-infrastructure";
inputs.nixpkgs-nixos-2211.follows = "nixpkgs-stable";
inputs.nixpkgs-nixos-unstable.follows = "nixpkgs-unstable";
};
threema.url = "git+file:///etc/nixos/defaults/threema";
threema.inputs.nixpkgs-unstable.follows = "nixpkgs-unstable";
fcc-unlock = {
url = "git+file:///etc/nixos/fcc-unlock";
inputs.nixos-stable.follows = "nixpkgs-stable";
};
};
outputs = { self, nixpkgs-unstable, nixpkgs-stable, home-manager
, qois-infrastructure, nixos-hardware, threema, fcc-unlock, ... }@inputs:
let
system = "x86_64-linux";
pkgsUnstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = true; # For vscode
};
hosts = [ "speer" "hummelberg" "ochsenchopf" "bachtel" ];
in {
checks.${system}.formatCheck = let pkgs = pkgsUnstable;
in pkgs.runCommand "nixfmt-check" { } ''
set -euo pipefail
cd ${self}
${self.apps.${system}.format.program} --check
mkdir $out
'';
# Build with `nixos-rebuild --flake .#<hostname>` or
# `nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel
nixosConfigurations = let
sharedSpecialArgs = {
threemaModules = threema.nixosModules;
inherit pkgsUnstable;
pkgFccUnlock = fcc-unlock.packages.${system}.default;
};
home-manager-config = {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = sharedSpecialArgs;
users.fhauser = import ./home/fhauser/default.nix;
};
};
mapHostnameToAttr = host:
nixpkgs-stable.lib.nixosSystem {
inherit system;
specialArgs = sharedSpecialArgs // {
hardwareModules = nixos-hardware.nixosModules;
};
modules = [
qois-infrastructure.nixosModules.default
home-manager.nixosModules.home-manager
./host/${host}/default.nix
] ++ (if host == "bachtel" then [ ] else [ home-manager-config ]);
};
in pkgsUnstable.lib.genAttrs hosts mapHostnameToAttr;
# Nix development shell
devShells.${system}.default = import ./shell.nix { pkgs = pkgsUnstable; };
# Run checks and build all hosts as default package
packages.${system}.default = with pkgsUnstable.lib;
let
checks = attrValues self.checks.${system};
nixosConfigs = mapAttrsToList (n: v: v.config.system.build.toplevel)
self.nixosConfigurations;
in pkgsUnstable.linkFarmFromDrvs "allHosts" (checks ++ nixosConfigs);
apps.${system} = {
# Execute nixfmt on the repository
format = let
pkgs = pkgsUnstable;
formatter = pkgsUnstable.writeShellScriptBin "formatter" ''
${pkgs.findutils}/bin/find . -type f -name '*.nix' -exec ${pkgs.nixfmt}/bin/nixfmt $@ {} +
'';
in {
type = "app";
program = "${formatter}/bin/formatter";
};
};
};
}