From a524bf5c41c17975d7e85d87db1dc1d49e472f88 Mon Sep 17 00:00:00 2001 From: Miran Bastaja Date: Tue, 30 Jul 2024 16:12:20 +0200 Subject: Initial commit --- .gitignore | 1 + README.md | 14 ++++++++++++++ examples/simple/flake.nix | 29 +++++++++++++++++++++++++++++ flake.lock | 39 +++++++++++++++++++++++++++++++++++++++ flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 examples/simple/flake.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1a6fb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*result* diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c9027e --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Minimal flake utils + +This repo contains random bits of code that I often use when creating flakes. + +## Included functions + +### `eachSystem :: ( -> attrs)` + +Esentially equivalent to [flake-utils' eachDefaultSystem](https://github.com/numtide/flake-utils/blob/b1d9ab70662946ef0850d488da1c9019f3a9752a/README.md#eachdefaultsystem--system---attrs) + +### `mkMinimalShell :: ( {name ? "nix-shell", packages ? [], inputsFrom ? [], shellHook ? "", ...} -> derivation)` + +Like [nixpkgs' mkShell](https://ryantm.github.io/nixpkgs/builders/special/mkshell/) but pulls in +fewer dependencies. The extra arguments (...) are all the attributes of `stdenv.mkDerivation`. diff --git a/examples/simple/flake.nix b/examples/simple/flake.nix new file mode 100644 index 0000000..366464d --- /dev/null +++ b/examples/simple/flake.nix @@ -0,0 +1,29 @@ +{ + description = "futils demo."; + + inputs.futils = { + url = "git+https://git.sorre.xyz/miranb/futils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + { + self, + nixpkgs, + futils, + }: + futils.lib.eachSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = futils.lib.mkMinimalShell pkgs { + packages = with pkgs; [ + git + hello + ]; + }; + } + ); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0198db3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,39 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-+W5eZOhhemLQxelojLxETfbFbc19NWawsXBlapYpqIA=", + "path": "/nix/store/70y8v9qfn34sdfsnwh3l9772lk4rpfiy-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "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/flake.nix b/flake.nix new file mode 100644 index 0000000..4016d27 --- /dev/null +++ b/flake.nix @@ -0,0 +1,42 @@ +{ + description = "Mashup of various utility functions that I use often."; + + inputs = { + systems.url = "github:nix-systems/default"; + }; + + outputs = + { + self, + nixpkgs, + systems, + }: + let + stdenvMinimal = nixpkgs.stdenvNoCC.override { + cc = null; + preHook = ""; + allowedRequsites = null; + initialPath = nixpkgs.lib.filter ( + a: nixpkgs.lib.hasPrefix "coreutils" a.name + ) nixpkgs.stdenvNoCC.initialPath; + extraNativeBuildInputs = [ ]; + }; + in + { + lib = { + # Basically equivalent to flake-utils' eachDefaultSystem + eachSystem = nixpkgs.lib.genAttrs (import systems); + + # Like mkShell, but with less dependencies. + # See https://fzakaria.com/2021/08/02/a-minimal-nix-shell.html + minimalMkShell = pkgs: pkgs.mkShell.override { stdenv = stdenvMinimal; }; + }; + + templates = { + eachSystem = { + path = ./examples/simple; + description = "Example showing off a few simple functions."; + }; + }; + }; +} -- cgit v1.3.1