Compare commits

...
5 Commits
Author SHA1 Message Date
Jörg Thalheim 31787cd754 docs: clarify generated image names 2024-03-11 09:55:04 +01:00
Jörg Thalheim 714768a174 docs: expand diskoImagesScript example 2024-03-11 09:40:38 +01:00
github-actions[bot] d389901567 flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/43d259f8d726113fac056e8bb17d5ac2dea3e0a8' (2024-03-05)
  → 'github:NixOS/nixpkgs/d40e866b1f98698d454dad8f592fe7616ff705a4' (2024-03-10)
2024-03-11 01:19:14 +00:00
Jörg Thalheim 72818e54ec move disko-install into disko package 2024-03-09 07:05:35 +00:00
github-actions[bot] a2009bc2b4 flake.lock: Update
Flake lock file updates:

• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/fa9a51752f1b5de583ad5213eb621be071806663' (2024-03-02)
  → 'github:NixOS/nixpkgs/43d259f8d726113fac056e8bb17d5ac2dea3e0a8' (2024-03-05)
2024-03-07 01:05:29 +00:00
5 changed files with 78 additions and 21 deletions

No files matched your search

+57 -5
View File
@@ -51,12 +51,49 @@ generate disk images:
### Generating the `.raw` VM Image ### Generating the `.raw` VM Image
1. **Build the disko image script:** Replace `mySystem` in the command below with your 1. **Create a NixOS configuration that includes the disko and the disk configuration of your choice**
specific system configuration name:
```console In the this example we create a flake containing a nixos configuration for `myhost`.
nix build .#nixosConfigurations.mySystem.config.system.build.diskoImagesScript
```nix
# save this as flake.nix
{
description = "A disko images example";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, disko, nixpkgs }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
# You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
./simple-efi.nix
disko.nixosModules.disko
({ config, ... }: {
# shut up state version warning
system.stateVersion = config.system.nixos.version;
# Adjust this to your liking.
# WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
disko.devices.disk.vdb.imageSize = "10G";
})
];
};
};
}
``` ```
2. **Execute the result file:** Execute the generated result file. Running
2. **Build the disko image script:** Replace `myhost` in the command below with your
specific system configuration name:
```console
nix build .#nixosConfigurations.myhost.config.system.build.diskoImagesScript
```
3. **Execute the disko image script:** Execute the generated disko image script. Running
`./result --help` will output the available options: `./result --help` will output the available options:
```console ```console
@@ -81,6 +118,21 @@ generate disk images:
There is no check if the specified path is actually a disk so you can also write to another file There is no check if the specified path is actually a disk so you can also write to another file
``` ```
An example run may look like this:
```
sudo ./result --build-memory 2048
```
The script will generate the actual image outside of the nix store in the current working directory.
The create image names depend on the names used in `disko.disks` attrset in the NixOS configuration.
In our code example it will produce the following image:
```
$ ls -la vdb.raw
.rw-r--r-- root root 10 GB 2 minutes ago vdb.raw
```
### Additional Configuration ### Additional Configuration
- For virtual drive use, define the image size in your Disko configuration: - For virtual drive use, define the image size in your Disko configuration:
Generated
+3 -3
View File
@@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1709386671, "lastModified": 1710097495,
"narHash": "sha256-VPqfBnIJ+cfa78pd4Y5Cr6sOWVW8GYHRVucxJGmRf8Q=", "narHash": "sha256-B7Ea7q7hU7SE8wOPJ9oXEBjvB89yl2csaLjf5v/7jr8=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "fa9a51752f1b5de583ad5213eb621be071806663", "rev": "d40e866b1f98698d454dad8f592fe7616ff705a4",
"type": "github" "type": "github"
}, },
"original": { "original": {
+4 -1
View File
@@ -28,7 +28,10 @@
in in
{ {
disko = pkgs.callPackage ./package.nix { }; disko = pkgs.callPackage ./package.nix { };
disko-install = pkgs.callPackage ./disko-install.nix { }; # alias to make `nix run` more convenient
disko-install = self.packages.${system}.disko.overrideAttrs (old: {
name = "disko-install";
});
default = self.packages.${system}.disko; default = self.packages.${system}.disko;
} // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64) { } // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64) {
disko-doc = pkgs.callPackage ./doc.nix { }; disko-doc = pkgs.callPackage ./doc.nix { };
+13 -10
View File
@@ -1,6 +1,6 @@
{ stdenvNoCC, makeWrapper, lib, path }: { stdenvNoCC, makeWrapper, lib, path, nix, coreutils }:
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation (finalAttrs: {
name = "disko"; name = "disko";
src = ./.; src = ./.;
nativeBuildInputs = [ nativeBuildInputs = [
@@ -8,13 +8,15 @@ stdenvNoCC.mkDerivation rec {
]; ];
installPhase = '' installPhase = ''
mkdir -p $out/bin $out/share/disko mkdir -p $out/bin $out/share/disko
cp -r cli.nix default.nix disk-deactivate lib $out/share/disko cp -r install-cli.nix cli.nix default.nix disk-deactivate lib $out/share/disko
sed \
-e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \ for i in disko disko-install; do
-e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \ sed -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" "$i" > "$out/bin/$i"
disko > $out/bin/disko chmod 755 "$out/bin/$i"
chmod 755 $out/bin/disko wrapProgram "$out/bin/$i" \
wrapProgram $out/bin/disko --prefix NIX_PATH : "nixpkgs=${path}" --prefix PATH : ${lib.makeBinPath [ nix coreutils ]} \
--prefix NIX_PATH : "nixpkgs=${path}"
done
''; '';
meta = with lib; { meta = with lib; {
description = "Format disks with nix-config"; description = "Format disks with nix-config";
@@ -22,5 +24,6 @@ stdenvNoCC.mkDerivation rec {
license = licenses.mit; license = licenses.mit;
maintainers = with maintainers; [ lassulus ]; maintainers = with maintainers; [ lassulus ];
platforms = platforms.linux; platforms = platforms.linux;
mainProgram = finalAttrs.name;
}; };
} })
+1 -2
View File
@@ -1,11 +1,10 @@
{ pkgs ? import <nixpkgs> { }, self }: { pkgs ? import <nixpkgs> { }, self }:
let let
disko-install = pkgs.callPackage ../../disko-install.nix { }; disko-install = pkgs.callPackage ../../disko-install.nix { };
toplevel = self.nixosConfigurations.testmachine.config.system.build.toplevel;
dependencies = [ dependencies = [
pkgs.stdenv.drvPath pkgs.stdenv.drvPath
toplevel self.nixosConfigurations.testmachine.config.system.build.toplevel
self.nixosConfigurations.testmachine.config.system.build.diskoScript self.nixosConfigurations.testmachine.config.system.build.diskoScript
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs); ] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);