Skip to content

Commit

Permalink
✨ (templates): Added some personal Nix templates
Browse files Browse the repository at this point in the history
  • Loading branch information
theobori committed Nov 14, 2024
1 parent d944e41 commit 950f06f
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 1 deletion.
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,10 @@
};

outputs-builder = channels: { formatter = channels.nixpkgs.nixfmt-rfc-style; };

templates = {
xdp-c.description = "My template for building a XDP program in C";
python.description = "My template for a base project in Python";
};
};
}
2 changes: 1 addition & 1 deletion modules/home/desktops/addons/plasma6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ in
extraWorkspace = mkOpt attrs {
colorScheme = "DraculaPurple";
theme = "Dracula";
lookAndFeel = "Dracula";
#lookAndFeel = "Dracula";

windowDecorations = {
library = "org.kde.kwin.aurorae";
Expand Down
25 changes: 25 additions & 0 deletions templates/python/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
lib,
buildPythonPackage,
setuptools,
}:
buildPythonPackage {
pname = "pname";
version = "version";
pyproject = true;

src = ./.;

dependencies = [ ];

nativeBuildInputs = [ setuptools ];

pythonImportsCheck = [ "complete" ];

meta = {
description = "My project description";
homepage = "My project homepage";
license = lib.licenses.mit;
mainProgram = "program name";
};
}
50 changes: 50 additions & 0 deletions templates/python/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
treefmt-nix,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages = {
default = pkgs.callPackage ./. { inherit (pkgs.python3Packages) buildPythonPackage setuptools; };
};

devShells = {
default = pkgs.mkShell {
venvDir = ".venv";
packages =
with pkgs;
[
python3
pypy
]
++ (with pkgs.python3Packages; [
pip
venvShellHook
]);
};
};

formatter = treefmtEval.config.build.wrapper;

checks = {
formatting = treefmtEval.config.build.check self;
};
}
);
}
6 changes: 6 additions & 0 deletions templates/python/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs.black.enable = true;
programs.nixfmt.enable = true;
}
45 changes: 45 additions & 0 deletions templates/xdp-c/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
stdenv,
lib,
xdp-tools,
clang,
libbpf,
zlib,
elfutils,
pkgsi686Linux,
llvm_18,
}:
stdenv.mkDerivation {
pname = "pname";
version = "version";

src = ./.;

buildInputs = [
xdp-tools
clang
libbpf
zlib
elfutils
pkgsi686Linux.glibc
llvm_18
];

hardeningDisable = [
"stackprotector"
"zerocallusedregs"
];

installPhase = ''
mkdir -p $out/bin
cp tinyfilter $out/bin
'';

meta = {
description = "My project description";
homepage = "My project homepage";
license = lib.licenses.mit;
mainProgram = "program name";
};
}
46 changes: 46 additions & 0 deletions templates/xdp-c/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
treefmt-nix,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages = {
default = pkgs.callPackage ./. { };
};

devShells = {
default = pkgs.mkShell {
packages =
with pkgs;
[
bpftop
bpftools
]
++ self.packages.${system}.default.buildInputs;
};
};

formatter = treefmtEval.config.build.wrapper;

checks = {
formatting = treefmtEval.config.build.check self;
};
}
);
}
6 changes: 6 additions & 0 deletions templates/xdp-c/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs.clang-format.enable = true;
programs.nixfmt.enable = true;
}

0 comments on commit 950f06f

Please sign in to comment.