From dc4b030cbacef0951f1349a051c61209a964d766 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 19 Sep 2021 13:56:40 +0200 Subject: support nix flake check --- flake.nix | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index eb6f1fda..021146ea 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ inherit (nixpkgs) lib; utils = import ./utils { inherit lib; }; inherit (utils) nixImport overrideModule; - inherit (lib) nixosSystem mkIf splitString filterAttrs listToAttrs mapAttrsToList nameValuePair concatMap composeManyExtensions mapAttrs mapAttrs' recursiveUpdate genAttrs unique elem optionalAttrs; + inherit (lib) nixosSystem mkIf splitString filterAttrs listToAttrs mapAttrsToList nameValuePair concatMap composeManyExtensions mapAttrs mapAttrs' recursiveUpdate genAttrs unique elem optionalAttrs isDerivation concatLists; accountUserName = accountName: let @@ -104,12 +104,13 @@ // outputs // { imports = [self.nixosModules.users.${userName} or ({...}: { imports = defaultUserProfiles userName; })] ++ (outputs.imports or []); }); - forAllSystems = f: mapAttrs f nixpkgs.legacyPackages; + systemsSelector = "(x86_64|i686)-linux"; + forAllSystems = f: mapAttrs f (filterAttrs (system: _systemPkgs: !(isNull (builtins.match systemsSelector system))) nixpkgs.legacyPackages); forAllUsers = genAttrs (unique (map accountUserName (attrNames self.nixosModules.accounts))); activateNixosConfigurations = forAllSystems (system: _pkgs: mapAttrs' (hostName: nixosConfig: nameValuePair "${hostName}-activate" { type = "app"; program = "${nixosConfig.config.system.build.toplevel}/bin/switch-to-configuration"; }) self.nixosConfigurations); - overlayPaths = nixImport rec { dir = ./overlays; _import = (path: _name: dir + "/${path}"); } // { pkgs = ./pkgs; }; + overlayPaths = nixImport rec { dir = ./overlays; _import = (path: _name: dir + "/${path}"); }; installerProfiles = system: let nixpkgs-path = nixpkgs.legacyPackages.${system}.path; @@ -121,8 +122,13 @@ installerConfig = if pathExists ./installer.nix then "installer.nix" else (if pathExists ./installer then "installer" else null); installers = let mkInstallers = system: mapAttrs (mkInstaller system) (installerProfiles system); - mkInstaller = system: name: {profile, output}: output (mkNixosConfiguration [profile { config = { nixpkgs.system = system; }; }] ./. installerConfig "installer"); - in if !(isNull installerConfig) then { installers = forAllSystems (system: _systemPkgs: mkInstallers system); } else {}; + mkInstaller = system: name: {profile, output}: let mkOutput = output; in rec { config = mkNixosConfiguration [profile { config = { nixpkgs.system = system; }; }] ./. installerConfig "installer"; output = mkOutput config; }; + in forAllSystems (system: _systemPkgs: optionalAttrs (!(isNull installerConfig)) (mkInstallers system)); + installerNixosConfigurations = listToAttrs (concatLists (mapAttrsToList (system: mapAttrsToList (profile: { config, ... }: nameValuePair ("installer-${system}-${profile}") config)) installers)); + + packages = + let installerPackages = system: optionalAttrs (!(isNull installerConfig)) (mapAttrs' (profile: value: nameValuePair "installer-${profile}" value.output) installers.${system}); + in forAllSystems (system: systemPkgs: self.overlay (self.legacyPackages.${system}) systemPkgs // installerPackages system); in { nixosModules = @@ -133,19 +139,20 @@ accounts = recursiveUpdate rootAccounts (nixImport rec { dir = ./accounts; _import = mkAccountModule dir; }); rootAccounts = mapAttrs' (hostName: _value: nameValuePair "root@${hostName}" ({...}: { imports = [ self.nixosModules.users.root or ({...}: { imports = defaultUserProfiles "root"; }) ]; })) self.nixosConfigurations; in modulesAttrs // { inherit systemProfiles users userProfiles accounts; }; - nixosConfigurations = optionalAttrs (!(isNull installerConfig)) { installer = installerConfig; } // nixImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; + nixosConfigurations = installerNixosConfigurations // nixImport rec { dir = ./hosts; _import = mkNixosConfiguration [] dir; }; homeManagerModules = nixImport rec { dir = ./home-modules; }; - overlay = import overlayPaths.pkgs; + overlay = final: prev: composeManyExtensions (attrValues self.overlays) final prev; overlays = mapAttrs (_name: path: import path) overlayPaths; overlays-path = forAllSystems (system: _: self.legacyPackages.${system}.writeText "overlays.nix" '' map import (builtins.attrValues (builtins.fromJSON (builtins.readFile ${self.legacyPackages.${system}.writeText "overlays.json" (toJSON overlayPaths)}))) ''); - packages = forAllSystems (system: systemPkgs: composeManyExtensions (attrValues self.overlays) (self.legacyPackages.${system}) systemPkgs); + packages = mapAttrs (_name: filterAttrs (_name: isDerivation)) packages; + packages' = mapAttrs (_name: filterAttrs (_name: value: !(isDerivation value))) packages; - legacyPackages = forAllSystems (system: systemPkgs: recursiveUpdate systemPkgs self.packages.${system}); + legacyPackages = forAllSystems (system: systemPkgs: recursiveUpdate systemPkgs packages.${system}); apps = activateNixosConfigurations; @@ -155,5 +162,5 @@ path = ./.; description = "GKleen's flakey nixos configuration"; }; - } // installers; + }; } -- cgit v1.2.3