mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-02-22 12:55:21 +08:00
temp
This commit is contained in:
parent
c015c357fe
commit
92900265e2
9 changed files with 143 additions and 127407 deletions
5978
index.html
5978
index.html
File diff suppressed because it is too large
Load diff
|
|
@ -15,14 +15,6 @@
|
|||
pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
};
|
||||
|
||||
aarch64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "aarch64-linux"; };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
};
|
||||
}; # devShells
|
||||
|
||||
packages = {
|
||||
|
|
@ -40,24 +32,10 @@
|
|||
mkdir -p $out/bin
|
||||
cp $src/cow-hello.sh $out/bin
|
||||
chmod +x $out/bin/cow-hello.sh
|
||||
'';
|
||||
buildInputs = [ pkgs.cowsay ];
|
||||
}; # mkDerivation
|
||||
|
||||
aarch64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "aarch64-linux"; };
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "cow-hello.sh";
|
||||
src = ./.;
|
||||
unpackPhase = "true";
|
||||
buildPhase = ":";
|
||||
installPhase =
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
cp $src/cow-hello.sh $out/bin
|
||||
chmod +x $out/bin/cow-hello.sh
|
||||
# modify the cow-hello.sh script so it can find cowsay
|
||||
COWSAY=$(type -p cowsay)
|
||||
sed "s_cowsay_"$COWSAY"_" --in-place $out/bin/cow-hello.sh
|
||||
'';
|
||||
buildInputs = [ pkgs.cowsay ];
|
||||
}; # mkDerivation
|
||||
|
|
|
|||
|
|
@ -5,24 +5,32 @@
|
|||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
||||
forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
|
||||
nixpkgsFor = forEachSystem (system: import nixpkgs { inherit system; });
|
||||
outputs = { self, nixpkgs }: {
|
||||
|
||||
in {
|
||||
|
||||
devShells = forEachSystem (system:
|
||||
let pkgs = nixpkgsFor.${system}; in {
|
||||
default = pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
devShells = {
|
||||
x86_64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
};
|
||||
});
|
||||
|
||||
packages = forEachSystem (system:
|
||||
let pkgs = nixpkgsFor.${system}; in {
|
||||
default = pkgs.stdenv.mkDerivation {
|
||||
aarch64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "aarch64-linux"; };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
};
|
||||
}; # devShells
|
||||
|
||||
packages = {
|
||||
x86_64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "cow-hello.sh";
|
||||
src = ./.;
|
||||
unpackPhase = "true";
|
||||
|
|
@ -32,10 +40,36 @@
|
|||
mkdir -p $out/bin
|
||||
cp $src/cow-hello.sh $out/bin
|
||||
chmod +x $out/bin/cow-hello.sh
|
||||
|
||||
# modify the cow-hello.sh script so it can find cowsay
|
||||
COWSAY=$(type -p cowsay)
|
||||
sed "s_cowsay_"$COWSAY"_" --in-place $out/bin/cow-hello.sh
|
||||
'';
|
||||
buildInputs = [ pkgs.cowsay ];
|
||||
}; # mkDerivation
|
||||
}); # packages
|
||||
|
||||
aarch64-linux.default =
|
||||
let
|
||||
pkgs = import nixpkgs { system = "aarch64-linux"; };
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "cow-hello.sh";
|
||||
src = ./.;
|
||||
unpackPhase = "true";
|
||||
buildPhase = ":";
|
||||
installPhase =
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
cp $src/cow-hello.sh $out/bin
|
||||
chmod +x $out/bin/cow-hello.sh
|
||||
|
||||
# modify the cow-hello.sh script so it can find cowsay
|
||||
COWSAY=$(type -p cowsay)
|
||||
sed "s_cowsay_"$COWSAY"_" --in-place $out/bin/cow-hello.sh
|
||||
'';
|
||||
buildInputs = [ pkgs.cowsay ];
|
||||
}; # mkDerivation
|
||||
}; # packages
|
||||
|
||||
}; # outputs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,9 @@
|
|||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
|
||||
|
||||
forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forEachSystem (system: import nixpkgs {
|
||||
inherit system;
|
||||
config = { };
|
||||
overlays = [ ];
|
||||
});
|
||||
nixpkgsFor = forEachSystem (system: import nixpkgs { inherit system; });
|
||||
|
||||
in {
|
||||
|
||||
|
|
@ -28,8 +21,8 @@
|
|||
});
|
||||
|
||||
packages = forEachSystem (system:
|
||||
let pkgs = nixpkgsFor.${system}; in rec {
|
||||
hello = pkgs.stdenv.mkDerivation {
|
||||
let pkgs = nixpkgsFor.${system}; in {
|
||||
default = pkgs.stdenv.mkDerivation {
|
||||
name = "cow-hello.sh";
|
||||
src = ./.;
|
||||
unpackPhase = "true";
|
||||
|
|
@ -39,21 +32,14 @@
|
|||
mkdir -p $out/bin
|
||||
cp $src/cow-hello.sh $out/bin
|
||||
chmod +x $out/bin/cow-hello.sh
|
||||
|
||||
# modify the cow-hello.sh script so it can find cowsay
|
||||
COWSAY=$(type -p cowsay)
|
||||
sed "s_cowsay_"$COWSAY"_" --in-place $out/bin/cow-hello.sh
|
||||
'';
|
||||
buildInputs = [ pkgs.cowsay ];
|
||||
}; # mkDerivation
|
||||
|
||||
default = hello;
|
||||
}); # packages
|
||||
|
||||
apps = forEachSystem (system:
|
||||
let pkgs = nixpkgsFor.${system}; in rec {
|
||||
hello = {
|
||||
type = "app";
|
||||
program = pkgs.lib.getExe self.packages.${system}.hello;
|
||||
};
|
||||
|
||||
default = hello;
|
||||
});
|
||||
}; # outputs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ $# nix develop --command sh
|
|||
|
||||
Because we haven't added `flake.nix` to the git repository, it's essentially invisible to Nix.
|
||||
Let's correct that and try again.
|
||||
We'll also add the script to the git repository.
|
||||
We'll also add the script to the git repository
|
||||
(otherwise we would get a confusing message about the file being "missing").
|
||||
|
||||
....
|
||||
$ git add flake.nix cow-hello.sh
|
||||
|
|
@ -181,7 +182,7 @@ pkgs.stdenv.mkDerivation {
|
|||
}; # mkDerivation
|
||||
....
|
||||
|
||||
To update the flake, add the new lines below to `flake.nix`.
|
||||
Here's the updated `flake.nix`.
|
||||
Again, change `x86_64-linux` if needed to match your system architecture.
|
||||
|
||||
////
|
||||
|
|
@ -197,14 +198,37 @@ $# cat flake.nix
|
|||
Let's test the package.
|
||||
First, we should exit the development shell so we can verify that the flake dependencies are automatically loaded.
|
||||
Otherwise the script could use `cowsay` from the development shell.
|
||||
We'll also commit the changes to get rid of the warnings.
|
||||
|
||||
....
|
||||
$ exit
|
||||
$ nix run
|
||||
$ git commit -am "define package"
|
||||
$ nix run # fails
|
||||
....
|
||||
|
||||
If we hadn't added `cow-hello.sh` to the git repository,
|
||||
we would have an error about the file being missing.
|
||||
What went wrong?
|
||||
Although we made `cowsay` available in the runtime environment,
|
||||
the `cow-hello.sh` script can't find it.
|
||||
|
||||
For now, we can just edit the script during the build phase.
|
||||
We'll see another way to handle this in <<#writeShellApplication>>.
|
||||
|
||||
////
|
||||
$ cp ../flake-3.nix flake.nix
|
||||
////
|
||||
|
||||
[source,nix,linenums,highlight="36..38"]
|
||||
.flake.nix (version 3)
|
||||
....
|
||||
$# cat flake.nix
|
||||
....
|
||||
|
||||
Let's try running the flake again.
|
||||
|
||||
....
|
||||
$ git commit -am "fill in cowsay path"
|
||||
$ nix run
|
||||
....
|
||||
|
||||
[#multi-arch]
|
||||
== Supporting multiple architectures
|
||||
|
|
@ -216,11 +240,11 @@ Of course we want to test it on the new architecture,
|
|||
so we'll add an entry to `devShells` as well.
|
||||
|
||||
////
|
||||
$ cp ../flake-3.nix flake.nix
|
||||
$ cp ../flake-4.nix flake.nix
|
||||
////
|
||||
|
||||
[source,nix,linenums,highlight="19..25,47..63"]
|
||||
.flake.nix (version 3)
|
||||
[source,nix,linenums,highlight="19..25,51..71"]
|
||||
.flake.nix (version 4)
|
||||
....
|
||||
$# cat flake.nix
|
||||
....
|
||||
|
|
@ -228,6 +252,7 @@ $# cat flake.nix
|
|||
Let's make sure it still runs on our system.
|
||||
|
||||
....
|
||||
$ git commit -am "suport aarch64-linux"
|
||||
$ nix run
|
||||
....
|
||||
|
||||
|
|
@ -333,15 +358,16 @@ You may want to compare it carefully to the original version,
|
|||
in order to reassure yourself that the definitions are equivalent.
|
||||
|
||||
////
|
||||
$ cp ../flake-4.nix flake.nix
|
||||
$ cp ../flake-5.nix flake.nix
|
||||
////
|
||||
|
||||
[source,nix,linenums,highlight="10..12,16,17,23,24"]
|
||||
.flake.nix (version 4)
|
||||
.flake.nix (version 5)
|
||||
....
|
||||
$# cat flake.nix
|
||||
....
|
||||
|
||||
Note that if we need to support another architecture, we only need to add it to line 10.
|
||||
Let's verify that it runs on our system.
|
||||
|
||||
....
|
||||
|
|
@ -393,11 +419,11 @@ https://nixos.org/manual/nixpkgs/stable/#chap-overlays[overlays].
|
|||
Putting everything together, we have:
|
||||
|
||||
////
|
||||
$ cp ../flake-5.nix flake.nix
|
||||
$ cp ../flake-6.nix flake.nix
|
||||
////
|
||||
|
||||
[source,nix,linenums,highlight="17,18,31,32,46,49..57"]
|
||||
.flake.nix (version 5)
|
||||
[source,nix,linenums,highlight="17,18,31,32,50,53..61"]
|
||||
.flake.nix (version 6)
|
||||
....
|
||||
$# cat flake.nix
|
||||
....
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
description = "a very simple and friendly flake";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
packages = [ pkgs.cowsay ];
|
||||
};
|
||||
};
|
||||
|
||||
packages = rec {
|
||||
hello = pkgs.writeShellApplication {
|
||||
name = "hello-cow";
|
||||
|
||||
runtimeInputs = [
|
||||
pkgs.cowsay
|
||||
];
|
||||
|
||||
text = ''
|
||||
cowsay "hello";
|
||||
'';
|
||||
};
|
||||
default = hello;
|
||||
};
|
||||
|
||||
apps = rec {
|
||||
hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
|
||||
default = hello;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -18,6 +18,22 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"hello-nix": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1757705465,
|
||||
"narHash": "sha256-sJCQ9+8Dy+QF9ISaupp42+mGbuXtFyqbX85tWzeNPOI=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "56044f61231c996e4ab795de1da89e5f79db3f4f",
|
||||
"revCount": 5,
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-nix"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-nix"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1760435515,
|
||||
|
|
@ -36,6 +52,7 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"hello-nix": "hello-nix",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
27
source/recipes/devshell/nix-non-flake/tempwork/flake.nix
Normal file
27
source/recipes/devshell/nix-non-flake/tempwork/flake.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-nix = {
|
||||
url = "git+https://codeberg.org/mhwombat/hello-nix";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-nix }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
helloNix = import hello-nix { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
packages = [ helloNix ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
121312
wombats-book-of-nix.pdf
121312
wombats-book-of-nix.pdf
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue