Skip to content

Multi-arch support for hosts(nixosConfigurations) #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,47 @@

extern = import ./extern { inherit inputs; };

pkgs' = os.mkPkgs;
multiPkgs = os.mkPkgs;

outputs =
let
system = "x86_64-linux";
pkgs = pkgs'.${system};
in
{
nixosConfigurations =
import ./hosts (nixos.lib.recursiveUpdate inputs {
inherit pkgs system extern;
inherit (pkgs) lib;
outputs = {
nixosConfigurations =
import ./hosts (nixos.lib.recursiveUpdate inputs {
inherit multiPkgs extern;
defaultSystem = "x86_64-linux";
lib = nixos.lib.extend (final: prev: {
dev = self.lib;
});
});

nixosModules =
let moduleList = import ./modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList;
nixosModules =
let moduleList = import ./modules/module-list.nix;
in lib.pathsToImportedAttrs moduleList;

overlay = import ./pkgs;
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);
overlay = import ./pkgs;
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.description = "flk template";
defaultTemplate = self.templates.flk;
templates.flk.path = ./.;
templates.flk.description = "flk template";
defaultTemplate = self.templates.flk;

deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
};

systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = multiPkgs.${system}; in
{
checks =
let
tests = import ./tests { inherit self pkgs; };
deployChecks = builtins.mapAttrs
(system: deployLib: deployLib.deployChecks self.deploy)
deploy.lib;
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; };
Comment on lines +74 to +76
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't currently working. For some reason nix flake check evaluates all systems starting with 'x86_64'. Including x86_64-darwin, which now fails because the related nixpkgs doesn't evaluate on x86_64-linux.

Any ideas on what to do for this @nrdxp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to debug this and I can't understand why nix flake check evaluates x86_64-darwin checks. I would assume that it would only build the checks for the current system.

Copy link
Member Author

@Pacman99 Pacman99 Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh I see it tries to evaluate all systems which normally shouldn't be an issue, but because of the patched-nixpkgs it ends up using IFD. This is a known issue NixOS/nix#4265.

The optimal solution would be to avoid IFD in checks, but thats not possible right now because of the specialArgs issue.

And I believe switching to nixos-unstable will fix this.

in
nixos.lib.recursiveUpdate tests deployChecks;
};

systemOutputs = utils.lib.eachDefaultSystem (system:
let pkgs = pkgs'.${system}; in
{
packages = utils.lib.flattenTreeSystem system
(os.mkPackages { inherit pkgs; });

Expand Down
4 changes: 4 additions & 0 deletions hosts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

hosts/librem.nix:
Expand Down
11 changes: 6 additions & 5 deletions hosts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
, lib
, nixos
, override
, pkgs
, multiPkgs
, self
, system
, defaultSystem
, ...
}:
let
Expand All @@ -27,7 +27,7 @@ let
modules;
};

global = {
global = { config, ... }: {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;

Expand All @@ -39,7 +39,7 @@ let
"home-manager=${home}"
];

nixpkgs = { inherit pkgs; };
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};

nix.registry = {
devos.flake = self;
Expand Down Expand Up @@ -79,7 +79,8 @@ let
};
in
dev.os.devosSystem {
inherit system specialArgs;
inherit specialArgs;
system = defaultSystem;
modules = modules // { inherit local lib; };
};

Expand Down
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
args@{ nixos, pkgs, self, ... }:
args@{ nixos, self, ... }:
let inherit (nixos) lib; in
lib.makeExtensible (final:
let callLibs = file: import file
Expand Down
71 changes: 35 additions & 36 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,44 @@ let
nixosTesting.makeTest calledTest;
in
{
x86_64-linux = {
profilesTest = mkTest {
name = "profiles";
profilesTest = mkTest {
name = "profiles";

machine = { suites, ... }: {
imports = suites.allProfiles ++ suites.allUsers;
};

testScript = ''
machine.systemctl("is-system-running --wait")
'';
machine = { suites, ... }: {
imports = suites.allProfiles ++ suites.allUsers;
};

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
testScript = ''
machine.systemctl("is-system-running --wait")
'';
};

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
'';
}