From 4a4f0e6947d220ca390ad4982ae0de32435d08a0 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 5 May 2025 14:52:28 +0200 Subject: [PATCH] module.nix: config -> settings --- example-config.ini | 4 ++-- flake.nix | 6 +++--- nix/module.nix | 28 ++++++++++++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/example-config.ini b/example-config.ini index c382fc9..7abacb0 100644 --- a/example-config.ini +++ b/example-config.ini @@ -5,8 +5,8 @@ show_tracebacks = true input_encoding = 'utf8' [database] -; url = postgresql://robertem@127.0.0.1/pvvvv -url = sqlite:///test.db +# url = "postgresql://robertem@127.0.0.1/pvvvv" +url = "sqlite:///test.db" [limits] low_credit_warning_limit = -100 diff --git a/flake.nix b/flake.nix index c6e7c8f..4410f60 100644 --- a/flake.nix +++ b/flake.nix @@ -5,14 +5,14 @@ outputs = { self, nixpkgs, flake-utils }: let inherit (nixpkgs) lib; - + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - + forAllSystems = f: lib.genAttrs systems (system: let pkgs = nixpkgs.legacyPackages.${system}; in f system pkgs); @@ -45,7 +45,7 @@ python = pkgs.python312; }; }); - + # Note: using the module requires that you have applied the overlay first nixosModules.default = import ./nix/module.nix; diff --git a/nix/module.nix b/nix/module.nix index b8bd24a..79bf26a 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,21 +1,31 @@ { config, pkgs, lib, ... }: let cfg = config.services.dibbler; + + format = pkgs.formats.ini { }; in { options.services.dibbler = { enable = lib.mkEnableOption "dibbler, the little kiosk computer"; - + package = lib.mkPackageOption pkgs "dibbler" { }; - - config = lib.mkOption { - type = lib.types.path; - description = "Path to the configuration file."; - default = ../example-config.ini; + + settings = lib.mkOption { + description = "Configuration for dibbler"; + default = { }; + type = lib.types.submodule { + freeformType = format.type; + }; }; }; config = let screen = "${pkgs.screen}/bin/screen"; in lib.mkIf cfg.enable { + services.dibbler.settings = lib.pipe ../example-config.ini [ + builtins.readFile + builtins.fromTOML + (lib.mapAttrsRecursive (_: lib.mkDefault)) + ]; + boot = { consoleLogLevel = 0; enableContainers = false; @@ -28,7 +38,7 @@ in { group = "dibbler"; extraGroups = [ "lp" ]; isNormalUser = true; - shell = ((pkgs.writeShellScriptBin "login-shell" "${screen} -x dibbler") // {shellPath = "/bin/login-shell";}); + shell = (pkgs.writeShellScriptBin "login-shell" "${screen} -x dibbler") // {shellPath = "/bin/login-shell";}; }; }; @@ -37,7 +47,9 @@ in { wantedBy = [ "default.target" ]; serviceConfig = { ExecStartPre = "-${screen} -X -S dibbler kill"; - ExecStart = "${screen} -dmS dibbler -O -l ${cfg.package}/bin/dibbler --config ${cfg.config} loop"; + ExecStart = let + config = format.generate "dibbler-config.ini" cfg.settings; + in "${screen} -dmS dibbler -O -l ${cfg.package}/bin/dibbler --config ${config} loop"; ExecStartPost = "${screen} -X -S dibbler width 42 80"; User = "dibbler"; Group = "dibbler";