nixos-containers: Added flake option (#413463)

authored by

jade and committed by
GitHub
f43a0881 2defa371

+33 -5
+33 -5
nixos/modules/virtualisation/nixos-containers.nix
··· 113 114 cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf" 115 116 declare -a extraFlags 117 118 if [ "$PRIVATE_NETWORK" = 1 ]; then ··· 844 ''; 845 }; 846 847 # Removed option. See `checkAssertion` below for the accompanying error message. 848 pkgs = mkOption { visible = false; }; 849 } // networkOptions; ··· 867 - containers.${name}.config.nixpkgs.pkgs 868 This only sets the `pkgs` argument used inside the container modules. 869 '' 870 else 871 null; 872 in 873 { 874 - path = 875 - builtins.seq checkAssertion mkIf options.config.isDefined 876 - config.config.system.build.toplevel; 877 }; 878 } 879 ) ··· 929 930 unitConfig.RequiresMountsFor = "${stateDirectory}/%i"; 931 932 - path = [ pkgs.iproute2 ]; 933 934 environment = { 935 root = "${stateDirectory}/%i"; ··· 1044 name: cfg: 1045 nameValuePair "${configurationDirectoryName}/${name}.conf" { 1046 text = '' 1047 - SYSTEM_PATH=${cfg.path} 1048 ${optionalString cfg.privateNetwork '' 1049 PRIVATE_NETWORK=1 1050 ${optionalString (cfg.hostBridge != null) ''
··· 113 114 cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf" 115 116 + if [ -n "$FLAKE" ] && [ ! -e "/nix/var/nix/profiles/per-container/$INSTANCE/system" ]; then 117 + # we create the etc/nixos-container config file, then if we utilize the update function, we can then build all the necessary system files for the container 118 + ${lib.getExe nixos-container} update "$INSTANCE" 119 + fi 120 + 121 declare -a extraFlags 122 123 if [ "$PRIVATE_NETWORK" = 1 ]; then ··· 849 ''; 850 }; 851 852 + flake = lib.mkOption { 853 + type = lib.types.nullOr lib.types.str; 854 + default = null; 855 + example = "github:NixOS/nixpkgs/master"; 856 + description = '' 857 + The Flake URI of the NixOS configuration to use for the container. 858 + Replaces the option {option}`containers.<name>.path`. 859 + ''; 860 + }; 861 + 862 # Removed option. See `checkAssertion` below for the accompanying error message. 863 pkgs = mkOption { visible = false; }; 864 } // networkOptions; ··· 882 - containers.${name}.config.nixpkgs.pkgs 883 This only sets the `pkgs` argument used inside the container modules. 884 '' 885 + else if options.config.isDefined && (options.flake.value != null) then 886 + throw '' 887 + The options 'containers.${name}.path' and 'containers.${name}.flake' cannot both be set. 888 + '' 889 else 890 null; 891 in 892 { 893 + path = builtins.seq checkAssertion mkMerge [ 894 + (mkIf options.config.isDefined config.config.system.build.toplevel) 895 + (mkIf (config.flake != null) "/nix/var/nix/profiles/per-container/${name}") 896 + ]; 897 }; 898 } 899 ) ··· 949 950 unitConfig.RequiresMountsFor = "${stateDirectory}/%i"; 951 952 + path = [ 953 + pkgs.iproute2 954 + config.nix.package 955 + ]; 956 957 environment = { 958 root = "${stateDirectory}/%i"; ··· 1067 name: cfg: 1068 nameValuePair "${configurationDirectoryName}/${name}.conf" { 1069 text = '' 1070 + ${optionalString (cfg.flake == null) '' 1071 + SYSTEM_PATH=${cfg.path} 1072 + ''} 1073 + ${optionalString (cfg.flake != null) '' 1074 + FLAKE=${cfg.flake} 1075 + ''} 1076 ${optionalString cfg.privateNetwork '' 1077 PRIVATE_NETWORK=1 1078 ${optionalString (cfg.hostBridge != null) ''