From aec7c92cc71aeeb2ad492f59cb9e5b942bc593ae Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Mon, 15 Mar 2021 19:04:28 -0700 Subject: [PATCH 1/2] hosts: set nixpkgs.pkgs based on nixpkgs.system --- flake.nix | 60 +++++++++++++++++++++++------------------------ hosts/README.md | 4 ++++ hosts/default.nix | 11 +++++---- lib/default.nix | 2 +- 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/flake.nix b/flake.nix index 4f8cc3bd..7975a6f5 100644 --- a/flake.nix +++ b/flake.nix @@ -36,47 +36,45 @@ 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; - 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; - }; + 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: - let pkgs = pkgs'.${system}; in + let pkgs = multiPkgs.${system}; in { packages = utils.lib.flattenTreeSystem system (os.mkPackages { inherit pkgs; }); diff --git a/hosts/README.md b/hosts/README.md index d101ec97..b573f50b 100644 --- a/hosts/README.md +++ b/hosts/README.md @@ -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: diff --git a/hosts/default.nix b/hosts/default.nix index 0a4884ed..a4bf3f30 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -3,9 +3,9 @@ , lib , nixos , override -, pkgs +, multiPkgs , self -, system +, defaultSystem , ... }: let @@ -27,7 +27,7 @@ let modules; }; - global = { + global = { config, ... }: { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; @@ -39,7 +39,7 @@ let "home-manager=${home}" ]; - nixpkgs = { inherit pkgs; }; + nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system}; nix.registry = { devos.flake = self; @@ -79,7 +79,8 @@ let }; in dev.os.devosSystem { - inherit system specialArgs; + inherit specialArgs; + system = defaultSystem; modules = modules // { inherit local lib; }; }; diff --git a/lib/default.nix b/lib/default.nix index df85f4e7..7fceb3ce 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,4 @@ -args@{ nixos, pkgs, self, ... }: +args@{ nixos, self, ... }: let inherit (nixos) lib; in lib.makeExtensible (final: let callLibs = file: import file From 3c8d22a5281e70ec5619e425f3e140d17b444bd4 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 14 Mar 2021 19:14:51 -0700 Subject: [PATCH 2/2] flake/tests: improve multi arch support for flake checks --- flake.nix | 19 +++++++------ tests/default.nix | 71 +++++++++++++++++++++++------------------------ 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/flake.nix b/flake.nix index 7975a6f5..130c2b13 100644 --- a/flake.nix +++ b/flake.nix @@ -62,20 +62,21 @@ defaultTemplate = self.templates.flk; 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: 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 (os.mkPackages { inherit pkgs; }); diff --git a/tests/default.nix b/tests/default.nix index 59a42f24..d1ecddd3 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 + ''; } +