From 44237e65aef327e678cead78f06d2e071cc18a15 Mon Sep 17 00:00:00 2001 From: derped Date: Sat, 16 Nov 2024 18:44:05 +0100 Subject: [PATCH] Use flake-utils to map flake outputs. --- flake.nix | 121 +++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/flake.nix b/flake.nix index cb90528..5b11914 100644 --- a/flake.nix +++ b/flake.nix @@ -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); + } + ); }