Fix a few issues

This commit is contained in:
Hassan Abedi 2026-04-20 11:12:42 +02:00
parent 7208051274
commit 93ce3f75c2
5 changed files with 51 additions and 16 deletions

27
01-devshell/flake.lock generated Normal file
View File

@ -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
}

View File

@ -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.<system>.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; [

View File

@ -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.";
};
};
}

View File

@ -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)"
'';
@ -45,7 +48,7 @@
# 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
${self.packages.${pkgs.stdenv.hostPlatform.system}.default}/bin/hello-multi > $out
'';
});
};

View File

@ -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 ?=