Skip to content

Commit

Permalink
Formatting and cleanup in flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzleutgeb committed Aug 3, 2023
1 parent f4af99d commit 66a4995
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 102 deletions.
2 changes: 1 addition & 1 deletion configs/all-configurations.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{ pkgs }: {
{pkgs}: {
liberaforms-container = import ./liberaforms/container.nix;
}
102 changes: 54 additions & 48 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,64 @@
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";

outputs = inputs@{ self, nixpkgs, flake-utils, treefmt-nix, ... }:
let
buildOutputs = system:
let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in {
packages = import ./all-packages.nix { inherit (pkgs) newScope; };
nixosModules = {
modules = import ./modules/all-modules.nix;
ngipkgs = { ... }: {
# Inject an additional argument into the module system evaluation.
# This way our package set can be accessed separately and we don't have
# to muck around with overlays (which don't work with flakes as you'd expect)
_module.args.ngipkgs = self.packages.${system};
};
};

formatter = treefmtEval.config.build.wrapper;
outputs = {
self,
nixpkgs,
flake-utils,
treefmt-nix,
...
}: let
buildOutputs = system: let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in {
packages = import ./all-packages.nix {inherit (pkgs) newScope;};
nixosModules = {
modules = import ./modules/all-modules.nix;
ngipkgs = {...}: {
# Inject an additional argument into the module system evaluation.
# This way our package set can be accessed separately and we don't have
# to muck around with overlays (which don't work with flakes as you'd expect)
_module.args.ngipkgs = self.packages.${system};
};
};

checkOutputs = system:
let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
inject-ngipkgs = k: v:
pkgs.nixos
({ ... }: { imports = [ self.nixosModules.${system}.ngipkgs v ]; });

ngipkgsModule = self.nixosModules.${system}.ngipkgs;
in {
# Configurations have to go in checkOutputs (ie, avoid `eachDefaultSystem`) to generate
# a single attribute name for nixos-container deployments (`<config-name>`), because
# nixos-container can't parse dot-separated sequence attribute paths (`x86_64-linux.<config-name>`).
nixosConfigurations = let
all-configurations =
import ./configs/all-configurations.nix { inherit pkgs; };
in builtins.mapAttrs inject-ngipkgs all-configurations;
formatter = treefmtEval.config.build.wrapper;
};

# To generate a Hydra jobset for CI builds of all packages
# https://hydra.ngi0.nixos.org/jobset/ngipkgs/main
hydraJobs = { packages.${system} = self.packages.${system}; };
checkOutputs = system: let
pkgs = nixpkgs.legacyPackages.${system};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
ngipkgsModule = self.nixosModules.${system}.ngipkgs;
in {
# Configurations have to go in checkOutputs (ie, avoid `eachDefaultSystem`) to generate
# a single attribute name for nixos-container deployments (`<config-name>`), because
# nixos-container can't parse dot-separated sequence attribute paths (`x86_64-linux.<config-name>`).
nixosConfigurations = let
all-configurations = import ./configs/all-configurations.nix {inherit pkgs;};
inject-ngipkgs = k: v: pkgs.nixos ({...}: {imports = [ngipkgsModule v];});
in
builtins.mapAttrs inject-ngipkgs all-configurations;

test-pretalx = pkgs.nixosTest
(import ./tests/pretalx/pretalx.nix { inherit ngipkgsModule;});
# To generate a Hydra jobset for CI builds of all packages
# https://hydra.ngi0.nixos.org/jobset/ngipkgs/main
hydraJobs = {
packages.${system} = self.packages.${system};
};

# For .github/workflows/ci.yaml to *build* all packages, because
# `nix flake check` only evaluates packages, but it builds checks.
checks.${system} = self.packages.${system} // {
formatting = treefmtEval.config.build.check self;
};
# For .github/workflows/ci.yaml to *build* all packages, because
# `nix flake check` only evaluates packages, but it builds checks.
checks.${system} =
self.packages.${system}
// {
formatting = treefmtEval.config.build.check self;
test-pretalx =
pkgs.nixosTest
(import ./tests/pretalx/pretalx.nix {
inherit ngipkgsModule;
});
};
in (flake-utils.lib.eachDefaultSystem buildOutputs)
// (checkOutputs "x86_64-linux");
};
in
(flake-utils.lib.eachDefaultSystem buildOutputs) // (checkOutputs "x86_64-linux");
}
47 changes: 28 additions & 19 deletions modules/pretalx.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{ config, lib, pkgs, ngipkgs, ... }:
with lib;
let
{
config,
lib,
pkgs,
ngipkgs,
...
}:
with lib; let
cfg = config.services.pretalx;
group = "pretalx";
default_home = "/var/lib/pretalx";
Expand All @@ -20,26 +25,30 @@ let
port = "8001";
};

environmentFile = pkgs.runCommand "pretalx-environ" {
buildInputs = [ pretalx gunicorn ]; # Sets PYTHONPATH in derivation
} ''
cat > $out <<EOF
PYTHONPATH=$PYTHONPATH
EOF
'';

mkTimer = { description, unit, onCalendar }: {
environmentFile =
pkgs.runCommand "pretalx-environ" {
buildInputs = [pretalx gunicorn]; # Sets PYTHONPATH in derivation
} ''
cat > $out <<EOF
PYTHONPATH=$PYTHONPATH
EOF
'';

mkTimer = {
description,
unit,
onCalendar,
}: {
inherit description;
requires = [ "pretalx-migrate.service" ];
after = [ "network.target" ];
wantedBy = [ "timers.target" ];
requires = ["pretalx-migrate.service"];
after = ["network.target"];
wantedBy = ["timers.target"];
timerConfig = {
Persistent = true;
OnCalendar = onCalendar;
Unit = unit;
};
};

in {
options.services.pretalx = with types; {
enable = mkEnableOption "pretalx server";
Expand Down Expand Up @@ -115,9 +124,9 @@ in {
--bind=${server.bind}:${server.port}
'';
};
wantedBy = [ "multi-user.target" ];
requires = [ "pretalx-migrate.service" ];
after = [ "network.target" ];
wantedBy = ["multi-user.target"];
requires = ["pretalx-migrate.service"];
after = ["network.target"];
};

systemd.services.pretalx-clearsessions = {
Expand Down
65 changes: 35 additions & 30 deletions pkgs/pretalx/default.nix
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
{ lib, fetchFromGitHub, gettext, poetry2nix }:
let
{
lib,
fetchFromGitHub,
gettext,
poetry2nix,
}: let
pname = "pretalx";
version = "v2.3.2";
in (poetry2nix.mkPoetryApplication {
projectDir = ./.;
propagatedBuildInputs = [ gettext ];
propagatedBuildInputs = [gettext];

overrides = poetry2nix.overrides.withDefaults (self: super:
let
f = (old: {
propagatedBuildInputs = (old.propagatedBuildInputs or [ ])
++ [ self.setuptools ];
});
in {
defusedcsv = super.defusedcsv.overridePythonAttrs f;
django-context-decorator =
super.django-context-decorator.overridePythonAttrs f;
django-i18nfield = super.django-i18nfield.overridePythonAttrs f;
publicsuffixlist = super.publicsuffixlist.overridePythonAttrs f;
rules = super.rules.overridePythonAttrs f;
urlman = super.urlman.overridePythonAttrs f;
kombu = super.kombu.overridePythonAttrs
(old: (f old) // { patches = [ ./kombu.patch ]; });
celery = super.celery.overridePythonAttrs
(old: { patches = [ ./celery.patch ]; });
django-hierarkey = super.django-hierarkey.overridePythonAttrs f;
django-jquery-js = super.django-jquery-js.overridePythonAttrs f;
django-scopes = super.django-scopes.overridePythonAttrs f;
django-bootstrap4 = super.django-bootstrap4.overridePythonAttrs f;
inlinestyler = super.inlinestyler.overridePythonAttrs f;
django-libsass = super.django-libsass.overridePythonAttrs f;
});
overrides = poetry2nix.overrides.withDefaults (self: super: let
f = old: {
propagatedBuildInputs =
(old.propagatedBuildInputs or [])
++ [self.setuptools];
};
in {
defusedcsv = super.defusedcsv.overridePythonAttrs f;
django-context-decorator =
super.django-context-decorator.overridePythonAttrs f;
django-i18nfield = super.django-i18nfield.overridePythonAttrs f;
publicsuffixlist = super.publicsuffixlist.overridePythonAttrs f;
rules = super.rules.overridePythonAttrs f;
urlman = super.urlman.overridePythonAttrs f;
kombu =
super.kombu.overridePythonAttrs
(old: (f old) // {patches = [./kombu.patch];});
celery =
super.celery.overridePythonAttrs
(old: {patches = [./celery.patch];});
django-hierarkey = super.django-hierarkey.overridePythonAttrs f;
django-jquery-js = super.django-jquery-js.overridePythonAttrs f;
django-scopes = super.django-scopes.overridePythonAttrs f;
django-bootstrap4 = super.django-bootstrap4.overridePythonAttrs f;
inlinestyler = super.inlinestyler.overridePythonAttrs f;
django-libsass = super.django-libsass.overridePythonAttrs f;
});

meta = with lib; {
description = pname;
homepage = "https://example.com";
license = licenses.unlicense;
maintainers = [ ];
maintainers = [];
};
})

8 changes: 4 additions & 4 deletions tests/pretalx/pretalx.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{ ngipkgsModule, ... }: {
{ngipkgsModule, ...}: {
name = "pretalx tests";

nodes = {
server = {
imports = [
imports = [
../../modules/pretalx.nix
ngipkgsModule
];

networking.firewall.allowedTCPPorts = [ 8001 ];
networking.firewall.allowedTCPPorts = [8001];

services.pretalx = {
enable = true;
Expand Down Expand Up @@ -52,7 +52,7 @@
};
};

testScript = { nodes, ... }: ''
testScript = {nodes, ...}: ''
start_all()
with subtest("Test http service"):
Expand Down

0 comments on commit 66a4995

Please sign in to comment.