dotfiles/flake.nix

92 lines
3.3 KiB
Nix

{
inputs = {
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-21.11";
nixos-hardware.url = "github:NixOS/nixos-hardware";
home-manager.url = "github:nix-community/home-manager/release-21.11";
home-manager.inputs.nixpkgs.follows = "nixpkgs-stable";
qois-infrastructure.url = "path:/etc/nixos/qois-infrastructure";
threema.url = "path:/etc/nixos/defaults/threema";
threema.inputs.nixpkgs-unstable.follows = "nixpkgs-unstable";
fabianhauser-etaxes-sg.url = "github:fabianhauser/etaxes-sg-nix";
fabianhauser-etaxes-sg.inputs.nixpkgs.follows = "nixpkgs-stable";
};
outputs = { self, nixpkgs-unstable, nixpkgs-stable, home-manager
, qois-infrastructure, fabianhauser-etaxes-sg, nixos-hardware, threema, ...
}@inputs:
let
system = "x86_64-linux";
pkgsUnstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = true; # For vscode
};
hosts = [ "speer" "hummelberg" ];
in {
checks.${system}.formatCheck = let pkgs = pkgsUnstable;
in pkgs.runCommand "nixfmt-check" { } ''
set -euo pipefail
cd ${self}
${pkgs.findutils}/bin/find . -type f -name '*.nix' -exec ${pkgs.nixfmt}/bin/nixfmt --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;
};
home-manager-config = {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = sharedSpecialArgs // {
pkgsEtaxesSg = fabianhauser-etaxes-sg.packages.${system};
};
users.fhauser = import ./home/fhauser/default.nix;
};
};
mapHostnameToAttr = host:
nixpkgs-stable.lib.nixosSystem {
inherit system;
specialArgs = sharedSpecialArgs // {
hardwareModules = nixos-hardware.nixosModules;
};
modules = [
qois-infrastructure.nixosModule
home-manager.nixosModules.home-manager
home-manager-config
./host/${host}/default.nix
];
};
in pkgsUnstable.lib.genAttrs hosts mapHostnameToAttr;
# Nix development shell
devShell.${system} = import ./shell.nix { pkgs = pkgsUnstable; };
# Run checks and build all hosts as default package
packages.${system}.defaultPackage.${system} = 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";
};
};
};
}