Add Nix Packaging

This commit is contained in:
Andrew R. M 2023-11-10 20:28:51 +00:00
parent 32522df0e2
commit 331e7c8279
3 changed files with 94 additions and 2 deletions

9
Vagrantfile vendored
View File

@ -78,14 +78,19 @@ Vagrant.configure("2") do |config|
path: "provisioners/install-xfce-minimal.sh" \ path: "provisioners/install-xfce-minimal.sh" \
if gui_enabled if gui_enabled
config.vm.provision :shell,
name: "Install APT Packages",
path: "provisioners/install-apt-packages.sh"
config.vm.provision :shell, config.vm.provision :shell,
name: "Install Nix", name: "Install Nix",
path: "provisioners/install-nix.sh", path: "provisioners/install-nix.sh",
privileged: false privileged: false
config.vm.provision :shell, config.vm.provision :shell,
name: "Install APT Packages", name: "Install Nix Packages",
path: "provisioners/install-apt-packages.sh" path: "provisioners/install-nix-packages-flakes.sh",
privileged: false
config.vm.provision :shell, config.vm.provision :shell,
name: "Setup SSH keys", name: "Setup SSH keys",

View File

@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Installs packages to the nix profile using nix profile
# Reference: https://nixos.org/manual/nixpkgs/stable/#sec-declarative-package-management
set -ex
nix_packages=(
# Personal tools
"vimHugeX"
"ranger"
"jq"
"yq"
# Professional tools
"kubernetes-helm"
"vault"
"kubectl"
"rancher"
"terraform"
"terragrunt"
"skopeo"
"awscli2"
)
mkdir -p ~/.config/nixpkgs/
templated_insert=$(for nix_package in ${nix_packages[@]}; do echo " $nix_package"; done)
# Reference: https://discourse.nixos.org/t/nix-profile-in-combination-with-declarative-package-management/21228/9
cat << EOF > ~/.config/nixpkgs/flake.nix
{
description = "A declarative system installation";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; # also possible: `nixos-unstable`
};
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
# Generate a user-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.\${system};
in {
default = self.packages.\${system}.myPackageCollection;
myPackageCollection = # libs and clis
let
pkgs = nixpkgs.legacyPackages.\${system}; # here we need just legacy packages
in pkgs.buildEnv {
name = "myPackages";
paths = with pkgs; [
${templated_insert}
];
extraOutputsToInstall = [ "man" "doc" ];
};
}); # packages
}; # outputs
}
EOF
install_nix_packages()
{
# The name of the package we are going to install, needed to check for presence/uninstall
package_name=packages.x86_64-linux.myPackageCollection
if [ "${nix_packages[*]}" ]; then
if nix profile list | cut -d' ' -f 2 | grep -q "${package_name}"; then
echo "Removing previous version of profile"
nix profile remove "${package_name}"
fi
echo "Installing profile"
nix profile install "${HOME}/.config/nixpkgs/flake.nix#myPackageCollection"
fi
}
install_nix_packages

0
provisioners/install-nix.sh Normal file → Executable file
View File