From 1e7ccb7acf70805693d6e8f4a4ef01d191804544 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 26 Nov 2025 16:53:32 -0500 Subject: [PATCH 1/6] refactor: improve `flake.nix` code --- flake.nix | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/flake.nix b/flake.nix index 51cee52..2ec1f3f 100644 --- a/flake.nix +++ b/flake.nix @@ -2,41 +2,45 @@ description = "Hello World flake templates for various languages and build systems"; outputs = { self, ... }: - let + with builtins; let + concatMapAttrs = func: attr: + foldl' (x: y: x // y) {} (map func attr); + + # Template Aliases + # Used to pick default template for each language aliases = { bash = "bash_script_nixpkgs"; fish = "fish_script_nixpkgs"; python = "python_pyproject_nixpkgs_basic"; }; - # Get all project directories + # Get all subdirectories of the given path + # Returns [str] subdirs = dir: - let sub = __readDir dir; - in builtins.filter - (d: sub.${d} == "directory") - (builtins.attrNames sub); - - concatMapAttrs = func: attr: - builtins.foldl' (x: y: x // y) {} - (builtins.map func attr); + let subd = readDir dir; + in filter (d: subd.${d} == "directory") (attrNames subd); + # Get all proper recursive subdirectories with flakes in them + # Returns [[str]] (list of subdirectory sequences, for processing) flakeSubdirs = dir: - builtins.concatMap (sub: - if builtins.pathExists /${dir}/${sub}/flake.nix then [ [ sub ] ] else - builtins.map (l: [ sub ] ++ l) (flakeSubdirs /${dir}/${sub})) + concatMap (subd: + if pathExists /${dir}/${subd}/flake.nix then [ [ subd ] ] else + map (l: [ subd ] ++ l) (flakeSubdirs /${dir}/${subd})) (subdirs dir); + + generateDesc = subds: + "${head subds} template - ${concatStringsSep ", " (tail subds)}"; in { - templates = concatMapAttrs (path: { - ${builtins.concatStringsSep "_" path} = { - description = "${builtins.head path} template - ${builtins.concatStringsSep - ", " (builtins.tail path)}"; - path = builtins.filterSource - (path: type: builtins.baseNameOf path != "flake.lock") - (builtins.foldl' (dir: sub: /${dir}/${sub}) ./. path); + templates = concatMapAttrs (subds: { + ${concatStringsSep "_" subds} = { + description = generateDesc subds; + path = filterSource + (p: _: baseNameOf p != "flake.lock") + (foldl' (dir: subd: /${dir}/${subd}) ./. subds); }; - }) (flakeSubdirs ./.) // builtins.mapAttrs (lang: def: - self.templates.${def} // { - description = "${lang} template"; - }) aliases; + }) (flakeSubdirs ./.) // mapAttrs (from: to: + self.templates.${to} // { + description = generateDesc (filter (p: p != []) (split "_" to)); + }) aliases; }; } From 2225d6a02c56613f71ea61dccb55acd73730e421 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 26 Nov 2025 16:53:43 -0500 Subject: [PATCH 2/6] refactor: fix `shell.nix` interface --- bash/script/nixpkgs/package.nix | 5 +++-- fish/script/nixpkgs/package.nix | 5 +++-- python/pyproject/nixpkgs/basic/flake.nix | 2 +- python/pyproject/nixpkgs/basic/package.nix | 3 ++- python/pyproject/nixpkgs/basic/shell.nix | 11 ++++++----- python/pyproject/nixpkgs/cli/flake.nix | 2 +- python/pyproject/nixpkgs/cli/package.nix | 3 ++- python/pyproject/nixpkgs/cli/shell.nix | 11 ++++++----- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/bash/script/nixpkgs/package.nix b/bash/script/nixpkgs/package.nix index 458a1ce..8c36ba4 100644 --- a/bash/script/nixpkgs/package.nix +++ b/bash/script/nixpkgs/package.nix @@ -1,5 +1,6 @@ -{ stdenvNoCC -, bash +{ + stdenvNoCC, + bash, }: stdenvNoCC.mkDerivation { diff --git a/fish/script/nixpkgs/package.nix b/fish/script/nixpkgs/package.nix index 6e6dcde..a15fe80 100644 --- a/fish/script/nixpkgs/package.nix +++ b/fish/script/nixpkgs/package.nix @@ -1,5 +1,6 @@ -{ stdenvNoCC -, fish +{ + stdenvNoCC, + fish, }: stdenvNoCC.mkDerivation { diff --git a/python/pyproject/nixpkgs/basic/flake.nix b/python/pyproject/nixpkgs/basic/flake.nix index 0c2dc0d..9b0c8a8 100644 --- a/python/pyproject/nixpkgs/basic/flake.nix +++ b/python/pyproject/nixpkgs/basic/flake.nix @@ -17,7 +17,7 @@ devShells = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - default = pkgs.callPackage ./shell.nix {}; + default = import ./shell.nix { inherit pkgs; }; }); }; } diff --git a/python/pyproject/nixpkgs/basic/package.nix b/python/pyproject/nixpkgs/basic/package.nix index 9919aa3..af627a8 100644 --- a/python/pyproject/nixpkgs/basic/package.nix +++ b/python/pyproject/nixpkgs/basic/package.nix @@ -1,4 +1,5 @@ -{ python3 +{ + python3, }: python3.pkgs.buildPythonPackage { diff --git a/python/pyproject/nixpkgs/basic/shell.nix b/python/pyproject/nixpkgs/basic/shell.nix index 4a7e9e5..dca9c0a 100644 --- a/python/pyproject/nixpkgs/basic/shell.nix +++ b/python/pyproject/nixpkgs/basic/shell.nix @@ -1,8 +1,9 @@ -{ mkShell -, python3 -}: - -mkShell { +{ pkgs ? import {} }: +let inherit (pkgs) + mkShellNoCC + python3 +; +in mkShellNoCC { inputsFrom = [ python3.buildEnv.env ]; packages = [ python3.pkgs.python-lsp-server ]; } diff --git a/python/pyproject/nixpkgs/cli/flake.nix b/python/pyproject/nixpkgs/cli/flake.nix index 0c2dc0d..9b0c8a8 100644 --- a/python/pyproject/nixpkgs/cli/flake.nix +++ b/python/pyproject/nixpkgs/cli/flake.nix @@ -17,7 +17,7 @@ devShells = eachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in { - default = pkgs.callPackage ./shell.nix {}; + default = import ./shell.nix { inherit pkgs; }; }); }; } diff --git a/python/pyproject/nixpkgs/cli/package.nix b/python/pyproject/nixpkgs/cli/package.nix index ce28631..54c02ad 100644 --- a/python/pyproject/nixpkgs/cli/package.nix +++ b/python/pyproject/nixpkgs/cli/package.nix @@ -1,4 +1,5 @@ -{ python3 +{ + python3, }: python3.pkgs.buildPythonApplication { diff --git a/python/pyproject/nixpkgs/cli/shell.nix b/python/pyproject/nixpkgs/cli/shell.nix index 4a7e9e5..dca9c0a 100644 --- a/python/pyproject/nixpkgs/cli/shell.nix +++ b/python/pyproject/nixpkgs/cli/shell.nix @@ -1,8 +1,9 @@ -{ mkShell -, python3 -}: - -mkShell { +{ pkgs ? import {} }: +let inherit (pkgs) + mkShellNoCC + python3 +; +in mkShellNoCC { inputsFrom = [ python3.buildEnv.env ]; packages = [ python3.pkgs.python-lsp-server ]; } From 50a0f0abc2f4fc77e006da99d04c7f5445b46953 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 26 Nov 2025 17:44:19 -0500 Subject: [PATCH 3/6] doc: update README --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fba2d5..a74ecfd 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,13 @@ there are three or four: 1. The programming language 2. The build system used to compile/package the repository -3. The Nix library/evaluation system used in the flake itself -4. (Optional) Additional differences in project structure +3. The Nix evaluation system used in the flake itself +4. (Optional) Additional differences in project structure, including but not + limited to: + - `basic`: Minimal acceptable project structure + - `cli`: Sample CLI program + - `gui`: Sample GUI program + - `lib`: Library For example, the `python_pyproject_nixpkgs_cli` template generates a Python repository packaged in Pyproject format where the flake uses Nixpkgs' standard From e5faf58ba8c51f6cd8658dbfe2c61062f09418b9 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 26 Nov 2025 17:45:12 -0500 Subject: [PATCH 4/6] feat: Rust templates --- flake.nix | 3 +- rust/cargo-nightly/crane+fenix/.envrc | 2 + rust/cargo-nightly/crane+fenix/Cargo.lock | 7 ++ rust/cargo-nightly/crane+fenix/Cargo.toml | 6 ++ rust/cargo-nightly/crane+fenix/flake.lock | 98 ++++++++++++++++++++ rust/cargo-nightly/crane+fenix/flake.nix | 59 ++++++++++++ rust/cargo-nightly/crane+fenix/package.nix | 19 ++++ rust/cargo-nightly/crane+fenix/shell.nix | 12 +++ rust/cargo-nightly/crane+fenix/src/main.rs | 3 + rust/cargo-nightly/nixpkgs+fenix/.envrc | 2 + rust/cargo-nightly/nixpkgs+fenix/Cargo.lock | 7 ++ rust/cargo-nightly/nixpkgs+fenix/Cargo.toml | 6 ++ rust/cargo-nightly/nixpkgs+fenix/flake.lock | 82 ++++++++++++++++ rust/cargo-nightly/nixpkgs+fenix/flake.nix | 35 +++++++ rust/cargo-nightly/nixpkgs+fenix/package.nix | 12 +++ rust/cargo-nightly/nixpkgs+fenix/shell.nix | 11 +++ rust/cargo-nightly/nixpkgs+fenix/src/main.rs | 3 + rust/cargo-stable/crane/.envrc | 2 + rust/cargo-stable/crane/Cargo.lock | 7 ++ rust/cargo-stable/crane/Cargo.toml | 6 ++ rust/cargo-stable/crane/flake.lock | 59 ++++++++++++ rust/cargo-stable/crane/flake.nix | 52 +++++++++++ rust/cargo-stable/crane/package.nix | 19 ++++ rust/cargo-stable/crane/shell.nix | 10 ++ rust/cargo-stable/crane/src/main.rs | 3 + rust/cargo-stable/nixpkgs/.envrc | 2 + rust/cargo-stable/nixpkgs/Cargo.lock | 7 ++ rust/cargo-stable/nixpkgs/Cargo.toml | 6 ++ rust/cargo-stable/nixpkgs/flake.lock | 43 +++++++++ rust/cargo-stable/nixpkgs/flake.nix | 23 +++++ rust/cargo-stable/nixpkgs/package.nix | 12 +++ rust/cargo-stable/nixpkgs/shell.nix | 10 ++ rust/cargo-stable/nixpkgs/src/main.rs | 3 + 33 files changed, 630 insertions(+), 1 deletion(-) create mode 100644 rust/cargo-nightly/crane+fenix/.envrc create mode 100644 rust/cargo-nightly/crane+fenix/Cargo.lock create mode 100644 rust/cargo-nightly/crane+fenix/Cargo.toml create mode 100644 rust/cargo-nightly/crane+fenix/flake.lock create mode 100644 rust/cargo-nightly/crane+fenix/flake.nix create mode 100644 rust/cargo-nightly/crane+fenix/package.nix create mode 100644 rust/cargo-nightly/crane+fenix/shell.nix create mode 100644 rust/cargo-nightly/crane+fenix/src/main.rs create mode 100644 rust/cargo-nightly/nixpkgs+fenix/.envrc create mode 100644 rust/cargo-nightly/nixpkgs+fenix/Cargo.lock create mode 100644 rust/cargo-nightly/nixpkgs+fenix/Cargo.toml create mode 100644 rust/cargo-nightly/nixpkgs+fenix/flake.lock create mode 100644 rust/cargo-nightly/nixpkgs+fenix/flake.nix create mode 100644 rust/cargo-nightly/nixpkgs+fenix/package.nix create mode 100644 rust/cargo-nightly/nixpkgs+fenix/shell.nix create mode 100644 rust/cargo-nightly/nixpkgs+fenix/src/main.rs create mode 100644 rust/cargo-stable/crane/.envrc create mode 100644 rust/cargo-stable/crane/Cargo.lock create mode 100644 rust/cargo-stable/crane/Cargo.toml create mode 100644 rust/cargo-stable/crane/flake.lock create mode 100644 rust/cargo-stable/crane/flake.nix create mode 100644 rust/cargo-stable/crane/package.nix create mode 100644 rust/cargo-stable/crane/shell.nix create mode 100644 rust/cargo-stable/crane/src/main.rs create mode 100644 rust/cargo-stable/nixpkgs/.envrc create mode 100644 rust/cargo-stable/nixpkgs/Cargo.lock create mode 100644 rust/cargo-stable/nixpkgs/Cargo.toml create mode 100644 rust/cargo-stable/nixpkgs/flake.lock create mode 100644 rust/cargo-stable/nixpkgs/flake.nix create mode 100644 rust/cargo-stable/nixpkgs/package.nix create mode 100644 rust/cargo-stable/nixpkgs/shell.nix create mode 100644 rust/cargo-stable/nixpkgs/src/main.rs diff --git a/flake.nix b/flake.nix index 2ec1f3f..02907d6 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ bash = "bash_script_nixpkgs"; fish = "fish_script_nixpkgs"; python = "python_pyproject_nixpkgs_basic"; + rust = "rust_cargo-nightly_crane+fenix"; }; # Get all subdirectories of the given path @@ -35,7 +36,7 @@ ${concatStringsSep "_" subds} = { description = generateDesc subds; path = filterSource - (p: _: baseNameOf p != "flake.lock") + (p: _: !(elem (baseNameOf p) [ "flake.lock" "Cargo.lock" ])) (foldl' (dir: subd: /${dir}/${subd}) ./. subds); }; }) (flakeSubdirs ./.) // mapAttrs (from: to: diff --git a/rust/cargo-nightly/crane+fenix/.envrc b/rust/cargo-nightly/crane+fenix/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/rust/cargo-nightly/crane+fenix/Cargo.lock b/rust/cargo-nightly/crane+fenix/Cargo.lock new file mode 100644 index 0000000..bdfea16 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello" +version = "0.1.0" diff --git a/rust/cargo-nightly/crane+fenix/Cargo.toml b/rust/cargo-nightly/crane+fenix/Cargo.toml new file mode 100644 index 0000000..f6f3649 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/rust/cargo-nightly/crane+fenix/flake.lock b/rust/cargo-nightly/crane+fenix/flake.lock new file mode 100644 index 0000000..641ec50 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/flake.lock @@ -0,0 +1,98 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1763938834, + "narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1764226020, + "narHash": "sha256-FzUCFwXNjLnnZmVqYj/FjlBhUpat59SExflEaIGT62s=", + "owner": "nix-community", + "repo": "fenix", + "rev": "2d8176c02f7be6d13578d24d5fd5049f1b46a4c5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764138170, + "narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bb813de6d2241bcb1b5af2d3059f560c66329967", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1764175386, + "narHash": "sha256-LfgFqvPz3C80VjaffSjy8lLyRWfbThhB7gE7IWXHjYU=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "71ddf07c1c75046df3bb496cf824de5c053d99ad", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "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 +} diff --git a/rust/cargo-nightly/crane+fenix/flake.nix b/rust/cargo-nightly/crane+fenix/flake.nix new file mode 100644 index 0000000..23f75ed --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/flake.nix @@ -0,0 +1,59 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + + crane.url = "github:ipetkov/crane"; + fenix.url = "github:nix-community/fenix"; + fenix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, systems, crane, fenix, ... }: + let + eachSystem = nixpkgs.lib.genAttrs (import systems); + fenixToolchain = "default"; + in { + packages = eachSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; + in { + hello = pkgs.callPackage ./package.nix { + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + }; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs crane fenix fenixToolchain; }; + }); + + checks = eachSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + crate = self.packages.${system}.default; + in { + inherit crate; + + clippy = craneLib.cargoClippy ( + crate.commonArgs + // { + inherit (crate) cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + doc = craneLib.cargoDoc ( + crate.commonArgs + // { + inherit (crate) cargoArtifacts; + env.RUSTDOCFLAGS = "--deny warnings"; + } + ); + }); + }; +} diff --git a/rust/cargo-nightly/crane+fenix/package.nix b/rust/cargo-nightly/crane+fenix/package.nix new file mode 100644 index 0000000..6945646 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/package.nix @@ -0,0 +1,19 @@ +{ + craneLib, +}: + +let + commonArgs = { + src = craneLib.cleanCargoSource ./.; + strictDeps = true; + + buildInputs = [ + # Additional runtime dependencies + ]; + + passthru.commonArgs = commonArgs; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + crate = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); +in crate diff --git a/rust/cargo-nightly/crane+fenix/shell.nix b/rust/cargo-nightly/crane+fenix/shell.nix new file mode 100644 index 0000000..e53fb11 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/shell.nix @@ -0,0 +1,12 @@ +{ pkgs ? import {}, + crane ? builtins.getFlake "github:ipetkov/crane", + fenix ? builtins.getFlake "github:nix-community/fenix", + fenixToolchain ? "default" +}: +let + fenixPkgs = fenix.packages.${pkgs.system}; + toolchain = fenixPkgs.${fenixToolchain}.toolchain; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; +in craneLib.devShell { + packages = [ fenixPkgs.rust-analyzer ]; +} diff --git a/rust/cargo-nightly/crane+fenix/src/main.rs b/rust/cargo-nightly/crane+fenix/src/main.rs new file mode 100644 index 0000000..0672e51 --- /dev/null +++ b/rust/cargo-nightly/crane+fenix/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, World!"); +} diff --git a/rust/cargo-nightly/nixpkgs+fenix/.envrc b/rust/cargo-nightly/nixpkgs+fenix/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/rust/cargo-nightly/nixpkgs+fenix/Cargo.lock b/rust/cargo-nightly/nixpkgs+fenix/Cargo.lock new file mode 100644 index 0000000..bdfea16 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello" +version = "0.1.0" diff --git a/rust/cargo-nightly/nixpkgs+fenix/Cargo.toml b/rust/cargo-nightly/nixpkgs+fenix/Cargo.toml new file mode 100644 index 0000000..f6f3649 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/rust/cargo-nightly/nixpkgs+fenix/flake.lock b/rust/cargo-nightly/nixpkgs+fenix/flake.lock new file mode 100644 index 0000000..ef578f0 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1764226020, + "narHash": "sha256-FzUCFwXNjLnnZmVqYj/FjlBhUpat59SExflEaIGT62s=", + "owner": "nix-community", + "repo": "fenix", + "rev": "2d8176c02f7be6d13578d24d5fd5049f1b46a4c5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764138170, + "narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bb813de6d2241bcb1b5af2d3059f560c66329967", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1764175386, + "narHash": "sha256-LfgFqvPz3C80VjaffSjy8lLyRWfbThhB7gE7IWXHjYU=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "71ddf07c1c75046df3bb496cf824de5c053d99ad", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "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 +} diff --git a/rust/cargo-nightly/nixpkgs+fenix/flake.nix b/rust/cargo-nightly/nixpkgs+fenix/flake.nix new file mode 100644 index 0000000..7441f09 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/flake.nix @@ -0,0 +1,35 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + + fenix.url = "github:nix-community/fenix"; + fenix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, systems, fenix, ... }: + let + eachSystem = nixpkgs.lib.genAttrs (import systems); + fenixToolchain = "default"; + in { + packages = eachSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + toolchain = fenix.packages.${system}.${fenixToolchain}.toolchain; + in { + hello = pkgs.callPackage ./package.nix { + rustPlatform = pkgs.makeRustPlatform { + rustc = toolchain; + cargo = toolchain; + }; + }; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs fenix fenixToolchain; }; + }); + }; +} diff --git a/rust/cargo-nightly/nixpkgs+fenix/package.nix b/rust/cargo-nightly/nixpkgs+fenix/package.nix new file mode 100644 index 0000000..242ad5a --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/package.nix @@ -0,0 +1,12 @@ +{ + lib, + rustPlatform, +}: + +rustPlatform.buildRustPackage { + pname = "hello"; + version = "0.1"; + src = ./.; + + cargoLock.lockFile = ./Cargo.lock; +} diff --git a/rust/cargo-nightly/nixpkgs+fenix/shell.nix b/rust/cargo-nightly/nixpkgs+fenix/shell.nix new file mode 100644 index 0000000..42f8825 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/shell.nix @@ -0,0 +1,11 @@ +{ pkgs ? import {}, + fenix ? builtins.getFlake "github:nix-community/fenix", + fenixToolchain ? "default" +}: +let + inherit (pkgs) mkShellNoCC; + fenixPkgs = fenix.packages.${pkgs.system}; + toolchain = fenixPkgs.${fenixToolchain}.toolchain; +in mkShellNoCC { + packages = [ toolchain fenixPkgs.rust-analyzer ]; +} diff --git a/rust/cargo-nightly/nixpkgs+fenix/src/main.rs b/rust/cargo-nightly/nixpkgs+fenix/src/main.rs new file mode 100644 index 0000000..0672e51 --- /dev/null +++ b/rust/cargo-nightly/nixpkgs+fenix/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, World!"); +} diff --git a/rust/cargo-stable/crane/.envrc b/rust/cargo-stable/crane/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/rust/cargo-stable/crane/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/rust/cargo-stable/crane/Cargo.lock b/rust/cargo-stable/crane/Cargo.lock new file mode 100644 index 0000000..bdfea16 --- /dev/null +++ b/rust/cargo-stable/crane/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello" +version = "0.1.0" diff --git a/rust/cargo-stable/crane/Cargo.toml b/rust/cargo-stable/crane/Cargo.toml new file mode 100644 index 0000000..f6f3649 --- /dev/null +++ b/rust/cargo-stable/crane/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/rust/cargo-stable/crane/flake.lock b/rust/cargo-stable/crane/flake.lock new file mode 100644 index 0000000..0a37cf6 --- /dev/null +++ b/rust/cargo-stable/crane/flake.lock @@ -0,0 +1,59 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1763938834, + "narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1764138170, + "narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bb813de6d2241bcb1b5af2d3059f560c66329967", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "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 +} diff --git a/rust/cargo-stable/crane/flake.nix b/rust/cargo-stable/crane/flake.nix new file mode 100644 index 0000000..d524296 --- /dev/null +++ b/rust/cargo-stable/crane/flake.nix @@ -0,0 +1,52 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + + crane.url = "github:ipetkov/crane"; + }; + + outputs = { self, nixpkgs, systems, crane, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + hello = pkgs.callPackage ./package.nix { + craneLib = crane.mkLib pkgs; + }; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs crane; }; + }); + + checks = eachSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + craneLib = crane.mkLib pkgs; + crate = self.packages.${system}.default; + in { + inherit crate; + + clippy = craneLib.cargoClippy ( + crate.commonArgs + // { + inherit (crate) cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + doc = craneLib.cargoDoc ( + crate.commonArgs + // { + inherit (crate) cargoArtifacts; + env.RUSTDOCFLAGS = "--deny warnings"; + } + ); + }); + }; +} diff --git a/rust/cargo-stable/crane/package.nix b/rust/cargo-stable/crane/package.nix new file mode 100644 index 0000000..6945646 --- /dev/null +++ b/rust/cargo-stable/crane/package.nix @@ -0,0 +1,19 @@ +{ + craneLib, +}: + +let + commonArgs = { + src = craneLib.cleanCargoSource ./.; + strictDeps = true; + + buildInputs = [ + # Additional runtime dependencies + ]; + + passthru.commonArgs = commonArgs; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + crate = craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; }); +in crate diff --git a/rust/cargo-stable/crane/shell.nix b/rust/cargo-stable/crane/shell.nix new file mode 100644 index 0000000..7a34e46 --- /dev/null +++ b/rust/cargo-stable/crane/shell.nix @@ -0,0 +1,10 @@ +{ pkgs ? import {}, + crane ? builtins.getFlake "github:ipetkov/crane" +}: +let + inherit (pkgs) + rust-analyzer +; +in (crane.mkLib pkgs).devShell { + packages = [ rust-analyzer ]; +} diff --git a/rust/cargo-stable/crane/src/main.rs b/rust/cargo-stable/crane/src/main.rs new file mode 100644 index 0000000..0672e51 --- /dev/null +++ b/rust/cargo-stable/crane/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, World!"); +} diff --git a/rust/cargo-stable/nixpkgs/.envrc b/rust/cargo-stable/nixpkgs/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/rust/cargo-stable/nixpkgs/Cargo.lock b/rust/cargo-stable/nixpkgs/Cargo.lock new file mode 100644 index 0000000..bdfea16 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello" +version = "0.1.0" diff --git a/rust/cargo-stable/nixpkgs/Cargo.toml b/rust/cargo-stable/nixpkgs/Cargo.toml new file mode 100644 index 0000000..f6f3649 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/rust/cargo-stable/nixpkgs/flake.lock b/rust/cargo-stable/nixpkgs/flake.lock new file mode 100644 index 0000000..72ee575 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1764138170, + "narHash": "sha256-2bCmfCUZyi2yj9FFXYKwsDiaZmizN75cLhI/eWmf3tk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bb813de6d2241bcb1b5af2d3059f560c66329967", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "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 +} diff --git a/rust/cargo-stable/nixpkgs/flake.nix b/rust/cargo-stable/nixpkgs/flake.nix new file mode 100644 index 0000000..9b0c8a8 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/flake.nix @@ -0,0 +1,23 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + hello = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs; }; + }); + }; +} diff --git a/rust/cargo-stable/nixpkgs/package.nix b/rust/cargo-stable/nixpkgs/package.nix new file mode 100644 index 0000000..242ad5a --- /dev/null +++ b/rust/cargo-stable/nixpkgs/package.nix @@ -0,0 +1,12 @@ +{ + lib, + rustPlatform, +}: + +rustPlatform.buildRustPackage { + pname = "hello"; + version = "0.1"; + src = ./.; + + cargoLock.lockFile = ./Cargo.lock; +} diff --git a/rust/cargo-stable/nixpkgs/shell.nix b/rust/cargo-stable/nixpkgs/shell.nix new file mode 100644 index 0000000..b5dd7fd --- /dev/null +++ b/rust/cargo-stable/nixpkgs/shell.nix @@ -0,0 +1,10 @@ +{ pkgs ? import {} }: +let inherit (pkgs) + mkShellNoCC + rustc + cargo + rust-analyzer +; +in mkShellNoCC { + packages = [ rustc cargo rust-analyzer ]; +} diff --git a/rust/cargo-stable/nixpkgs/src/main.rs b/rust/cargo-stable/nixpkgs/src/main.rs new file mode 100644 index 0000000..0672e51 --- /dev/null +++ b/rust/cargo-stable/nixpkgs/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, World!"); +} From f5427d28a965c1d7ad4be5682218eb2397029e2c Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Mon, 19 Jan 2026 14:10:56 -0500 Subject: [PATCH 5/6] feat: C templates --- .gitignore | 1 + c/basic/nixpkgs/.envrc | 2 ++ c/basic/nixpkgs/flake.lock | 43 +++++++++++++++++++++++++++++++++++++ c/basic/nixpkgs/flake.nix | 23 ++++++++++++++++++++ c/basic/nixpkgs/package.nix | 23 ++++++++++++++++++++ c/basic/nixpkgs/shell.nix | 8 +++++++ c/basic/nixpkgs/src/hello.c | 6 ++++++ c/make/nixpkgs/.envrc | 2 ++ c/make/nixpkgs/Makefile | 37 +++++++++++++++++++++++++++++++ c/make/nixpkgs/flake.lock | 43 +++++++++++++++++++++++++++++++++++++ c/make/nixpkgs/flake.nix | 23 ++++++++++++++++++++ c/make/nixpkgs/package.nix | 10 +++++++++ c/make/nixpkgs/shell.nix | 8 +++++++ c/make/nixpkgs/src/hello.c | 6 ++++++ flake.nix | 1 + 15 files changed, 236 insertions(+) create mode 100644 c/basic/nixpkgs/.envrc create mode 100644 c/basic/nixpkgs/flake.lock create mode 100644 c/basic/nixpkgs/flake.nix create mode 100644 c/basic/nixpkgs/package.nix create mode 100644 c/basic/nixpkgs/shell.nix create mode 100644 c/basic/nixpkgs/src/hello.c create mode 100644 c/make/nixpkgs/.envrc create mode 100644 c/make/nixpkgs/Makefile create mode 100644 c/make/nixpkgs/flake.lock create mode 100644 c/make/nixpkgs/flake.nix create mode 100644 c/make/nixpkgs/package.nix create mode 100644 c/make/nixpkgs/shell.nix create mode 100644 c/make/nixpkgs/src/hello.c diff --git a/.gitignore b/.gitignore index 564c965..ac255b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ result* .direnv/ +build/ diff --git a/c/basic/nixpkgs/.envrc b/c/basic/nixpkgs/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/c/basic/nixpkgs/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/c/basic/nixpkgs/flake.lock b/c/basic/nixpkgs/flake.lock new file mode 100644 index 0000000..4243b18 --- /dev/null +++ b/c/basic/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1768783163, + "narHash": "sha256-tLj4KcRDLakrlpvboTJDKsrp6z2XLwyQ4Zmo+w8KsY4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bde09022887110deb780067364a0818e89258968", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "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 +} diff --git a/c/basic/nixpkgs/flake.nix b/c/basic/nixpkgs/flake.nix new file mode 100644 index 0000000..9b0c8a8 --- /dev/null +++ b/c/basic/nixpkgs/flake.nix @@ -0,0 +1,23 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + hello = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs; }; + }); + }; +} diff --git a/c/basic/nixpkgs/package.nix b/c/basic/nixpkgs/package.nix new file mode 100644 index 0000000..53b63e9 --- /dev/null +++ b/c/basic/nixpkgs/package.nix @@ -0,0 +1,23 @@ +{ + stdenv +}: +let + source = "src/hello.c"; + exec = "hello"; +in stdenv.mkDerivation { + pname = "hello"; + version = "0.1"; + src = ./.; + + buildPhase = '' + runHook preBuild + gcc ${source} -o ${exec}.bin + runHook postBuild + ''; + installPhase = '' + runHook preInstall + mkdir -p $out/bin + install ${exec}.bin $out/bin/${exec} + runHook postInstall + ''; +} diff --git a/c/basic/nixpkgs/shell.nix b/c/basic/nixpkgs/shell.nix new file mode 100644 index 0000000..4d2f40d --- /dev/null +++ b/c/basic/nixpkgs/shell.nix @@ -0,0 +1,8 @@ +{ pkgs ? import {} }: +let inherit (pkgs) + mkShell + llvmPackages_21 +; +in mkShell { + packages = [ llvmPackages_21.clang-tools ]; +} diff --git a/c/basic/nixpkgs/src/hello.c b/c/basic/nixpkgs/src/hello.c new file mode 100644 index 0000000..f26b97c --- /dev/null +++ b/c/basic/nixpkgs/src/hello.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!\n"); + return 0; +} diff --git a/c/make/nixpkgs/.envrc b/c/make/nixpkgs/.envrc new file mode 100644 index 0000000..af0cc93 --- /dev/null +++ b/c/make/nixpkgs/.envrc @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +use flake diff --git a/c/make/nixpkgs/Makefile b/c/make/nixpkgs/Makefile new file mode 100644 index 0000000..fb93306 --- /dev/null +++ b/c/make/nixpkgs/Makefile @@ -0,0 +1,37 @@ +## +# Example GCC Nix Project +# +# @file +# @version 0.1 + +SRC_DIR := ./src +BUILD_DIR := ./build + +EXEC ?= hello +INSTALL ?= $(PREFIX)/bin/ + +# Find all the C files we want to compile +SRCS := $(shell find $(SRC_DIR) -name '*.c') +OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) + +.PHONY: build install clean + +build: $(BUILD_DIR)/$(EXEC) +install: build + mkdir -p $(INSTALL) + cp $(BUILD_DIR)/$(EXEC) $(INSTALL) + + +# Link +$(BUILD_DIR)/$(EXEC): $(OBJS) + $(CC) $^ -o $@ $(LDFLAGS) + +# Compile +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c + mkdir -p $(dir $@) + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + +clean: + rm -r $(BUILD_DIR) + +# end diff --git a/c/make/nixpkgs/flake.lock b/c/make/nixpkgs/flake.lock new file mode 100644 index 0000000..4243b18 --- /dev/null +++ b/c/make/nixpkgs/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1768783163, + "narHash": "sha256-tLj4KcRDLakrlpvboTJDKsrp6z2XLwyQ4Zmo+w8KsY4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bde09022887110deb780067364a0818e89258968", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "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 +} diff --git a/c/make/nixpkgs/flake.nix b/c/make/nixpkgs/flake.nix new file mode 100644 index 0000000..9b0c8a8 --- /dev/null +++ b/c/make/nixpkgs/flake.nix @@ -0,0 +1,23 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = { self, nixpkgs, systems, ... }: + let eachSystem = nixpkgs.lib.genAttrs (import systems); + in { + packages = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + hello = pkgs.callPackage ./package.nix {}; + default = self.packages.${system}.hello; + }); + + devShells = eachSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; + in { + default = import ./shell.nix { inherit pkgs; }; + }); + }; +} diff --git a/c/make/nixpkgs/package.nix b/c/make/nixpkgs/package.nix new file mode 100644 index 0000000..795863a --- /dev/null +++ b/c/make/nixpkgs/package.nix @@ -0,0 +1,10 @@ +{ + stdenv +}: + +stdenv.mkDerivation rec { + pname = "hello"; + version = "0.1"; + src = ./.; + installFlags = [ "PREFIX=$(out)" "EXEC=${pname}" ]; +} diff --git a/c/make/nixpkgs/shell.nix b/c/make/nixpkgs/shell.nix new file mode 100644 index 0000000..4d2f40d --- /dev/null +++ b/c/make/nixpkgs/shell.nix @@ -0,0 +1,8 @@ +{ pkgs ? import {} }: +let inherit (pkgs) + mkShell + llvmPackages_21 +; +in mkShell { + packages = [ llvmPackages_21.clang-tools ]; +} diff --git a/c/make/nixpkgs/src/hello.c b/c/make/nixpkgs/src/hello.c new file mode 100644 index 0000000..f26b97c --- /dev/null +++ b/c/make/nixpkgs/src/hello.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!\n"); + return 0; +} diff --git a/flake.nix b/flake.nix index 02907d6..fff4f4c 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,7 @@ aliases = { bash = "bash_script_nixpkgs"; fish = "fish_script_nixpkgs"; + c = "c_make_nixpkgs"; python = "python_pyproject_nixpkgs_basic"; rust = "rust_cargo-nightly_crane+fenix"; }; From 9201edf9458e591aea3b48c082da0727ffd38a55 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Mon, 19 Jan 2026 14:11:17 -0500 Subject: [PATCH 6/6] refactor: pull out template filter into variable --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index fff4f4c..ac9ebb7 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,9 @@ rust = "rust_cargo-nightly_crane+fenix"; }; + # Files to filter out of the template + template-ignore = [ "flake.lock" "Cargo.lock" ]; + # Get all subdirectories of the given path # Returns [str] subdirs = dir: @@ -37,7 +40,7 @@ ${concatStringsSep "_" subds} = { description = generateDesc subds; path = filterSource - (p: _: !(elem (baseNameOf p) [ "flake.lock" "Cargo.lock" ])) + (p: _: !(elem (baseNameOf p) template-ignore)) (foldl' (dir: subd: /${dir}/${subd}) ./. subds); }; }) (flakeSubdirs ./.) // mapAttrs (from: to: