~zethra/sasha-fetch

8b21407bcb8a77c688d354261597601096115e5f — Sashanoraa 8 months ago 525d247
Nix module
4 files changed, 183 insertions(+), 0 deletions(-)

A flake.lock
A flake.nix
A module.nix
A shell.nix
A flake.lock => flake.lock +60 -0
@@ 0,0 1,60 @@
{
  "nodes": {
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1689068808,
        "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1690179384,
        "narHash": "sha256-+arbgqFTAtoeKtepW9wCnA0njCOyoiDFyl0Q0SBSOtE=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "b12803b6d90e2e583429bb79b859ca53c348b39a",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "ref": "nixos-unstable",
        "type": "indirect"
      }
    },
    "root": {
      "inputs": {
        "flake-utils": "flake-utils",
        "nixpkgs": "nixpkgs"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

A flake.nix => flake.nix +46 -0
@@ 0,0 1,46 @@
{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
				lib = pkgs.lib;
      in
      rec {
        packages = rec {
          sasha-fetch = pkgs.stdenv.mkDerivation rec {
            pname = "sasha-fetch";
            version = "1.0.1";

						src = ./.;

            nativeBuildInputs = with pkgs; [ makeWrapper ];

            installPhase = ''
							mkdir -p $out/bin
							mv sasha-fetch.py $out/bin/sasha-fetch

							wrapProgram $out/bin/sasha-fetch \
								--prefix PATH : ${lib.makeBinPath [ pkgs.python3 pkgs.catimg ]}
            '';

            meta = with lib; {
              homepage = "https://sr.ht/~zethra/sasha-fetch";
              description = "A fun neofetch clone with your info";
              license = licenses.mit;
              maintainers = [ "sashanoraa" ];
            };
          };
          default = sasha-fetch;
        };

        nixosModules = rec {
          sasha-fetch = import ./nixos packages.sasha-fetch;
          default = sasha-fetch;
        };
      });
}

A module.nix => module.nix +72 -0
@@ 0,0 1,72 @@
pkg: { config, lib, pkgs, ... }:

let
  cfg = config.services.sasha-fetch;
in
{

  options.services.sasha-fetch = {
    enable = lib.mkEnableOption "A fun neofetch clone with your info";

    package = lib.mkOption {
      type = lib.types.package;
      default = pkg;
      description = lib.mdDoc ''
        Overridable attribute of the gotosocial package to use.
      '';
    };

    output = lib.mkOption {
      type = lib.types.str;
      description = lib.mdDoc ''
        Path where fetch output is written
      '';
    };

    info = lib.mkOption {
      type = lib.types.path;
      description = lib.mdDoc ''
        Path where info is read from
      '';
    };

    profile-image = lib.mkOption {
      type = lib.types.path;
      description = lib.mdDoc ''
        Path where profile image is read from
      '';
    };

    profile-height = lib.mkOption {
      type = lib.types.int;
      default = 40;
      description = lib.mdDoc ''
        Height of the profile image as ascii
      '';
    };

  };


  config = lib.mkIf cfg.enable {
    systemd = {
      services.sasha-fetch = {
        description = "A fun neofetch clone with your info";
        wantedBy = [ "multi-user.target" ];

        serviceConfig = {
          Type = "oneshot";
          ExecStart = "${cfg.package}/bin/sasha-fetch -H ${cfg.profile-height} ${cfg.info} ${cfg.profile-image} ${cfg.output}";
        };
      };
      timers.sasha-fetch = {
        description = "A fun neofetch clone with your info";
        wantedBy = [ "multi-user.target" ];

        timerConfig = {
          OnCalendar = "*:0/15";
        };
      };
    };
  };
}

A shell.nix => shell.nix +5 -0
@@ 0,0 1,5 @@
{ pkgs ? import <nixpkgs> {} }:

      pkgs.mkShell {
        packages = with pkgs; [ python3 catimg ];
      }