diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index a3c83521c354..3f497566ff11 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -472,6 +472,13 @@ in ''; }; + systemd.generator-packages = mkOption { + default = []; + type = types.listOf types.package; + example = literalExample "[ pkgs.systemd-cryptsetup-generator ]"; + description = "Packages providing systemd generators."; + }; + systemd.defaultUnit = mkOption { default = "multi-user.target"; type = types.str; @@ -628,7 +635,18 @@ in environment.systemPackages = [ systemd ]; - environment.etc = { + environment.etc = let + # generate contents for /etc/systemd/system-generators from + # systemd.generators and systemd.generator-packages + generators = pkgs.runCommand "system-generators" { packages = cfg.generator-packages; } '' + mkdir -p $out + for package in $packages + do + ln -s $package/lib/systemd/system-generators/* $out/ + done; + ${concatStrings (mapAttrsToList (generator: target: "ln -s ${target} $out/${generator};\n") cfg.generators)} + ''; + in ({ "systemd/system".source = generateUnits "system" cfg.units upstreamSystemUnits upstreamSystemWants; "systemd/user".source = generateUnits "user" cfg.user.units upstreamUserUnits []; @@ -667,7 +685,9 @@ in ${concatStringsSep "\n" cfg.tmpfiles.rules} ''; - } // mapAttrs' (n: v: nameValuePair "systemd/system-generators/${n}" {"source"=v;}) cfg.generators; + + "systemd/system-generators" = { source = generators; }; + }); system.activationScripts.systemd = stringAfter [ "groups" ] '' diff --git a/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix b/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix new file mode 100644 index 000000000000..2935990755c6 --- /dev/null +++ b/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix @@ -0,0 +1,25 @@ +{ stdenv, systemd, cryptsetup }: + +assert stdenv.isLinux; + +stdenv.lib.overrideDerivation systemd (p: { + version = p.version; + name = "systemd-cryptsetup-generator"; + + nativeBuildInputs = p.nativeBuildInputs ++ [ cryptsetup ]; + outputs = [ "out" ]; + + buildPhase = '' + make $makeFlags built-sources + make $makeFlags systemd-cryptsetup + make $makeFlags systemd-cryptsetup-generator + ''; + + installPhase = '' + mkdir -p $out/lib/systemd/ + cp systemd-cryptsetup $out/lib/systemd/systemd-cryptsetup + + mkdir -p $out/lib/systemd/system-generators/ + cp systemd-cryptsetup-generator $out/lib/systemd/system-generators/systemd-cryptsetup-generator + ''; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8ca9370cc0e4..188788955ffe 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11006,6 +11006,9 @@ in linuxHeaders = linuxHeaders_3_18; }; + # standalone cryptsetup generator for systemd + systemd-cryptsetup-generator = callPackage ../os-specific/linux/systemd/cryptsetup-generator.nix { }; + # In nixos, you can set systemd.package = pkgs.systemd_with_lvm2 to get # LVM2 working in systemd. systemd_with_lvm2 = pkgs.lib.overrideDerivation pkgs.systemd (p: {