mirror of
https://github.com/nix-community/nixos-generators.git
synced 2024-09-11 12:15:29 +03:00
Merge pull request #241 from DavHau/all-formats
This commit is contained in:
commit
f17fb67fc8
49
all-formats.nix
Normal file
49
all-formats.nix
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
lib,
|
||||
extendModules,
|
||||
...
|
||||
}: let
|
||||
# attrs of all format modules from ./formats
|
||||
formatModules =
|
||||
lib.flip lib.mapAttrs' (builtins.readDir ./formats)
|
||||
(fname: type: {
|
||||
name = lib.removeSuffix ".nix" fname;
|
||||
value = ./formats + "/${fname}";
|
||||
});
|
||||
|
||||
# function to evaluate a given format to a config
|
||||
evalFormat = formatModule:
|
||||
extendModules {
|
||||
modules = [
|
||||
./format-module.nix
|
||||
formatModule
|
||||
];
|
||||
};
|
||||
|
||||
# evaluated configs for all formats
|
||||
allConfigs = lib.mapAttrs (formatName: evalFormat) formatModules;
|
||||
|
||||
# attrset of formats to be exposed under config.system.formats
|
||||
formats = lib.flip lib.mapAttrs allConfigs (
|
||||
formatName: conf:
|
||||
conf.config.system.build.${conf.config.formatAttr}
|
||||
);
|
||||
in {
|
||||
_file = ./all-formats.nix;
|
||||
# This deliberate key makes sure this module will be deduplicated
|
||||
# regardless of the accessor path: either via flake's nixosModule
|
||||
# or as part of the nixos-generate command. These two store paths
|
||||
# of the module may differ and hence don't serve as a key
|
||||
key = "github:nix-community/nixos-generators/all-formats.nix";
|
||||
|
||||
# declare option for exposing all formats
|
||||
options.system.formats = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf lib.types.raw;
|
||||
description = ''
|
||||
Different target formats generated for this NixOS configuratation.
|
||||
'';
|
||||
};
|
||||
|
||||
# expose all formats
|
||||
config.system = {inherit formats;};
|
||||
}
|
33
checks/test-all-formats.nix
Normal file
33
checks/test-all-formats.nix
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
nixpkgs ? <nixpkgs>,
|
||||
system ? builtins.currentSystem,
|
||||
lib ? import (nixpkgs + /lib),
|
||||
}: let
|
||||
nixosSystem = import (nixpkgs + /nixos/lib/eval-config.nix);
|
||||
|
||||
conf = nixosSystem {
|
||||
inherit system;
|
||||
modules = [
|
||||
../configuration.nix
|
||||
../all-formats.nix
|
||||
];
|
||||
};
|
||||
|
||||
exclude =
|
||||
(lib.optionalAttrs (system != "aarch64-linux") {
|
||||
sd-aarch64 = true;
|
||||
sd-aarch64-installer = true;
|
||||
})
|
||||
// (lib.optionalAttrs (system != "x86_64-linux") {
|
||||
azure = true;
|
||||
vagrant-virtualbox = true;
|
||||
virtualbox = true;
|
||||
vmware = true;
|
||||
});
|
||||
|
||||
testedFormats =
|
||||
lib.filterAttrs
|
||||
(name: _: ! exclude ? ${name})
|
||||
conf.config.system.formats;
|
||||
in
|
||||
testedFormats
|
@ -10,6 +10,6 @@
|
||||
networking.firewall.allowedTCPPorts = [80];
|
||||
|
||||
users.users.root.password = "nixos";
|
||||
services.openssh.permitRootLogin = lib.mkDefault "yes";
|
||||
services.openssh.settings.PermitRootLogin = lib.mkDefault "yes";
|
||||
services.getty.autologinUser = lib.mkDefault "root";
|
||||
}
|
||||
|
28
flake.nix
28
flake.nix
@ -108,15 +108,25 @@
|
||||
};
|
||||
});
|
||||
|
||||
checks = forAllSystems (system: {
|
||||
inherit
|
||||
(self.packages.${system})
|
||||
nixos-generate
|
||||
;
|
||||
is-formatted = import ./checks/is-formatted.nix {
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
};
|
||||
});
|
||||
checks =
|
||||
nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"]
|
||||
(
|
||||
system: let
|
||||
allFormats = import ./checks/test-all-formats.nix {
|
||||
inherit nixpkgs system;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit
|
||||
(self.packages.${system})
|
||||
nixos-generate
|
||||
;
|
||||
is-formatted = import ./checks/is-formatted.nix {
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
};
|
||||
}
|
||||
// allFormats
|
||||
);
|
||||
|
||||
devShells = forAllSystems (system: let
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
|
Loading…
Reference in New Issue
Block a user