From 71226ec478b71daf6a0e7d151514083feb1ca18f Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sun, 26 Jan 2025 15:38:38 -0600 Subject: templates: add 'system-flake' template --- templates/system-flake/pkgs/config/default.nix | 5 +++++ templates/system-flake/pkgs/config/unfree.nix | 7 +++++++ templates/system-flake/pkgs/default.nix | 12 ++++++++++++ templates/system-flake/pkgs/hello-world/Makefile | 6 ++++++ templates/system-flake/pkgs/hello-world/default.nix | 14 ++++++++++++++ templates/system-flake/pkgs/hello-world/hello-world.c | 7 +++++++ templates/system-flake/pkgs/lib/default.nix | 3 +++ templates/system-flake/pkgs/lib/fibonacci.nix | 7 +++++++ 8 files changed, 61 insertions(+) create mode 100644 templates/system-flake/pkgs/config/default.nix create mode 100644 templates/system-flake/pkgs/config/unfree.nix create mode 100644 templates/system-flake/pkgs/default.nix create mode 100644 templates/system-flake/pkgs/hello-world/Makefile create mode 100644 templates/system-flake/pkgs/hello-world/default.nix create mode 100644 templates/system-flake/pkgs/hello-world/hello-world.c create mode 100644 templates/system-flake/pkgs/lib/default.nix create mode 100644 templates/system-flake/pkgs/lib/fibonacci.nix (limited to 'templates/system-flake/pkgs') diff --git a/templates/system-flake/pkgs/config/default.nix b/templates/system-flake/pkgs/config/default.nix new file mode 100644 index 0000000..395d35d --- /dev/null +++ b/templates/system-flake/pkgs/config/default.nix @@ -0,0 +1,5 @@ +lib: +with lib; { + android_sdk.accept_license = true; + allowUnfreePredicate = pkg: import ./unfree.nix lib (getName pkg); +} diff --git a/templates/system-flake/pkgs/config/unfree.nix b/templates/system-flake/pkgs/config/unfree.nix new file mode 100644 index 0000000..deda971 --- /dev/null +++ b/templates/system-flake/pkgs/config/unfree.nix @@ -0,0 +1,7 @@ +lib: name: +with lib; + elem name [ + "libproprietary-v3" + "closed-source-pkg" + "favorite-abandonware" + ] diff --git a/templates/system-flake/pkgs/default.nix b/templates/system-flake/pkgs/default.nix new file mode 100644 index 0000000..78a86d4 --- /dev/null +++ b/templates/system-flake/pkgs/default.nix @@ -0,0 +1,12 @@ +final: prev: +with prev.lib; let + inherit (final) callPackage fetchpatch; +in { + lib = callPackage ./lib {}; + + hello-world = callPackage ./hello-world {}; + + override = { + sl = prev.sl.overrideAttrs {pname = "my-sl";}; + }; +} diff --git a/templates/system-flake/pkgs/hello-world/Makefile b/templates/system-flake/pkgs/hello-world/Makefile new file mode 100644 index 0000000..4eef056 --- /dev/null +++ b/templates/system-flake/pkgs/hello-world/Makefile @@ -0,0 +1,6 @@ +CFLAGS += -O3 -s + +all: hello-world + +%: %.c + $(CC) $(CFLAGS) -o $@ $< diff --git a/templates/system-flake/pkgs/hello-world/default.nix b/templates/system-flake/pkgs/hello-world/default.nix new file mode 100644 index 0000000..19047a1 --- /dev/null +++ b/templates/system-flake/pkgs/hello-world/default.nix @@ -0,0 +1,14 @@ +{stdenv, ...}: +stdenv.mkDerivation { + name = "hello-world"; + version = "1.0.0"; + + src = ./.; + + installPhase = '' + mkdir -p $out/bin + cp hello-world $out/bin + ''; + + meta.mainProgram = "hello-world"; +} diff --git a/templates/system-flake/pkgs/hello-world/hello-world.c b/templates/system-flake/pkgs/hello-world/hello-world.c new file mode 100644 index 0000000..d6cfa6b --- /dev/null +++ b/templates/system-flake/pkgs/hello-world/hello-world.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + printf("Hello, world!\n"); + return 0; +} diff --git a/templates/system-flake/pkgs/lib/default.nix b/templates/system-flake/pkgs/lib/default.nix new file mode 100644 index 0000000..ab54163 --- /dev/null +++ b/templates/system-flake/pkgs/lib/default.nix @@ -0,0 +1,3 @@ +{callPackage}: { + fibonacci = callPackage ./fibonacci.nix {}; +} diff --git a/templates/system-flake/pkgs/lib/fibonacci.nix b/templates/system-flake/pkgs/lib/fibonacci.nix new file mode 100644 index 0000000..a12576b --- /dev/null +++ b/templates/system-flake/pkgs/lib/fibonacci.nix @@ -0,0 +1,7 @@ +let + fib = n: + if n > 1 + then fib (n - 1) + fib (n - 2) + else 1; +in + fib -- cgit v1.2.3