161: Multi-arch support for hosts(nixosConfigurations) r=nrdxp a=Pacman99

fixes #72 

also related, #125 

This allows users to set `nixpkgs.system` to any architecture exported by the nixpkgs flake and nixpkgs.pkgs will be set to that system.

I also added `multiPkgs` as a special arg and made `nixpkgs.pkgs` a default. So if someone wanted to do crossSystem builds or anything else with pkgs, that is also an option(eg. mobile-nixos!!).

Co-authored-by: Pacman99 <pachum99@gmail.com>
This commit is contained in:
bors[bot] 2021-03-19 19:33:31 +00:00 committed by GitHub
commit c050027171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 74 deletions

View file

@ -36,48 +36,47 @@
extern = import ./extern { inherit inputs; }; extern = import ./extern { inherit inputs; };
pkgs' = os.mkPkgs; multiPkgs = os.mkPkgs;
outputs = outputs = {
let nixosConfigurations =
system = "x86_64-linux"; import ./hosts (nixos.lib.recursiveUpdate inputs {
pkgs = pkgs'.${system}; inherit multiPkgs extern;
in defaultSystem = "x86_64-linux";
{ lib = nixos.lib.extend (final: prev: {
nixosConfigurations = dev = self.lib;
import ./hosts (nixos.lib.recursiveUpdate inputs {
inherit pkgs system extern;
inherit (pkgs) lib;
}); });
});
nixosModules = nixosModules =
let moduleList = import ./modules/module-list.nix; let moduleList = import ./modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList; in lib.pathsToImportedAttrs moduleList;
overlay = import ./pkgs; overlay = import ./pkgs;
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays); overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);
lib = import ./lib { inherit nixos pkgs self inputs; }; lib = import ./lib { inherit nixos self inputs; };
templates.flk.path = ./.; templates.flk.path = ./.;
templates.flk.description = "flk template"; templates.flk.description = "flk template";
defaultTemplate = self.templates.flk; defaultTemplate = self.templates.flk;
deploy.nodes = os.mkNodes deploy self.nixosConfigurations; deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
};
checks =
let
tests = import ./tests { inherit self pkgs; };
deployChecks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy.lib;
in
nixos.lib.recursiveUpdate tests deployChecks;
};
systemOutputs = utils.lib.eachDefaultSystem (system: systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = pkgs'.${system}; in let pkgs = multiPkgs.${system}; in
{ {
checks =
let
tests = nixos.lib.optionalAttrs (system == "x86_64-linux")
(import ./tests { inherit self pkgs; });
deployHosts = nixos.lib.filterAttrs
(n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes;
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; };
in
nixos.lib.recursiveUpdate tests deployChecks;
packages = utils.lib.flattenTreeSystem system packages = utils.lib.flattenTreeSystem system
(os.mkPackages { inherit pkgs; }); (os.mkPackages { inherit pkgs; });

View file

@ -25,6 +25,10 @@ that you intend to use on your machine.
Additionally, this is the perfect place to import anything you might need from Additionally, this is the perfect place to import anything you might need from
the [nixos-hardware][nixos-hardware] repository. the [nixos-hardware][nixos-hardware] repository.
> ##### _Note:_
> Set `nixpkgs.system` to the architecture of this host, default is "x86_64-linux".
> Keep in mind that not all packages are available for all architectures.
## Example ## Example
hosts/librem.nix: hosts/librem.nix:

View file

@ -3,9 +3,9 @@
, lib , lib
, nixos , nixos
, override , override
, pkgs , multiPkgs
, self , self
, system , defaultSystem
, ... , ...
}: }:
let let
@ -27,7 +27,7 @@ let
modules; modules;
}; };
global = { global = { config, ... }: {
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
@ -39,7 +39,7 @@ let
"home-manager=${home}" "home-manager=${home}"
]; ];
nixpkgs = { inherit pkgs; }; nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
nix.registry = { nix.registry = {
devos.flake = self; devos.flake = self;
@ -79,7 +79,8 @@ let
}; };
in in
dev.os.devosSystem { dev.os.devosSystem {
inherit system specialArgs; inherit specialArgs;
system = defaultSystem;
modules = modules // { inherit local lib; }; modules = modules // { inherit local lib; };
}; };

View file

@ -1,4 +1,4 @@
args@{ nixos, pkgs, self, ... }: args@{ nixos, self, ... }:
let inherit (nixos) lib; in let inherit (nixos) lib; in
lib.makeExtensible (final: lib.makeExtensible (final:
let callLibs = file: import file let callLibs = file: import file

View file

@ -59,45 +59,44 @@ let
nixosTesting.makeTest calledTest; nixosTesting.makeTest calledTest;
in in
{ {
x86_64-linux = { profilesTest = mkTest {
profilesTest = mkTest { name = "profiles";
name = "profiles";
machine = { suites, ... }: { machine = { suites, ... }: {
imports = suites.allProfiles ++ suites.allUsers; imports = suites.allProfiles ++ suites.allUsers;
};
testScript = ''
machine.systemctl("is-system-running --wait")
'';
}; };
libTests = pkgs.runCommandNoCC "devos-lib-tests" testScript = ''
{ machine.systemctl("is-system-running --wait")
buildInputs = [
pkgs.nix
(
let tests = import ./lib.nix { inherit self pkgs; };
in
if tests == [ ]
then null
else throw (builtins.toJSON tests)
)
];
} ''
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export PAGER=cat
cacheDir=$TEST_ROOT/binary-cache
nix-store --init
touch $out
''; '';
}; };
libTests = pkgs.runCommandNoCC "devos-lib-tests"
{
buildInputs = [
pkgs.nix
(
let tests = import ./lib.nix { inherit self pkgs; };
in
if tests == [ ]
then null
else throw (builtins.toJSON tests)
)
];
} ''
datadir="${pkgs.nix}/share"
export TEST_ROOT=$(pwd)/test-tmp
export NIX_BUILD_HOOK=
export NIX_CONF_DIR=$TEST_ROOT/etc
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_STORE_DIR=$TEST_ROOT/store
export PAGER=cat
cacheDir=$TEST_ROOT/binary-cache
nix-store --init
touch $out
'';
} }