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