From 3986cc441b86cb7873c99eb2252df4b080976f76 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sun, 25 Apr 2021 16:36:48 -0700 Subject: [PATCH] pkgs-lib: don't system space functions have each function take pkgs as an argument, so a nixpkgs isn't created just for pkgs-lib and they support more systems --- lib/flake.nix | 2 +- lib/pkgs-lib/default.nix | 17 +++++------------ lib/pkgs-lib/shell/default.nix | 25 ++++++++++++++----------- lib/pkgs-lib/tests/default.nix | 25 ++++++++++++++----------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lib/flake.nix b/lib/flake.nix index 15d87197..393c9d6a 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -40,7 +40,7 @@ pkgs-lib = import ./pkgs-lib { lib = nixpkgs.lib // self; - inherit nixpkgs deploy devshell; + inherit deploy devshell; }; inherit (attrs) diff --git a/lib/pkgs-lib/default.nix b/lib/pkgs-lib/default.nix index 1cadc2fe..bcaee771 100644 --- a/lib/pkgs-lib/default.nix +++ b/lib/pkgs-lib/default.nix @@ -1,13 +1,6 @@ -{ lib, nixpkgs, deploy, devshell }: +{ lib, deploy, devshell }: +{ + tests = import ./tests { inherit lib deploy; }; + shell = import ./shell { inherit lib devshell deploy; }; +} -lib.genAttrs - lib.defaultSystems - (system: - let - pkgs = import nixpkgs { inherit system; }; - in - { - tests = import ./tests { inherit lib deploy nixpkgs pkgs system; }; - shell = import ./shell { inherit lib devshell deploy nixpkgs system; }; - } - ) diff --git a/lib/pkgs-lib/shell/default.nix b/lib/pkgs-lib/shell/default.nix index 0146ca22..5b73b54c 100644 --- a/lib/pkgs-lib/shell/default.nix +++ b/lib/pkgs-lib/shell/default.nix @@ -1,27 +1,30 @@ -{ lib, nixpkgs, devshell, deploy, system }: +{ lib, devshell, deploy }: + +{ pkgs }: let overlays = [ - devshell.overlay (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) - ]; - pkgs = import nixpkgs { inherit system overlays; config = { }; }; + pkgs' = import pkgs.path { + inherit (pkgs) system; + inherit overlays; + }; - flk = pkgs.callPackage ./flk.nix { }; + flk = pkgs'.callPackage ./flk.nix { }; installPkgs = (lib.nixosSystem { - inherit system; + inherit (pkgs') system; modules = [ ]; }).config.system.build; in -pkgs.devshell.mkShell { - imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; +pkgs'.devshell.mkShell { + imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ]; packages = with installPkgs; [ nixos-install @@ -33,13 +36,13 @@ pkgs.devshell.mkShell { pre-commit.text = lib.fileContents ./pre-commit.sh; }; - commands = with pkgs; [ + commands = with pkgs'; [ { package = flk; } { name = "nix"; - help = pkgs.nixFlakes.meta.description; + help = pkgs'.nixFlakes.meta.description; command = '' - ${pkgs.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" + ${pkgs'.nixFlakes}/bin/nix --experimental-features "nix-command flakes ca-references" "${"\${@}"}" ''; } ] diff --git a/lib/pkgs-lib/tests/default.nix b/lib/pkgs-lib/tests/default.nix index b3e60624..854332fe 100644 --- a/lib/pkgs-lib/tests/default.nix +++ b/lib/pkgs-lib/tests/default.nix @@ -1,25 +1,28 @@ -{ lib, nixpkgs, pkgs, deploy, system }: +{ lib, deploy }: let - mkChecks = { hosts, nodes, homes ? { } }: + mkChecks = { pkgs, hosts, nodes, homes ? { } }: let deployHosts = lib.filterAttrs - (n: _: hosts.${n}.config.nixpkgs.system == system) + (n: _: hosts.${n}.config.nixpkgs.system == pkgs.system) nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + deployChecks = deploy.lib.${pkgs.system}.deployChecks { nodes = deployHosts; }; tests = lib.optionalAttrs (deployHosts != { }) { - profilesTest = profilesTest (hosts.${(builtins.head (builtins.attrNames deployHosts))}); + profilesTest = profilesTest { + inherit pkgs; + host = hosts.${(builtins.head (builtins.attrNames deployHosts))}; + }; } // lib.mapAttrs (n: v: v.activationPackage) homes; in lib.recursiveUpdate tests deployChecks; - mkTest = host: + mkTest = { pkgs, host }: let nixosTesting = - (import "${nixpkgs}/nixos/lib/testing-python.nix" { - inherit system; + (import "${toString pkgs.path}/nixos/lib/testing-python.nix" { + inherit (pkgs) system; inherit (host.config.lib) specialArgs; inherit pkgs; extraConfigurations = [ @@ -40,15 +43,15 @@ let in nixosTesting.makeTest calledTest; - profilesTest = host: mkTest host { + profilesTest = args@{ host, ... }: mkTest args { name = "profiles"; machine = { suites, ... }: { - imports = suites.allProfiles ++ suites.allUsers; + imports = suites.allProfiles; }; testScript = '' - machine.systemctl("is-system-running --wait") + ${host.config.networking.hostName}.systemctl("is-system-running --wait") ''; }; in