From 9a184ae55e1ca85244eb436c1f38d116be750f69 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 29 Jul 2024 08:59:12 -0700 Subject: [PATCH] Add flake checks --- checks.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 15 ++++++++++--- lib.nix | 11 ++------- result | 1 + 4 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 checks.nix create mode 120000 result diff --git a/checks.nix b/checks.nix new file mode 100644 index 0000000..fb376e1 --- /dev/null +++ b/checks.nix @@ -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); +} diff --git a/flake.nix b/flake.nix index 9c38094..8b2ca65 100644 --- a/flake.nix +++ b/flake.nix @@ -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}; + } + ); }; } diff --git a/lib.nix b/lib.nix index 79713dc..a3630dc 100644 --- a/lib.nix +++ b/lib.nix @@ -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; } diff --git a/result b/result new file mode 120000 index 0000000..3edff72 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/jji7927zp2qx8j5yazg8hj32mgpqlf76-check-nixos-config \ No newline at end of file