Add flake checks

This commit is contained in:
Tim Van Baak 2024-07-29 08:59:12 -07:00
parent 494d24322a
commit 9a184ae55e
4 changed files with 80 additions and 12 deletions

65
checks.nix Normal file
View File

@ -0,0 +1,65 @@
{
self,
nixosSystem,
pkgs,
...
}:
let
# A dummy package with no maintainer
orphanPkg = pkgs.stdenv.mkDerivation {
name = "dummy-unmaintained-package";
installPhase = ''
echo "dummy-unmaintained-package" > $out
'';
meta = {
maintainers = [ ];
};
};
# A dummy package with a maintainer
parentPkg = pkgs.stdenv.mkDerivation {
name = "dummy-maintained-package";
buildInputs = [ orphanPkg ];
installPhase = ''
echo "dummy-maintained-package" > $out
'';
meta = {
maintainers = [ { github = "github"; } ];
};
};
# A dummy NixOS config with an unmaintained package in its closure
config = nixosSystem {
inherit (pkgs) system;
modules = [
(
{ ... }:
{
environment.systemPackages = [ parentPkg ];
# Boilerplate so nixosSystem compiles
fileSystems."/" = {
device = "/dev/dvd";
fsType = "ext4";
};
boot.loader.grub.device = "/dev/dvd";
system.stateVersion = "24.05";
}
)
];
};
inherit (self.bundlers.${pkgs.system}) all unmaintained;
grepCheck =
name: search: target:
pkgs.runCommandLocal name { } ''
wc -l ${target} >> test.log
grep ${search} ${target} >> test.log
cp test.log $out
'';
in
{
package = grepCheck "package" orphanPkg.name (unmaintained orphanPkg);
packageClosure = grepCheck "packageClosure" orphanPkg.name (unmaintained parentPkg);
configClosure = grepCheck "configClosure" orphanPkg.name (unmaintained config);
}

View File

@ -13,12 +13,12 @@
system = "x86_64-linux";
in
{
lib = forAllSystems (system: import ./lib.nix { pkgs = nixpkgsFor.${system}; });
bundlers = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
lib = import ./lib.nix { inherit pkgs; };
inherit (lib) allMaintainers expandInput noMaintainers;
inherit (self.lib.${system}) allMaintainers expandInput noMaintainers;
in
{
default = self.bundlers.${system}.unmaintained;
@ -28,5 +28,14 @@
);
formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
checks = forAllSystems (
system:
import ./checks.nix {
inherit self;
inherit (nixpkgs.lib) nixosSystem;
pkgs = nixpkgsFor.${system};
}
);
};
}

11
lib.nix
View File

@ -9,11 +9,7 @@ let
tail
;
inherit (pkgs) runCommandLocal writeText;
inherit (pkgs.lib)
concatLines
concatStringsSep
filter
;
inherit (pkgs.lib) concatLines concatStringsSep filter;
inherit (import ./closure.nix { inherit pkgs; }) drvClosure;
in
rec {
@ -65,10 +61,7 @@ rec {
expandInput =
input:
if (input.class or null == "nixos") && (input._type or null == "configuration") then
[
input.config.system.build.toplevel
input.config.environment.systemPackages
]
[ input.config.system.build.toplevel ] ++ input.config.environment.systemPackages
else
input;
}

1
result Symbolic link
View File

@ -0,0 +1 @@
/nix/store/jji7927zp2qx8j5yazg8hj32mgpqlf76-check-nixos-config