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 113 114 114 cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf" 115 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 + 116 121 declare -a extraFlags 117 122 118 123 if [ "$PRIVATE_NETWORK" = 1 ]; then ··· 844 849 ''; 845 850 }; 846 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 + 847 862 # Removed option. See `checkAssertion` below for the accompanying error message. 848 863 pkgs = mkOption { visible = false; }; 849 864 } // networkOptions; ··· 867 882 - containers.${name}.config.nixpkgs.pkgs 868 883 This only sets the `pkgs` argument used inside the container modules. 869 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 + '' 870 889 else 871 890 null; 872 891 in 873 892 { 874 - path = 875 - builtins.seq checkAssertion mkIf options.config.isDefined 876 - config.config.system.build.toplevel; 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 + ]; 877 897 }; 878 898 } 879 899 ) ··· 929 949 930 950 unitConfig.RequiresMountsFor = "${stateDirectory}/%i"; 931 951 932 - path = [ pkgs.iproute2 ]; 952 + path = [ 953 + pkgs.iproute2 954 + config.nix.package 955 + ]; 933 956 934 957 environment = { 935 958 root = "${stateDirectory}/%i"; ··· 1044 1067 name: cfg: 1045 1068 nameValuePair "${configurationDirectoryName}/${name}.conf" { 1046 1069 text = '' 1047 - SYSTEM_PATH=${cfg.path} 1070 + ${optionalString (cfg.flake == null) '' 1071 + SYSTEM_PATH=${cfg.path} 1072 + ''} 1073 + ${optionalString (cfg.flake != null) '' 1074 + FLAKE=${cfg.flake} 1075 + ''} 1048 1076 ${optionalString cfg.privateNetwork '' 1049 1077 PRIVATE_NETWORK=1 1050 1078 ${optionalString (cfg.hostBridge != null) ''