Skip to content

ES-Nix/es

Repository files navigation

es

Remote using this flake

Example: nginx in an NixOS QEMU VM

nix run --impure 'github:ES-Nix/es/?dir=src/templates/nginx'
nix build --cores 8 --no-link --print-build-logs --print-out-paths --impure \
'github:ES-Nix/es/?dir=src/templates/pandoc-latex'

nix build --cores 8 --no-link --print-build-logs --print-out-paths --impure \
'github:ES-Nix/es/?dir=src/templates/memcached-static'
docker \
run \
--tty=true \
--interactive=true \
--rm=true \
docker.io/nixpkgs/nix-flakes \
bash

With a local clone

TODO: remove warnings TODO: better name things, consistency and case conventions

nix flake show --json .# | jq '."templates"'

nix eval --json '.#templates' \
| jq '.[].path' \
| cut -d'/' -f5- \
| tr -d '"' \
| xargs -I{} nix eval '.?dir={}#allTests'

nix eval --json '.#templates' \
| jq '.[].path' \
| cut -d'/' -f5- \
| tr -d '"' \
| xargs -I{} sh -cl 'cd {} && nix run .#allTests && cd -'
TEMPLATE_FOLDERS_RELATIVE_PATH=($(nix --option warn-dirty false eval --json '.#templates' | jq '.[].path' | cut -d'/' -f5- | tr -d '"'))
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}";
do
    cd "$template" \
    && nix --option warn-dirty false eval '.#'
    # clear
    cd -
done

TEMPLATE_FOLDERS_RELATIVE_PATH=($(nix --option warn-dirty false eval --json '.#templates' | jq '.[].path' | cut -d'/' -f5- | tr -d '"'))
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}";
do
    cd "$template" \
    && nix --option warn-dirty false eval '.#allTests'
    # clear
    cd -
done
TEMPLATE_FOLDERS_RELATIVE_PATH=($(nix eval --json '.#templates' | jq '.[].path' | cut -d'/' -f5- | tr -d '"'))
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}";
do
    cd "$template" \
    && nix --option warn-dirty false run '.#allTests'
    # clear
    cd -
done
TEMPLATE_FOLDERS_RELATIVE_PATH=(
    './src/templates/minimal-busybox-sandbox-shell'
    './src/templates/binfmt-emulated-riscv64-python-alpine-wheels-via-pip-and-docker'
    './src/templates/binfmt-emulated-riscv64-python-wheels-docker-registry-images'
    './src/templates/binfmt-emulated-systems-docker'
    './src/templates/binfmt-emulated-systems-hello'
    './src/templates/binfmt-emulated-systems-python-docker-registry-images'
    './src/templates/docker-multiple-kernel-versions'
)

for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}"; do
    cd "$template" \
    && nix run '.#allTests' \
    && cd -
done


TEMPLATE_FOLDERS_RELATIVE_PATH=(
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-bloated'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-geopandas'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-hello'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-mmh3'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-numpy'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-pandas'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-polars'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-fastapi-scipy'  
)
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}"; do
    cd "$template" \
    && nix run '.#allTests' \
    && cd -
done

TEMPLATE_FOLDERS_RELATIVE_PATH=(
#'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-bloated'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-geopandas'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-hello'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-mmh3'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-numpy'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-pandas'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-polars'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-docker-poetry2nix-flask-scipy'  
)
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}"; do
    cd "$template" \
    && nix run '.#allTests' \
    && cd -
done


TEMPLATE_FOLDERS_RELATIVE_PATH=(
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-almalinux'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-alpine'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-alpine'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-archlinux'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-debian'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-fedora'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-nixos'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-opensuse'
'./src/templates/qemu-virtual-machine-xfce-copy-paste-libvirt-vagrant-ubuntu'
)
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}"; do
    cd "$template" \
    && nix run '.#allTests' \
    && cd -
done

TEMPLATE_FOLDERS_RELATIVE_PATH=(
'./src/templates/redis-static'
'./src/templates/valkey-static'
'./src/templates/nginx-static'
'./src/templates/memcached-static'
)
for template in "${TEMPLATE_FOLDERS_RELATIVE_PATH[@]}"; do
    cd "$template" \
    && nix run '.#allTests' \
    && cd -
done

Contributing

nix flake clone 'git+ssh://git@github.com/ES-Nix/es.git' --dest es \
&& cd es 1>/dev/null 2>/dev/null \
&& (direnv --version 1>/dev/null 2>/dev/null && direnv allow) \
|| nix develop $SHELL

Using

# https://xkcd.com/1654/
command -v curl || (command -v apt && sudo apt-get update && sudo apt-get install -y curl)
command -v curl || (command -v apk && sudo apk add --no-cache curl)

(( test -d /nix/var/nix \
|| test -w /nix \
|| test 1735 -eq $(stat -c '%a' /nix/var/nix)
) || sudo sh -c 'mkdir -pv -m 1735 /nix/var/nix && chown -Rv '"$(id -nu)":"$(id -gn)"' /nix') \
&& curl -L https://hydra.nixos.org/build/297111184/download-by-type/file/binary-dist > nix \
&& echo 7838348c0e560855921cfa97051161bd63e29ee7ef4111eedc77228e91772958'  'nix \
 | sha256sum -c \
&& chmod +x nix \
&& ./nix --version \
&& ./nix \
--extra-experimental-features nix-command \
--extra-experimental-features flakes \
run \
github:ES-nix/es#installStartConfigTemplate \
&& exec ~/.nix-profile/bin/zsh

# command -v ssh-keygen || nix profile install nixpkgs#openssh
# command -v git || nix profile install nixpkgs#git
nix \
run \
--refresh \
github:ES-nix/es#sendToCacheInstallStartConfigTemplate

nix registry list
nix flake show templates

TODO: test all the templates!

nix flake show templates --json

nix \
--refresh \
run \
github:ES-nix/es#installStartConfigTemplate
rm -frv ~/.cache/nix/*
mkdir -pv ~/sandbox/sandbox \
&& cd ~/sandbox/sandbox
nix \
--refresh \
flake \
init \
--template \
github:ES-nix/es#"$(nix eval --impure --raw --expr 'builtins.currentSystem')".startConfig
nix shell nixpkgs#git -c sh -c 'git init && git add .'
# Precisa das variáveis de ambiente USER e HOME

# DIRECTORY_TO_CLONE=/home/"$USER"/.config/nixpkgs
DIRECTORY_TO_CLONE=/home/"$USER"/sandbox/sandbox

# export DUMMY_USER=alpine
export DUMMY_USER="$USER"
# export DUMMY_USER="$(id -un)"

# TODO: Mac
# export DUMMY_HOME="$HOME"
export DUMMY_HOME=/home/"$USER"

# export DUMMY_HOSTNAME=alpine316.localdomain
export DUMMY_HOSTNAME="$(hostname)"



BASE_HM_ATTR_NAME="$DUMMY_USER"-"$DUMMY_HOSTNAME"
FLAKE_ARCHITECTURE=$(nix eval --impure --raw --expr 'builtins.currentSystem').

HM_ATTR_FULL_NAME="$FLAKE_ARCHITECTURE"'"""'"$BASE_HM_ATTR_NAME"'"""'

FLAKE_ATTR="$DIRECTORY_TO_CLONE""#homeConfigurations.""$HM_ATTR_FULL_NAME"".activationPackage"

# "$(nix eval --impure --raw --expr 'builtins.currentSystem')"-
#HM_ATTR_FULL_NAME='"'"$DUMMY_USER"-"$DUMMY_HOSTNAME"'"'
#FLAKE_ATTR="$DIRECTORY_TO_CLONE""#homeConfigurations.""$HM_ATTR_FULL_NAME"".activationPackage"

nix profile install github:NixOS/nixpkgs/f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb#git
 
time \
nix \
--option eval-cache false \
--option extra-trusted-public-keys binarycache-1:XiPHS/XT/ziMHu5hGoQ8Z0K88sa1Eqi5kFTYyl33FJg= \
--option extra-substituters https://playing-bucket-nix-cache-test.s3.amazonaws.com \
shell \
github:NixOS/nixpkgs/f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb#{git,bashInteractive,coreutils,gnused,home-manager} \
--command \
bash <<-EOF
    echo $DIRECTORY_TO_CLONE
    rm -frv $DIRECTORY_TO_CLONE
    mkdir -pv $DIRECTORY_TO_CLONE

    cd $DIRECTORY_TO_CLONE
    
    nix \
    --refresh \
    flake \
    init \
    --template \
    github:ES-nix/es#"$(nix eval --impure --raw --expr 'builtins.currentSystem')".startConfig

    sed -i 's/username = ".*";/username = "'$DUMMY_USER'";/g' flake.nix \
    && sed -i 's/hostname = ".*";/hostname = "'"$DUMMY_HOSTNAME"'";/g' flake.nix \
    && git init \
    && git status \
    && git add . \
    && nix flake update --override-input nixpkgs github:NixOS/nixpkgs/f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb \
    && git status \
    && git add .
    
    echo "$FLAKE_ATTR"
    # TODO: --max-jobs 0 \
    nix \
    --option eval-cache false \
    --option extra-trusted-public-keys binarycache-1:XiPHS/XT/ziMHu5hGoQ8Z0K88sa1Eqi5kFTYyl33FJg= \
    --option extra-substituters https://playing-bucket-nix-cache-test.s3.amazonaws.com \
    build \
    --keep-failed \
    --max-jobs 0 \
    --no-link \
    --print-build-logs \
    --print-out-paths \
    "$FLAKE_ATTR"
    
    export NIXPKGS_ALLOW_UNFREE=1 \
    && home-manager switch -b backuphm --impure --flake "$DIRECTORY_TO_CLONE"#"$HM_ATTR_FULL_NAME" \
    && home-manager generations
    
    #
    TARGET_SHELL='zsh' \
    && FULL_TARGET_SHELL=/home/"$DUMMY_USER"/.nix-profile/bin/"\$TARGET_SHELL" \
    && echo \
    && ls -al "\$FULL_TARGET_SHELL" \
    && echo \
    && echo "\$FULL_TARGET_SHELL" | sudo tee -a /etc/shells \
    && echo \
    && sudo \
          -k \
          usermod \
          -s \
          /home/"$DUMMY_USER"/.nix-profile/bin/"\$TARGET_SHELL" \
          "$DUMMY_USER"
    
EOF

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages