diff --git a/flake.nix b/flake.nix index 26c7640..a68dccc 100644 --- a/flake.nix +++ b/flake.nix @@ -5,42 +5,45 @@ nixpkgs.url = github:nixos/nixpkgs/nixos-23.05; }; - outputs = { self, nixpkgs }: - let - supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); - in { + outputs = { + self, + nixpkgs, + } @ inputs: let + supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in { + # Formatter + formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); - # Formatter - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); + # Packages + packages = forAllSystems (system: { + default = pkgs.${system}.poetry2nix.mkPoetryApplication {projectDir = self;}; + }); - # Packages - packages = forAllSystems (system: { - default = pkgs.${system}.poetry2nix.mkPoetryApplication { projectDir = self; }; - }); + # Dev Shell + devShells = forAllSystems (system: { + default = pkgs.${system}.mkShellNoCC { + shellHook = "echo Welcome to your nix-powered dev environment for dyn-gandi!"; - # Dev Shell - devShells = forAllSystems (system: { - default = pkgs.${system}.mkShellNoCC { - shellHook = "Welcome to your nix-powered dev environment for dyn-gandi!"; + packages = with pkgs.${system}; [ + (poetry2nix.mkPoetryEnv {projectDir = self;}) + poetry + ]; + }; + }); - packages = with pkgs.${system}; [ - (poetry2nix.mkPoetryEnv { projectDir = self; }) - poetry - ]; + # Run as apps + apps = forAllSystems (system: { + default = { + program = "${self.packages.${system}.default}/bin/dyn_gandi"; + type = "app"; + }; + }); - }; - }); - - # Run as apps - apps = forAllSystems (system: { - default = { - program = "${self.packages.${system}.default}/bin/dyn_gandi"; - type = "app"; - }; - }); - - homeManagerModules.default = import ./nix/hm-module.nix self; - }; + # Home Manager Module + homeManagerModules.default = import ./nix/hm-module.nix self; + # NixOS Module + #nixosModules.default = import ./nix/module.nix inputs; + }; } diff --git a/nix/hm-module.nix b/nix/hm-module.nix index b5611d2..c64c9b2 100644 --- a/nix/hm-module.nix +++ b/nix/hm-module.nix @@ -1,15 +1,72 @@ -{ config, lib, pkgs, ... }: -let - cfg = config.dyn-gandi; +self: { + config, + lib, + pkgs, + ... +}: let + cfg = config.services.dyn-gandi; + inherit (lib) mkIf mkEnableOption mkOption types; in { + options.services.dyn-gandi = { + enable = mkEnableOption "dyn-gandi"; - options.dyn-gandi = { - enable = lib.mkEnableOption null // { - description = lib.mdDoc ''''; + timer = lib.mkOption { + type = lib.types.int; + default = 0; + description = lib.mdDoc '' + The time intervall in seconds the script should be repeated. + 0 disables automatic starts. + ''; + }; + + settings = mkOption { + type = with types; let + valueType = nullOr (oneOf [ + bool + int + float + str + path + (attrsOf valueType) + (listOf valueType) + ]); + in + valueType; + + default = {api = {"example.com" = ["@" "www"];};}; + example = { + General = { + disabledTrayIcon = true; + showStartupLaunchMessage = false; + }; + }; + description = ''''; }; }; - config = lib.mkIf cfg.enable { + config = mkIf cfg.enable { + home.packages = [self.packages.x86_64-linux.default]; -}; -} \ No newline at end of file + xdg.configFile."dyn-gandi/config.json" = { + text = builtins.toJSON cfg.settings; + }; + + systemd.user.services.dyn-gandi = + mkIf cfg.timer + != 0 { + Unit = { + Description = "DNS Updater tool for Gandi.net"; + After = ["graphical-session-pre.target"]; + PartOf = ["graphical-session.target"]; + }; + }; + systemd.user.timers.dyn-gandi = { + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "0s"; + OnUnitActiveSec = "${cfg.timer}s"; + Unit = "dyn-gandi.service"; + }; + }; + }; +} diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..65366b6 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,16 @@ +inputs: { config, lib, pkgs, ... }: +let + cfg = config.services.dyn-gandi; + inherit (lib) mkIf mkEnableOption; + #package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default; +in { + + options.services.dyn-gandi = { + enable = mkEnableOption null; + }; + + config = mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + } + +} \ No newline at end of file