Skip to content

Instantly share code, notes, and snippets.

@juhp
Last active November 21, 2025 19:29
Show Gist options
  • Select an option

  • Save juhp/91c71a85f89fdc371b68764956a66012 to your computer and use it in GitHub Desktop.

Select an option

Save juhp/91c71a85f89fdc371b68764956a66012 to your computer and use it in GitHub Desktop.
nixos container
{
description = "NixOS container image";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
lib = nixpkgs.lib;
osRelease = pkgs.writeTextDir "etc/os-release" ''
ANSI_COLOR="0;38;2;126;186;228"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="25.05.20251120.c58bc7f"
CPE_NAME="cpe:/o:nixos:nixos:25.05"
DEFAULT_HOSTNAME=nixos
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
ID_LIKE=""
IMAGE_ID=""
IMAGE_VERSION=""
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 25.05 (Warbler)"
SUPPORT_END="2025-12-31"
SUPPORT_URL="https://nixos.org/community.html"
VARIANT=""
VARIANT_ID=""
VENDOR_NAME=NixOS
VENDOR_URL="https://nixos.org/"
VERSION="25.05 (Warbler)"
VERSION_CODENAME=warbler
VERSION_ID="25.05"
'';
in
{
packages.${system}.default = pkgs.dockerTools.buildLayeredImage {
name = "nixos";
tag = lib.version;
contents = with pkgs; [
osRelease
dockerTools.binSh
dockerTools.usrBinEnv
dockerTools.fakeNss
dockerTools.caCertificates
bashInteractive
coreutils
curl
findutils
gitMinimal
gnugrep
nix
vim
];
extraCommands = ''
mkdir -p root tmp
chmod 1777 tmp
chmod 700 root
'';
config = {
Cmd = [ "/bin/bash" ];
Env = [
"USER=root"
"HOME=/root"
"PATH=/bin:/usr/bin"
# "SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
"LANG=C.UTF-8"
];
};
};
};
}
@juhp
Copy link
Author

juhp commented Nov 21, 2025

Initial nixos:25.05 container

Assisted by Gemini 3 Pro

$ nix build
$ nix path-info -Sh ./result 
$ cat result | podman load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment