Skip to content

Commit

Permalink
Refactor flake, remove flake-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
SFrijters committed Dec 3, 2024
1 parent eac24be commit 614c6d8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 83 deletions.
5 changes: 5 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
final: prev: {
logwatch = final.callPackage ./packages/logwatch.nix { };
nix-gc-script = final.callPackage ./packages/logwatch-scripts/nix-gc.nix { };
nixos-upgrade-script = final.callPackage ./packages/logwatch-scripts/nixos-upgrade.nix { };
}
34 changes: 0 additions & 34 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 54 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
{
description = "Logwatch for NixOS";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs";

outputs =
{
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages = rec {
default = logwatch;
logwatch = pkgs.callPackage ./packages/logwatch.nix { };
nix-gc-script = pkgs.callPackage ./packages/logwatch-scripts/nix-gc.nix { };
nixos-upgrade-script = pkgs.callPackage ./packages/logwatch-scripts/nixos-upgrade.nix { };
};
let
forAllSystems =
function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
] (system: function nixpkgs.legacyPackages.${system});
in
{
nixosModules.logwatch = import ./modules/logwatch.nix;

overlays.default = import ./.;

packages = forAllSystems (pkgs: rec {
default = logwatch;
logwatch = pkgs.callPackage ./packages/logwatch.nix { };
nix-gc-script = pkgs.callPackage ./packages/logwatch-scripts/nix-gc.nix { };
nixos-upgrade-script = pkgs.callPackage ./packages/logwatch-scripts/nixos-upgrade.nix { };
});

checks.default = pkgs.nixosTest {
checks = forAllSystems (pkgs: {
default = pkgs.nixosTest {
name = "logwatch-module-test";

nodes.server =
Expand All @@ -45,38 +51,37 @@
virtualisation.diskSize = 128; # MB
};

testScript = ''
import time
start_all()
server.wait_for_unit("default.target")
# Force restart of logwatch so it sends a mail
server.systemctl("restart logwatch")
# VMs on CI runners can be kind of slow, delay here
time.sleep(3)
# Get all mails for root and check if the expected subject is there
mail = server.succeed("mail -p")
print(mail)
if "Subject: Logwatch for server" not in mail:
raise Exception("Missing text 'Subject: Logwatch for server' in output of 'mail -p'")
if "unstable" not in "${self.packages.${system}.logwatch.version}":
if "Logwatch ${self.packages.${system}.logwatch.version}" not in mail:
raise Exception("Missing text 'Logwatch ${
self.packages.${system}.logwatch.version
} in output of 'mail -p'")
else:
if "Logwatch ${self.packages.${system}.logwatch.src.rev}" not in mail:
raise Exception("Missing text 'Logwatch ${
self.packages.${system}.logwatch.src.rev
} in output of 'mail -p'")
'';
testScript =
let
inherit (pkgs) system;
in
''
import time
start_all()
server.wait_for_unit("default.target")
# Force restart of logwatch so it sends a mail
server.systemctl("restart logwatch")
# VMs on CI runners can be kind of slow, delay here
time.sleep(3)
# Get all mails for root and check if the expected subject is there
mail = server.succeed("mail -p")
print(mail)
if "Subject: Logwatch for server" not in mail:
raise Exception("Missing text 'Subject: Logwatch for server' in output of 'mail -p'")
if "unstable" not in "${self.packages.${pkgs.system}.logwatch.version}":
if "Logwatch ${self.packages.${pkgs.system}.logwatch.version}" not in mail:
raise Exception("Missing text 'Logwatch ${
self.packages.${pkgs.system}.logwatch.version
} in output of 'mail -p'")
else:
if "Logwatch ${self.packages.${pkgs.system}.logwatch.src.rev}" not in mail:
raise Exception("Missing text 'Logwatch ${
self.packages.${pkgs.system}.logwatch.src.rev
} in output of 'mail -p'")
'';
};
});

formatter = pkgs.nixfmt-rfc-style;
}
)
// {
nixosModules = {
logwatch = import ./modules/logwatch.nix;
};
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}

0 comments on commit 614c6d8

Please sign in to comment.