Skip to content

Commit

Permalink
Merge branch 'main' into rm-unused-flarum-opt-binding
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzleutgeb authored Dec 1, 2023
2 parents 96caca5 + 1681c4f commit 1b4770e
Show file tree
Hide file tree
Showing 32 changed files with 759 additions and 513 deletions.
240 changes: 123 additions & 117 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,139 +20,145 @@
treefmt-nix,
sops-nix,
...
}:
with builtins; let
inherit
(nixpkgs.lib)
concatMapAttrs
mapAttrs'
foldr
recursiveUpdate
nameValuePair
nixosSystem
filterAttrs
;

importPackages = pkgs: let
nixosTests = let
dir = ./tests;
testDirs = readDir dir;

dirToTest = name: _: let
mkTestModule = import "${dir}/${name}";

testModule = mkTestModule {
inherit pkgs;
inherit (pkgs) lib;
modules = extendedModules;
configurations = rawNixosConfigs;
};
in
pkgs.nixosTest testModule;
}: let
inherit
(builtins)
readDir
mapAttrs
attrValues
;

inherit
(nixpkgs.lib)
concatMapAttrs
mapAttrs'
foldr
recursiveUpdate
nameValuePair
nixosSystem
filterAttrs
;

importPackages = pkgs: let
nixosTests = let
dir = ./tests;
testDirs = readDir dir;

dirToTest = name: _: let
mkTestModule = import "${dir}/${name}";

testModule = mkTestModule {
inherit pkgs;
inherit (pkgs) lib;
modules = extendedModules;
configurations = rawNixosConfigs;
};
in
mapAttrs dirToTest testDirs;
pkgs.nixosTest testModule;
in
mapAttrs dirToTest testDirs;

callPackage = pkgs.newScope (
allPackages // {inherit callPackage nixosTests;}
);
callPackage = pkgs.newScope (
allPackages // {inherit callPackage nixosTests;}
);

pkgsByName = import ./pkgs/by-name {
inherit (pkgs) lib;
inherit callPackage;
};
pkgsByName = import ./pkgs/by-name {
inherit (pkgs) lib;
inherit callPackage;
};

explicitPkgs = import ./pkgs {
inherit (pkgs) lib;
inherit callPackage;
};
explicitPkgs = import ./pkgs {
inherit (pkgs) lib;
inherit callPackage;
};

allPackages = pkgsByName // explicitPkgs;
in
allPackages;
allPackages = pkgsByName // explicitPkgs;
in
allPackages;

importNixpkgs = system: overlays: import nixpkgs {inherit system overlays;};
importNixpkgs = system: overlays: import nixpkgs {inherit system overlays;};

rawNixosConfigs = import ./configs/all-configurations.nix;
rawNixosConfigs = import ./configs/all-configurations.nix;

loadTreefmt = pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
loadTreefmt = pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

# Attribute set containing all modules obtained via `inputs` and defined
# in this flake towards definition of `nixosConfigurations` and `nixosTests`.
extendedModules =
self.nixosModules
// {
sops-nix = sops-nix.nixosModules.default;
};

# Attribute set containing all modules obtained via `inputs` and defined
# in this flake towards definition of `nixosConfigurations` and `nixosTests`.
extendedModules =
self.nixosModules
nixosConfigurations =
mapAttrs
(_: config: nixosSystem {modules = [config] ++ attrValues extendedModules;})
rawNixosConfigs;

eachDefaultSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let
pkgs = importNixpkgs system [];
treefmtEval = loadTreefmt pkgs;
toplevel = name: config: nameValuePair "${name}-toplevel" config.config.system.build.toplevel;
in {
packages = importPackages pkgs;
formatter = treefmtEval.config.build.wrapper;
checks = mapAttrs' toplevel nixosConfigurations;
});

x86_64-linuxOutputs = let
system = "x86_64-linux";
pkgs = importNixpkgs system [self.overlays.default];
treefmtEval = loadTreefmt pkgs;
nonBrokenPkgs = filterAttrs (_: v: !v.meta.broken) self.packages.${system};
in {
# Github Actions executes `nix flake check` therefore this output
# should only contain derivations that can built within CI.
# See `.github/workflows/ci.yaml`.
checks.${system} =
# For `nix flake check` to *build* all packages, because by default
# `nix flake check` only evaluates packages and does not build them.
nonBrokenPkgs
// {
sops-nix = sops-nix.nixosModules.default;
formatting = treefmtEval.config.build.check self;
};

nixosConfigurations =
mapAttrs
(_: config: nixosSystem {modules = [config] ++ attrValues extendedModules;})
rawNixosConfigs;

eachDefaultSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let
pkgs = importNixpkgs system [];
treefmtEval = loadTreefmt pkgs;
toplevel = name: config: nameValuePair "${name}-toplevel" config.config.system.build.toplevel;
in {
packages = importPackages pkgs;
formatter = treefmtEval.config.build.wrapper;
checks = mapAttrs' toplevel nixosConfigurations;
});

x86_64-linuxOutputs = let
system = "x86_64-linux";
pkgs = importNixpkgs system [self.overlays.default];
treefmtEval = loadTreefmt pkgs;
nonBrokenPkgs = filterAttrs (_: v: !v.meta.broken) self.packages.${system};
# To generate a Hydra jobset for CI builds of all packages and tests.
# See <https://hydra.ngi0.nixos.org/jobset/ngipkgs/main>.
hydraJobs = let
passthruTests = concatMapAttrs (name: value:
if value ? passthru.tests
then {${name} = value.passthru.tests;}
else {})
nonBrokenPkgs;
in {
# Github Actions executes `nix flake check` therefore this output
# should only contain derivations that can built within CI.
# See `.github/workflows/ci.yaml`.
checks.${system} =
# For `nix flake check` to *build* all packages, because by default
# `nix flake check` only evaluates packages and does not build them.
nonBrokenPkgs
// {
formatting = treefmtEval.config.build.check self;
};
packages.${system} = nonBrokenPkgs;
tests.${system} = passthruTests;

# To generate a Hydra jobset for CI builds of all packages and tests.
# See <https://hydra.ngi0.nixos.org/jobset/ngipkgs/main>.
hydraJobs = let
passthruTests = concatMapAttrs (name: value:
if value ? passthru.tests
then {${name} = value.passthru.tests;}
else {})
nonBrokenPkgs;
in {
packages.${system} = nonBrokenPkgs;
tests.${system} = passthruTests;

nixosConfigurations.${system} =
mapAttrs
(name: config: config.config.system.build.toplevel)
nixosConfigurations;
};
nixosConfigurations.${system} =
mapAttrs
(name: config: config.config.system.build.toplevel)
nixosConfigurations;
};
};

systemAgnosticOutputs = {
inherit nixosConfigurations;
systemAgnosticOutputs = {
inherit nixosConfigurations;

nixosModules =
(import ./modules/all-modules.nix)
// {
# The default module adds the default overlay on top of nixpkgs.
# This is so that `ngipkgs` can be used alongside `nixpkgs` in a configuration.
default.nixpkgs.overlays = [self.overlays.default];
};
nixosModules =
(import ./modules/all-modules.nix)
// {
# The default module adds the default overlay on top of nixpkgs.
# This is so that `ngipkgs` can be used alongside `nixpkgs` in a configuration.
default.nixpkgs.overlays = [self.overlays.default];
};

# Overlays a package set (e.g. nixpkgs) with the packages defined in this flake.
overlays.default = final: prev: importPackages prev;
};
in
foldr recursiveUpdate {} [
eachDefaultSystemOutputs
x86_64-linuxOutputs
systemAgnosticOutputs
];
# Overlays a package set (e.g. nixpkgs) with the packages defined in this flake.
overlays.default = final: prev: importPackages prev;
};
in
foldr recursiveUpdate {} [
eachDefaultSystemOutputs
x86_64-linuxOutputs
systemAgnosticOutputs
];
}
25 changes: 20 additions & 5 deletions modules/flarum.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
{
config,
options,
lib,
pkgs,
self,
utils,
...
}:
with builtins;
with lib; let
}: let
inherit
(builtins)
toJSON
;

inherit
(lib)
types
mkOption
mkIf
mkEnableOption
mkPackageOption
optionalString
mkDefault
;

cfg = config.services.flarum;

flarumInstallConfig = pkgs.writeText "config.json" (builtins.toJSON {
flarumInstallConfig = pkgs.writeText "config.json" (toJSON {
debug = false;
offline = false;

Expand Down Expand Up @@ -203,7 +218,7 @@ in {
chmod a+x . public
chmod +x site.php extend.php flarum
''
+ lib.optionalString
+ optionalString
(cfg.createDatabaseLocally && cfg.database.driver == "mysql") ''
if [ ! -f config.php ]; then
php flarum install --file=${flarumInstallConfig}
Expand Down
45 changes: 33 additions & 12 deletions modules/kbin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,32 @@
pkgs,
...
}: let
inherit (lib.attrsets) filterAttrs mapAttrs mapAttrsToList;
inherit (lib.generators) mkValueStringDefault;
inherit (lib.lists) map optional;
inherit (lib.meta) getExe;
inherit (lib.strings) concatLines;
inherit
(builtins)
map
attrNames
listToAttrs
;

inherit
(lib)
options
types
modules
filterAttrs
mapAttrs
mapAttrsToList
optional
getExe
strings
concatLines
generators
;

inherit
(generators)
mkValueStringDefault
;

cfg = config.services.kbin;
opt = options.services.kbin;
Expand All @@ -19,8 +40,8 @@
secretsNonNull = filterAttrs (_: value: value != null) cfg.secrets;

# For usage of secrets via systemd credentials:
credentialIds = builtins.attrNames secretsNonNull;
loadCredentials = mapAttrsToList (name: value: "${name}:${builtins.toString value}") secretsNonNull;
credentialIds = attrNames secretsNonNull;
loadCredentials = mapAttrsToList (name: value: "${name}:${toString value}") secretsNonNull;

kbin-console = pkgs.writeShellApplication rec {
name = "kbin-console";
Expand Down Expand Up @@ -48,8 +69,8 @@
'';
};
in {
options.services.kbin = with lib.types;
with lib.options; {
options.services.kbin = with types;
with options; {
enable = mkEnableOption "Kbin";

package = mkPackageOption pkgs "kbin" {};
Expand Down Expand Up @@ -82,7 +103,7 @@ in {
type = submodule {
freeformType = attrsOf (nullOr path);

options = builtins.listToAttrs (builtins.map (
options = listToAttrs (map (
name: {
inherit name;
value = mkOption {
Expand All @@ -106,8 +127,8 @@ in {
};
};

config = with lib.modules;
with lib.options;
config = with modules;
with options;
mkIf cfg.enable {
warnings =
optional (cfg.settings.APP_ENV == "prod" && cfg.settings.APP_DEBUG != "0")
Expand Down
Loading

0 comments on commit 1b4770e

Please sign in to comment.