Use flake-utils to map flake outputs.

This commit is contained in:
Kevin Baensch 2024-11-16 18:44:05 +01:00
parent 5a98a03819
commit 44237e65ae
Signed by: derped
GPG key ID: C0F1D326C7626543

121
flake.nix
View file

@ -7,6 +7,7 @@
nixpkgs.url = "github:/NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:/NixOS/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master"; nixos-hardware.url = "github:NixOS/nixos-hardware/master";
impermanence.url = "github:nix-community/impermanence"; impermanence.url = "github:nix-community/impermanence";
flake-utils.url = "github:numtide/flake-utils";
alejandra = { alejandra = {
url = "github:kamadorueda/alejandra/3.0.0"; url = "github:kamadorueda/alejandra/3.0.0";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -20,71 +21,71 @@
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
flake-utils,
alejandra, alejandra,
mailserver, mailserver,
sops-nix, sops-nix,
... ...
} @ attrs: let } @ attrs:
inherit (nixpkgs) lib; flake-utils.lib.eachDefaultSystem (
fn = import ./fn.nix {inherit lib;}; system: let
mappedFormatter = builtins.mapAttrs (arch: packages: packages.default) alejandra.packages; inherit (nixpkgs) lib;
mappedApps = fn = import ./fn.nix {inherit lib;};
builtins.mapAttrs (_arch: packages: { pkgs = nixpkgs.legacyPackages."${system}";
"lint" = { machineList = fn.lst {
type = "app"; p = toString ./machines;
program = "${packages.statix}/bin/statix"; t = "directory";
b = false;
}; };
}) nixosSystemFor = machine: {
nixpkgs.legacyPackages; name = machine;
system = "x86_64-linux"; value = let
machineList = fn.lst { configFiles = fn.lst {
p = toString ./machines; p = toString ./config;
t = "directory"; b = true;
b = false; };
}; pkgsFiles = fn.lst {
configFiles = fn.lst { p = toString ./pkgs;
p = toString ./config; b = true;
b = true; };
}; serviceFiles = fn.lst {
pkgsFiles = fn.lst { p = toString ./services;
p = toString ./pkgs; b = true;
b = true; };
}; machinePath = lib.concatStringsSep "/" [(toString ./.) "machines" machine];
serviceFiles = fn.lst { machineFiles = lib.filter (lib.strings.hasSuffix ".nix") (fn.lst {
p = toString ./services; p = machinePath;
b = true; b = true;
}; });
nixosSystemFor = machine: { in
name = machine; nixpkgs.lib.nixosSystem {
value = let inherit system;
machinePath = lib.concatStringsSep "/" [(toString ./.) "machines" machine]; specialArgs =
machineFiles = lib.filter (lib.strings.hasSuffix ".nix") (fn.lst { attrs
p = machinePath; // {
b = true; inherit system;
}); inherit fn;
in };
nixpkgs.lib.nixosSystem { modules =
inherit system; [
specialArgs = (toString ./options/machine.nix)
attrs sops-nix.nixosModules.sops
// { ]
inherit system; ++ machineFiles
inherit fn; ++ configFiles
++ pkgsFiles
++ serviceFiles;
}; };
modules =
[
(toString ./options/machine.nix)
sops-nix.nixosModules.sops
]
++ machineFiles
++ configFiles
++ pkgsFiles
++ serviceFiles;
}; };
}; in {
in { apps = {
apps = mappedApps; "lint" = {
formatter = mappedFormatter; type = "app";
nixosConfigurations = lib.listToAttrs (map nixosSystemFor machineList); program = "${pkgs.statix}/bin/statix";
}; };
};
formatter = alejandra.defaultPackage."${system}";
packages.nixosConfigurations = lib.listToAttrs (map nixosSystemFor machineList);
}
);
} }