aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--examples/simple/flake.lock57
-rw-r--r--examples/simple/flake.nix8
-rw-r--r--flake.nix67
4 files changed, 109 insertions, 25 deletions
diff --git a/README.md b/README.md
index 9c9027e..2860841 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ This repo contains random bits of code that I often use when creating flakes.
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)`
+### `mkMinimalShell :: ( <pkgs> -> {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.lock b/examples/simple/flake.lock
new file mode 100644
index 0000000..b24646a
--- /dev/null
+++ b/examples/simple/flake.lock
@@ -0,0 +1,57 @@
+{
+ "nodes": {
+ "futils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1722349920,
+ "narHash": "sha256-Jyg5B9g9TtE9xGZpT6U77LwmjRGyzKrWh5GBZ5h7kpc=",
+ "ref": "refs/heads/main",
+ "rev": "fa2922de79eb53448c934e447e3490383fed4cd1",
+ "revCount": 2,
+ "type": "git",
+ "url": "https://git.sorre.xyz/miranb/futils"
+ },
+ "original": {
+ "type": "git",
+ "url": "https://git.sorre.xyz/miranb/futils"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 0,
+ "narHash": "sha256-+W5eZOhhemLQxelojLxETfbFbc19NWawsXBlapYpqIA=",
+ "path": "/nix/store/70y8v9qfn34sdfsnwh3l9772lk4rpfiy-source",
+ "type": "path"
+ },
+ "original": {
+ "id": "nixpkgs",
+ "type": "indirect"
+ }
+ },
+ "root": {
+ "inputs": {
+ "futils": "futils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "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/examples/simple/flake.nix b/examples/simple/flake.nix
index 366464d..3695196 100644
--- a/examples/simple/flake.nix
+++ b/examples/simple/flake.nix
@@ -1,10 +1,6 @@
{
description = "futils demo.";
-
- inputs.futils = {
- url = "git+https://git.sorre.xyz/miranb/futils";
- inputs.nixpkgs.follows = "nixpkgs";
- };
+ inputs.futils.url = "git+https://git.sorre.xyz/miranb/futils";
outputs =
{
@@ -18,7 +14,7 @@
pkgs = nixpkgs.legacyPackages.${system};
in
{
- devShells.default = futils.lib.mkMinimalShell pkgs {
+ devShells.default = futils.lib.minimalMkShell pkgs {
packages = with pkgs; [
git
hello
diff --git a/flake.nix b/flake.nix
index 4016d27..ae6273e 100644
--- a/flake.nix
+++ b/flake.nix
@@ -6,30 +6,61 @@
};
outputs =
- {
- self,
- nixpkgs,
- systems,
- }:
+ { self, ... }:
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 = [ ];
- };
+ systems = (import self.inputs.systems);
in
{
lib = {
- # Basically equivalent to flake-utils' eachDefaultSystem
- eachSystem = nixpkgs.lib.genAttrs (import systems);
+ # Equivalent to flake-utils' eachDefaultSystem
+ # Taken from flake-utils
+ eachSystem =
+ f:
+ let
+ # Merge together the outptus for all systems
+ op =
+ attrs: system:
+ let
+ ret = f system;
+ op =
+ attrs: key:
+ attrs
+ // {
+ ${key} = (attrs.${key} or { }) // {
+ ${system} = ret.${key};
+ };
+ };
+ in
+ builtins.foldl' op attrs (builtins.attrNames ret);
+ in
+ builtins.foldl' op { } (
+ systems
+ ++
+ # add the current system if --impure is used
+ (
+ if builtins ? currentSystem then
+ if builtins.elem builtins.currentSystem systems then [ ] else [ builtins.currentSystem ]
+ else
+ [ ]
+ )
+ );
# 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; };
+ # Taken from https://fzakaria.com/2021/08/02/a-minimal-nix-shell.html
+ minimalMkShell =
+ pkgs:
+ let
+ stdenvMinimal = pkgs.stdenvNoCC.override {
+ cc = null;
+ preHook = "";
+ allowedRequisites = null;
+ initialPath = pkgs.lib.filter (
+ a: pkgs.lib.hasPrefix "coreutils" a.name
+ ) pkgs.stdenvNoCC.initialPath;
+ extraNativeBuildInputs = [ ];
+ };
+ in
+ pkgs.mkShell.override { stdenv = stdenvMinimal; };
};
templates = {