128: add support for another mountpoint than /mnt r=Mic92 a=Lassulus



Co-authored-by: lassulus <lassulus@lassul.us>
Co-authored-by: lassulus <git@lassul.us>
This commit is contained in:
bors[bot] 2023-01-28 17:21:26 +00:00 committed by GitHub
commit aa26c0ce0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 31 deletions

View file

@ -3,10 +3,12 @@
, flake ? null , flake ? null
, flakeAttr ? null , flakeAttr ? null
, diskoFile ? null , diskoFile ? null
, rootMountPoint ? "/mnt"
, noDeps ? false , noDeps ? false
, ... }@args: , ... }@args:
let let
disko = import ./. { disko = import ./. {
inherit rootMountPoint;
lib = pkgs.lib; lib = pkgs.lib;
}; };

View file

@ -1,6 +1,8 @@
{ lib ? import <nixpkgs/lib> }: { lib ? import <nixpkgs/lib>
, rootMountPoint ? "/mnt"
}:
let let
types = import ./types.nix { inherit lib; }; types = import ./types.nix { inherit lib rootMountPoint; };
eval = cfg: lib.evalModules { eval = cfg: lib.evalModules {
modules = lib.singleton { modules = lib.singleton {
# _file = toString input; # _file = toString input;

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
set -efux set -efux
# dependencies: jq util-linux lvm2 mdadm zfs # dependencies: jq util-linux lvm2 mdadm zfs
disk=$1 disk=$(realpath "$1")
lsblk --output-all --json | jq -r --arg disk_to_clear "$disk" -f "$(dirname "$0")/disk-deactivate.jq" lsblk --output-all --json | jq -r --arg disk_to_clear "$disk" -f "$(dirname "$0")/disk-deactivate.jq"

8
disko
View file

@ -25,6 +25,8 @@ Options:
pass value to nix-build. can be used to set disk-names for example pass value to nix-build. can be used to set disk-names for example
* --argstr name value * --argstr name value
pass value to nix-build as string pass value to nix-build as string
* --root-mountpoint /mnt
where to mount the device tree
* --dry-run * --dry-run
just show the path to the script instead of running it just show the path to the script instead of running it
* --debug * --debug
@ -54,7 +56,7 @@ while [[ $# -gt 0 ]]; do
shift shift
;; ;;
-f | --flake) -f | --flake)
flake="$2" flake=$2
shift shift
;; ;;
--argstr | --arg) --argstr | --arg)
@ -69,6 +71,10 @@ while [[ $# -gt 0 ]]; do
--dry-run) --dry-run)
dry_run=y dry_run=y
;; ;;
--root-mountpoint)
nix_args+=(--arg rootMountPoint "$2")
shift
;;
--no-deps) --no-deps)
nix_args+=(--arg noDeps true) nix_args+=(--arg noDeps true)
;; ;;

View file

@ -1,7 +1,10 @@
{ lib, nixosOptionsDoc, runCommand, fetchurl, pandoc }: { lib, nixosOptionsDoc, runCommand, fetchurl, pandoc }:
let let
types = import ./types.nix { inherit lib; }; types = import ./types.nix {
inherit lib;
rootMountPoint = "/mnt";
};
eval = lib.evalModules { eval = lib.evalModules {
modules = [ modules = [
{ {

View file

@ -1,6 +1,9 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
types = import ./types.nix { inherit lib; }; types = import ./types.nix {
inherit lib;
rootMountPoint = config.disko.rootMountPoint;
};
cfg = config.disko; cfg = config.disko;
in { in {
options.disko = { options.disko = {
@ -9,6 +12,11 @@ in {
default = {}; default = {};
description = "The devices to set up"; description = "The devices to set up";
}; };
rootMountPoint = lib.mkOption {
type = lib.types.str;
default = "/mnt";
description = "Where the device tree should be mounted by the mountScript";
};
enableConfig = lib.mkOption { enableConfig = lib.mkOption {
description = '' description = ''
configure nixos with the specified devices configure nixos with the specified devices

View file

@ -1,4 +1,4 @@
{ lib }: { lib, rootMountPoint }:
with lib; with lib;
with builtins; with builtins;
@ -211,7 +211,7 @@ rec {
in '' in ''
set -efux set -efux
# first create the necessary devices # first create the necessary devices
${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev or "") sortedDeviceList} ${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) {} devices) {}).dev or "") sortedDeviceList}
# and then mount the filesystems in alphabetical order # and then mount the filesystems in alphabetical order
${concatStrings (attrValues fsMounts)} ${concatStrings (attrValues fsMounts)}
@ -223,7 +223,7 @@ rec {
*/ */
zapCreateMount = devices: '' zapCreateMount = devices: ''
set -efux set -efux
umount -Rv /mnt || : umount -Rv "${rootMountPoint}" mnt || :
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
${./disk-deactivate}/disk-deactivate "$dev" | bash -x ${./disk-deactivate}/disk-deactivate "$dev" | bash -x
@ -247,25 +247,22 @@ rec {
}; };
optionTypes = rec { optionTypes = rec {
# POSIX.12017, 3.281 Portable Filename
filename = mkOptionType { filename = mkOptionType {
name = "POSIX portable filename"; name = "filename";
check = x: isString x && builtins.match "[0-9A-Za-z._][0-9A-Za-z._-]*" x != null; check = x: isString x;
merge = mergeOneOption; merge = mergeOneOption;
description = "A filename"; description = "A filename";
}; };
# POSIX.12017, 3.2 Absolute Pathname
absolute-pathname = mkOptionType { absolute-pathname = mkOptionType {
name = "POSIX absolute pathname"; name = "absolute pathname";
check = x: isString x && substring 0 1 x == "/" && pathname.check x; check = x: isString x && substring 0 1 x == "/" && pathname.check x;
merge = mergeOneOption; merge = mergeOneOption;
description = "An absolute path"; description = "An absolute path";
}; };
# POSIX.1-2017, 3.271 Pathname
pathname = mkOptionType { pathname = mkOptionType {
name = "POSIX pathname"; name = "pathname";
check = x: check = x:
let let
# The filter is used to normalize paths, i.e. to remove duplicated and # The filter is used to normalize paths, i.e. to remove duplicated and
@ -354,8 +351,8 @@ rec {
inherit config options; inherit config options;
default = {}: { default = {}: {
fs.${config.mountpoint} = '' fs.${config.mountpoint} = ''
if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount -t ${config.fsType} ${config.device} "/mnt${config.mountpoint}" \ mount -t ${config.fsType} ${config.device} "${rootMountPoint}${config.mountpoint}" \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir -o X-mount.mkdir
fi fi
@ -434,8 +431,8 @@ rec {
in { in {
fs = subvolMounts.fs // optionalAttrs (!isNull config.mountpoint) { fs = subvolMounts.fs // optionalAttrs (!isNull config.mountpoint) {
${config.mountpoint} = '' ${config.mountpoint} = ''
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${dev} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "/mnt${config.mountpoint}" \ mount ${dev} "${rootMountPoint}${config.mountpoint}" \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir -o X-mount.mkdir
fi fi
@ -524,8 +521,8 @@ rec {
else null; else null;
in optionalAttrs (!isNull mountpoint) { in optionalAttrs (!isNull mountpoint) {
fs.${mountpoint} = '' fs.${mountpoint} = ''
if ! findmnt ${dev} "/mnt${mountpoint}" > /dev/null 2>&1; then if ! findmnt ${dev} "${rootMountPoint}${mountpoint}" > /dev/null 2>&1; then
mount ${dev} "/mnt${mountpoint}" \ mount ${dev} "${rootMountPoint}${mountpoint}" \
${concatMapStringsSep " " (opt: "-o ${opt}") (config.mountOptions ++ [ "subvol=${config.name}" ])} \ ${concatMapStringsSep " " (opt: "-o ${opt}") (config.mountOptions ++ [ "subvol=${config.name}" ])} \
-o X-mount.mkdir -o X-mount.mkdir
fi fi
@ -603,8 +600,8 @@ rec {
inherit config options; inherit config options;
default = {dev}: { default = {dev}: {
fs.${config.mountpoint} = '' fs.${config.mountpoint} = ''
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${dev} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "/mnt${config.mountpoint}" \ mount ${dev} "${rootMountPoint}${config.mountpoint}" \
-t "${config.format}" \ -t "${config.format}" \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir -o X-mount.mkdir
@ -683,9 +680,7 @@ rec {
let let
partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions; partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions;
in { in {
dev = '' dev = partMounts.dev or "";
${concatMapStrings (x: x.dev or "") (attrValues partMounts)}
'';
fs = partMounts.fs or {}; fs = partMounts.fs or {};
}; };
}; };
@ -1169,8 +1164,8 @@ rec {
''; '';
fs = datasetMounts.fs // optionalAttrs (!isNull config.mountpoint) { fs = datasetMounts.fs // optionalAttrs (!isNull config.mountpoint) {
${config.mountpoint} = '' ${config.mountpoint} = ''
if ! findmnt ${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${config.name} "/mnt${config.mountpoint}" \ mount ${config.name} "${rootMountPoint}${config.mountpoint}" \
${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir \ -o X-mount.mkdir \
@ -1273,8 +1268,8 @@ rec {
default = {zpool}: default = {zpool}:
optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount {dev = "/dev/zvol/${zpool}/${config.name}";}) // optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount {dev = "/dev/zvol/${zpool}/${config.name}";}) //
optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = '' optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = ''
if ! findmnt ${zpool}/${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${zpool}/${config.name} "/mnt${config.mountpoint}" \ mount ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" \
-o X-mount.mkdir \ -o X-mount.mkdir \
${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ ${concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \ ${optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \