Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix Flake #130

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c2aceb
add flake
justDeeevin Nov 10, 2024
543e4c0
add home-manager module
justDeeevin Nov 11, 2024
e19ae0f
temp try at home-manager package fix
justDeeevin Nov 11, 2024
3e0737c
maybe home.packages fix
justDeeevin Nov 11, 2024
d71bf8b
better use of callPackage?
justDeeevin Nov 11, 2024
91420b5
remove some unused arguments
justDeeevin Nov 11, 2024
e4ea497
add overlay + most likely fix to home-manager module
justDeeevin Nov 12, 2024
6e0918e
fix overlay addition in home-manager module
justDeeevin Nov 12, 2024
9f28c21
combine textual-autocomplete overlay with exported overlay
justDeeevin Nov 12, 2024
02c4654
parentheses to (hopefully) fix my overlay-combo thingy
justDeeevin Nov 12, 2024
a9f00b0
trying more parentheses stuff
justDeeevin Nov 12, 2024
e994119
add overlay to home-manager module
justDeeevin Nov 12, 2024
f7efcea
stop using `mkPackageOption` in home-manager module
justDeeevin Nov 12, 2024
b9439db
fix home-manager config definition
justDeeevin Nov 12, 2024
2f752f5
add textual-autocomplete to overlays in home-manager module
justDeeevin Nov 12, 2024
c818711
set overlay before setting package
justDeeevin Nov 12, 2024
dc4ce16
include the textual-autocomplete overlay in home-manager module regar…
justDeeevin Nov 12, 2024
be8a3a9
nicer spacing
justDeeevin Nov 12, 2024
a5b09ab
temp gutting of the home-manager module to test something
justDeeevin Nov 12, 2024
c30d221
temp remove home-manager module + use easyOverlay
justDeeevin Nov 12, 2024
d04c7b6
use pkgs.extend to add textual-autocomplete to pkgs
justDeeevin Nov 12, 2024
78b3a42
fix usage of mkPackageOption
justDeeevin Nov 12, 2024
b7f806a
fix typo
justDeeevin Nov 12, 2024
3e98351
use toJSON instead of toYAML
justDeeevin Nov 12, 2024
d47d648
use `prev.callPackage` instead of `final`
justDeeevin Nov 12, 2024
0a4cd64
go back to adding an overlay in home-manager module
justDeeevin Nov 12, 2024
120ad96
add unimplemented option for themes
justDeeevin Nov 12, 2024
c1be09c
implement theme option
justDeeevin Nov 13, 2024
90593f0
put themes in theme folder
justDeeevin Nov 13, 2024
169b271
proper use of builtins.listToAttrs
justDeeevin Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
textual-autocomplete = {
# TODO: update to darrenburns once flake PRr gets merged
url = "github:justdeeevin/textual-autocomplete/flake";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} rec {
imports = [flake-parts.flakeModules.modules];

systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];

flake.overlays.default = final: prev: (
inputs.textual-autocomplete.overlays.default final prev
// {
posting = prev.callPackage ./package.nix {};
}
);

flake.modules.homeManager.default = {
config,
lib,
pkgs,
...
}: let
inherit (lib) mkOption mkIf mkEnableOption mkPackageOption types;
cfg = config.programs.posting;
in {
options.programs.posting = {
enable = mkEnableOption "Posting API client";
package = mkPackageOption pkgs "posting" {};
settings = mkOption {
type = (pkgs.formats.yaml {}).type;
default = {};
example = {
theme = "galaxy";
layout = "horizontal";
response.prettify_json = false;
heading = {
visible = true;
show_host = false;
};
};
description = "Posting configuration settings. See <https://github.com/darrenburns/posting/blob/main/docs/guide/configuration.md>";
};
themes = mkOption {
type = types.listOf ((pkgs.formats.yaml {}).type);
default = {};
description = "List of user-defined themes. See <https://github.com/darrenburns/posting/blob/main/docs/guide/themes.md>";
};
};

config = mkIf cfg.enable {
home.packages = [cfg.package];
home.file =
{".config/posting/config.yaml".text = builtins.toJSON cfg.settings;}
// builtins.listToAttrs (map (theme: {
name = ".local/share/posting/themes/${theme.name}.yaml";
value = {text = builtins.toJSON theme;};
})
cfg.themes);
nixpkgs.overlays = [flake.overlays.default];
};
};

perSystem = {
pkgs,
system,
...
}: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.textual-autocomplete.overlays.default
];
};
packages.default = pkgs.callPackage ./package.nix {};
};
};
}
82 changes: 82 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
pkgs,
lib,
...
}: let
package = builtins.fromTOML (builtins.readFile ./pyproject.toml);
in
pkgs.python312Packages.buildPythonPackage {
pname = package.project.name;
version = package.project.version;
pyproject = true;
src = ./.;
build-system = [pkgs.python312Packages.hatchling];
dependencies = with pkgs.python312Packages; [
click
xdg-base-dirs
click-default-group
httpx
pyperclip
pydantic
pyyaml
pydantic-settings
python-dotenv
(pkgs.textual-autocomplete.overridePythonAttrs
(old: rec {
version = "3.0.0a12";
src = pkgs.fetchPypi {
pname = "textual_autocomplete";
inherit version;
hash = "sha256-HSyeTSTH9XWryMYSy2q//0cG9qqrm5OVBrldroRUkwk=";
};

postPatch = ''
sed -i "/^requires-python =.*/a version = '${version}'" pyproject.toml
'';
}))
(textual.overridePythonAttrs (old: rec {
version = "0.85.0";
src = pkgs.fetchFromGitHub {
owner = "Textualize";
repo = "textual";
rev = "refs/tags/v${version}";
hash = "sha256-ROq/Pjq6XRgi9iqMlCzpLmgzJzLl21MI7148cOxHS3o=";
};

postPatch = ''
sed -i "/^requires-python =.*/a version = '${version}'" pyproject.toml
'';
}))
(watchfiles.overridePythonAttrs (old: rec {
version = "0.24.0";

src = pkgs.fetchFromGitHub {
owner = "samuelcolvin";
repo = "watchfiles";
rev = "refs/tags/v${version}";
hash = "sha256-uc4CfczpNkS4NMevtRxhUOj9zTt59cxoC0BXnuHFzys=";
};

cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/samuelcolvin/watchfiles/refs/tags/v${version}/Cargo.lock";
hash = "sha256-rA6K0bjivOGhoGUYUk5OubFaMh3duEMaDgGtCqbY26g=";
};
outputHashes = {
"notify-6.1.1" = "sha256-lT3R5ZQpjx52NVMEKTTQI90EWT16YnbqphqvZmNpw/I=";
};
};

postPatch = ''
sed -i "/^requires-python =.*/a version = '${version}'" pyproject.toml
substituteInPlace Cargo.toml \
--replace-fail 'version = "0.0.0"' 'version = "${version}"'
'';
}))
];
meta = {
description = package.project.description;
homepage = package.project.urls.homepage;
license = lib.licenses.asl20;
};
}