Skip to content

Instantly share code, notes, and snippets.

@con-f-use
Last active September 17, 2024 17:41
Show Gist options
  • Save con-f-use/5ad3a605e45aa2527eb9b2f85ccfa043 to your computer and use it in GitHub Desktop.
Save con-f-use/5ad3a605e45aa2527eb9b2f85ccfa043 to your computer and use it in GitHub Desktop.
Random Nix Links
@con-f-use
Copy link
Author

con-f-use commented Sep 15, 2024

image

image

image

image

@con-f-use
Copy link
Author

con-f-use commented Sep 15, 2024

# Example for an impure way to deal with python dependencies

let
  commit = "91a00709aebb3602f172a0bf47ba1ef013e34835";
  pkgs = import (builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs/archive/${commit}.tar.gz";
  }) { config = {}; overlays = []; };
in
#{  # flake variant
#  outputs = { self, nixpkgs, ... }: let
#    system = "x86_64-linux";
#    pkgs = nixpkgs.legacyPackages."${system}";
#  in {
# devShells.${system}.default =
pkgs.mkShell {
  name = "impurePythonEnv";

  # Pure Part (python deps from nixpkgs):
  buildInputs = with pkgs; [
    python3Packages.python python3Packages.venvShellHook  # we need a python interpreter for the venv hook
    python3Packages.requests # a nixpkgs-packaged python requirements
    git openssl # system dependencies (runtime or for pip install ...)
  ];

  # Impure Part:
  venvDir = "./.venv";
  postVenvCreation = ''
    if [ -r requirements.txt ]; then
      pip install -r requirements.txt  # install non-nix packaged requirements
    fi
    pip install click
  '';

  postShellHook = ''
    python -c 'import requests, click
    print(f"{requests.__version__ = }\n{click.__version__ = }")
    c = requests.get("https://api.github.com/repos/NixOS/nixpkgs/commits/nixos-unstable").json()["sha"]
    print(f"latest nixos-unstable commit: {c}")'
    echo using ${commit}
  '';
}
#;  };
#}

@con-f-use
Copy link
Author

con-f-use commented Sep 16, 2024

Configuration options for nix:

echo '
allowed-users = @wheel
auto-optimise-store = true
experimental-features = nix-command flakes repl-flake
flake-registry = /etc/nix/registry.json
max-jobs = auto
nix-path = nixpkgs=/etc/nixpkgs
require-sigs = true
sandbox = true
sandbox-fallback = false
trusted-users = root @wheel
use-xdg-base-directories = true
builders-use-substitutes = true' | sudo tee -a /etc/nix.conf

cp -b /etc/nix/registry.json /etc/nix/registry.json~
echo '{
  "version": 2,
  "flakes": [ { 
      "from": { "type": "indirect", "id": "nixpkgs" },
      "to": { "type": "path", "path": "/etc/nixpkgs" }
    } ]
}' | sudo tee /etc/nix/registry.json

sudo systemctl restart nix-daemon.service

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