From 2c2af9ecda3164f028c7a8c04db03d3425796737 Mon Sep 17 00:00:00 2001 From: Hassan Abedi Date: Mon, 20 Apr 2026 11:12:42 +0200 Subject: [PATCH] Fix a few issues --- 01-devshell/flake.lock | 27 +++++++++++++++++++++++++++ 01-devshell/flake.nix | 6 ++++-- 02-package/flake.nix | 7 +++++-- 03-multi-system/flake.nix | 21 ++++++++++++--------- Makefile | 6 +++--- 5 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 01-devshell/flake.lock diff --git a/01-devshell/flake.lock b/01-devshell/flake.lock new file mode 100644 index 0000000..682004d --- /dev/null +++ b/01-devshell/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1776169885, + "narHash": "sha256-l/iNYDZ4bGOAFQY2q8y5OAfBBtrDAaPuRQqWaFHVRXM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bd9165a9165d7b5e33ae57f3eecbcb28fb231c9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/01-devshell/flake.nix b/01-devshell/flake.nix index 4aae071..f0d3719 100644 --- a/01-devshell/flake.nix +++ b/01-devshell/flake.nix @@ -10,11 +10,13 @@ # Outputs: a function that receives all inputs and returns an attrset. # The attrset's structure is what `nix` CLI commands look for (e.g. `devShells..default`). - outputs = { self, nixpkgs, ... }: + outputs = + { nixpkgs, ... }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - in { + in + { # `nix develop` picks this up by default. devShells.${system}.default = pkgs.mkShell { packages = with pkgs; [ diff --git a/02-package/flake.nix b/02-package/flake.nix index 32b1155..cb3c5ae 100644 --- a/02-package/flake.nix +++ b/02-package/flake.nix @@ -8,11 +8,13 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; - outputs = { self, nixpkgs, ... }: + outputs = + { self, nixpkgs, ... }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - in { + in + { packages.${system}.default = pkgs.stdenv.mkDerivation { pname = "greet"; version = "0.1.0"; @@ -42,6 +44,7 @@ apps.${system}.default = { type = "app"; program = "${self.packages.${system}.default}/bin/greet"; + meta.description = "Run the packaged greet script."; }; }; } diff --git a/03-multi-system/flake.nix b/03-multi-system/flake.nix index 355e67f..964ef9c 100644 --- a/03-multi-system/flake.nix +++ b/03-multi-system/flake.nix @@ -8,7 +8,8 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; - outputs = { self, nixpkgs, ... }: + outputs = + { self, nixpkgs, ... }: let # List every system you want to support. supportedSystems = [ @@ -20,11 +21,10 @@ # Helper: apply a function to each system and collect results into an attrset. # `nixpkgs.lib.genAttrs` turns a list of keys + a function into { key = f key; … }. - forAllSystems = f: - nixpkgs.lib.genAttrs supportedSystems (system: - f (import nixpkgs { inherit system; }) - ); - in { + forAllSystems = + f: nixpkgs.lib.genAttrs supportedSystems (system: f (import nixpkgs { inherit system; })); + in + { # Every output that varies per system goes through `forAllSystems`. packages = forAllSystems (pkgs: { default = pkgs.writeShellScriptBin "hello-multi" '' @@ -34,7 +34,10 @@ devShells = forAllSystems (pkgs: { default = pkgs.mkShell { - packages = with pkgs; [ jq ripgrep ]; + packages = with pkgs; [ + jq + ripgrep + ]; shellHook = '' echo "dev shell on $(uname -s)/$(uname -m)" ''; @@ -44,8 +47,8 @@ # `nix flake check` evaluates everything under `checks`. # Wrapping a simple test here shows the pattern. checks = forAllSystems (pkgs: { - runs = pkgs.runCommand "hello-multi-runs" {} '' - ${self.packages.${pkgs.system}.default}/bin/hello-multi > $out + runs = pkgs.runCommand "hello-multi-runs" { } '' + ${self.packages.${pkgs.stdenv.hostPlatform.system}.default}/bin/hello-multi > $out ''; }); }; diff --git a/Makefile b/Makefile index d7c3ca9..2bde144 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ EXAMPLES := $(sort $(wildcard [0-9][0-9]-*)) # Tools are invoked via `nix run` so nothing needs to be pre-installed beyond Nix itself. # Override any of these if you have the tools on $PATH and want faster startup. NIX ?= nix -NIXFMT ?= $(NIX) run nixpkgs#nixfmt-rfc-style -- -STATIX ?= $(NIX) run nixpkgs#statix -- -DEADNIX ?= $(NIX) run nixpkgs#deadnix -- +NIXFMT ?= $(NIX) run nixpkgs\#nixfmt -- +STATIX ?= $(NIX) run nixpkgs\#statix -- +DEADNIX ?= $(NIX) run nixpkgs\#deadnix -- # Selector for single-example targets (dev, show, update-one). EXAMPLE ?=