aboutsummaryrefslogtreecommitdiff
path: root/pkgs/python-packages/blivet/default.nix
blob: 108d548ac12bfa68e5323ca63c630862680ce20a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{ lib, writeText, poetry2nix, python, pythonPackages,
  gobject-introspection, libblockdev, libbytesize, fetchFromGitHub,
  pkg-config, parted, systemd,
  with_dmraid ? false,
  with_fs_btrfs ? false,
  with_fs_fat ? false,
  with_fs_f2fs ? false,
  with_fs_hfs_plus ? false,
  with_fs_jfs ? false,
  with_fs_nfs ? false,
  with_fs_nfsv4 ? false,
  with_fs_ntfs ? false,
  with_fs_reiserfs ? false,
  with_fs_xfs ? false,
  with_luks ? false,
  with_lvm ? false,
  with_mdadm ? false,
  with_multipath ? false,
  with_optical ? false,
  with_iscsi ? false,
  dmraid, multipath_tools, lvm2, eject, kmod, utillinux, lsof,
  openiscsi, coreutils, dosfstools, e2fsprogs, jfsutils, btrfs-progs,
  xfsprogs, f2fs-tools, hfsprogs, nfs-utils, ntfs3g, ntfsprogs,
  reiserfsprogs, devicemapper, cryptsetup, mdadm
}@args:
let
  # FIXME: blivet/tasks/fsmount.py links to /sbin
  additionalPackages =
      lib.optionals with_dmraid [ dmraid ]
   ++ lib.optionals with_fs_btrfs [ btrfs-progs ]
   ++ lib.optionals with_fs_fat [ dosfstools ]
   ++ lib.optionals with_fs_f2fs [ f2fs-tools ]
   ++ lib.optionals with_fs_hfs_plus [ hfsprogs ]
   ++ lib.optionals with_fs_jfs [ jfsutils ]
   ++ lib.optionals with_fs_nfs [ nfs-utils ]
   ++ lib.optionals with_fs_ntfs [ ntfs3g ntfsprogs ]
   ++ lib.optionals with_fs_reiserfs [ reiserfsprogs ]
   ++ lib.optionals with_fs_xfs [ xfsprogs.bin ]
   ++ lib.optionals with_luks [ devicemapper cryptsetup ]
   ++ lib.optionals with_lvm [ lvm2 ]
   ++ lib.optionals with_mdadm [ mdadm ]
   ++ lib.optionals with_multipath [ multipath_tools ]
   ++ lib.optionals with_optical [ eject ]
   ++ lib.optionals with_iscsi [ openiscsi ];
in
# nix-shell -E "with import <nixpkgs> {}; pkgs.mkShell { buildInputs = [ python3 python3Packages.blivet3 ]; }"
# nix-shell -E "with import <nixpkgs> {}; pkgs.mkShell { buildInputs = [ (python3.withPackages(p: [ p.blivet3 ])) ]; }"
poetry2nix.mkPoetryApplication {
  inherit python;
  propagatedBuildInputs = [
    gobject-introspection
    (pythonPackages.toPythonModule libblockdev)
    (pythonPackages.toPythonModule libbytesize)
  ];
  src = fetchFromGitHub {
    owner = "storaged-project";
    repo = "blivet";
    rev = "blivet-3.3.0";
    sha256 = "0ynxm37cxxr2sf2hj18hrdxs1qfw6dgdagkvv5f6g4fmp51m7c3c";
  };
  overrides = poetry2nix.overrides.withDefaults (self: super: {
    pyparted = super.pyparted.overridePythonAttrs (old: {
      buildInputs = old.buildInputs ++ [ parted ];
      nativeBuildInputs = old.nativeBuildInputs ++ [ pkg-config ];
    });
    selinux = super.selinux.overridePythonAttrs (old: {
      buildInputs = old.buildInputs ++ [ self.setuptools-scm-git-archive ];
      nativeBuildInputs = old.nativeBuildInputs ++ [ pkg-config ];
    });
  });
  patches = [ ./fix_path.patch ];
  postPatch = let
    runtimePaths = lib.makeBinPath ([
      systemd utillinux kmod e2fsprogs mdadm lsof coreutils
    ] ++ additionalPackages);
    libraryPath = builtins.concatStringsSep " " (map (v: "-rpath ${v}/lib -L ${v}/lib") [ systemd.lib ]);
    giLibraryPath = lib.makeSearchPath "lib/girepository-1.0" [libblockdev gobject-introspection];
    addGiPath = writeText "add-gi-path" ''
      import os
      newGiPath = "${giLibraryPath}"
      if newGiPath not in os.environ.get("GI_TYPELIB_PATH", ""):
          os.environ["GI_TYPELIB_PATH"] = os.environ.get("GI_TYPELIB_PATH", "") + ":" + newGiPath
    '';
    addPath = writeText "add-path" ''
      import os
      newPath = "${runtimePaths}"
      newLibraryPath = "${libraryPath}"
      if newPath not in os.environ.get("PATH", ""):
          os.environ["PATH"] = os.environ.get("PATH", "") + ":" + newPath
          os.environ["NIX_LDFLAGS"] = os.environ.get("NIX_LDFLAGS", "") + " " + newLibraryPath
    '';
  in
  ''
      prepend() {
        mv "$1" "$1.bak"
        cat ${addPath} "$1.bak" > $1
        rm -f "$1.bak"
      }
      prepend "blivet/__init__.py"
      prepend "blivet/iscsi.py"
      prepend "blivet/tasks/availability.py"
      prepend "blivet/util.py"
      prepend "blivet/udev.py"
      prependGi() {
        mv "$1" "$1.bak"
        cat ${addGiPath} "$1.bak" > $1
        rm -f "$1.bak"
      }
      grep -rl require_version blivet/ | while read i; do prependGi "$i"; done
      sed -i -e "s@/lib/modules@/run/booted-system/kernel-modules/lib/modules/@" blivet/tasks/fsmount.py
    '';
  postInstall = let
  in ''
    rm -rf $out/lib/python*/site-packages/{etc,usr}
    '';
  pyproject = ./pyproject.toml;
  poetrylock = ./poetry.lock;
}