Skip to content

Commit

Permalink
Rewrite CLI in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Jul 23, 2023
1 parent 12924d4 commit 941b1bd
Show file tree
Hide file tree
Showing 17 changed files with 920 additions and 688 deletions.
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"customizations": {
"vscode": {
"extensions": [
"bbenoist.Nix"
"jnoortheen.nix-ide"
]
}
},
Expand Down
4 changes: 0 additions & 4 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Used by https://direnv.net
set -euo pipefail

# Use our own last built devenv/nix in CLI
devenv_bin=$(nix build --print-out-paths --accept-flake-config)
PATH_add "$devenv_bin/bin"

# External users should use `source_url` to load this file
source_env ./direnvrc

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
- run: devenv shell devenv-test-example ${{ matrix.example }}
direnv:
name: direnv (${{ join(matrix.os) }})
needs: build
strategy:
fail-fast: false
matrix:
Expand All @@ -99,7 +100,7 @@ jobs:
}
' ./examples/simple/devenv.yaml.orig > ./examples/simple/devenv.yaml
nix profile remove '.*'
nix profile install . 'nixpkgs#direnv'
nix profile install . 'nixpkgs#direnv' nix profile install --accept-flake-config
mkdir -p ~/.config/direnv/
cat > ~/.config/direnv/direnv.toml << 'EOF'
[global]
Expand All @@ -109,6 +110,7 @@ jobs:
direnv exec ./examples/simple true
fish-zsh:
name: zsh/fish (${{ join(matrix.os) }})
needs: build
strategy:
fail-fast: false
matrix:
Expand Down
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Nix & devenv
result
.env*
/.env*
.devenv*
/.cache
/.pre-commit-config.yaml
/bin
/include
/lib
pyvenv.cfg
/.direnv
/.venv

# examples
examples/rust/app/target

# Python
/.venv
*.pyc
17 changes: 9 additions & 8 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{ inputs, pkgs, lib, config, ... }:

{
env = {
DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
};

packages = [
(import ./src/devenv.nix { inherit pkgs; nix = inputs.nix; })
pkgs.cairo
pkgs.xorg.libxcb
pkgs.yaml2json
];

languages.nix.enable = true;
languages.python.enable = true;
languages.python.venv.enable = true;
languages.python.poetry.enable = true;
languages.python.poetry.install.installRootPackage = true;
languages.python.poetry.install.groups = [ "docs" ];

devcontainer.enable = true;
devcontainer.settings.customizations.vscode.extensions = [ "jnoortheen.nix-ide" ];
Expand All @@ -21,7 +25,6 @@

# bin/mkdocs serve --config-file mkdocs.insiders.yml
processes.docs.exec = "mkdocs serve";
processes.build.exec = "${pkgs.watchexec}/bin/watchexec -e nix nix build";

scripts.devenv-bump-version.exec = ''
# TODO: ask for the new version
Expand Down Expand Up @@ -51,7 +54,7 @@
nix flake init --template ''${DEVENV_ROOT}#simple
nix flake update \
--override-input devenv ''${DEVENV_ROOT}
nix develop --impure --command echo nix-develop started succesfully |& tee ./console
nix develop --accept-flake-config --impure --command echo nix-develop started succesfully |& tee ./console
grep -F 'nix-develop started succesfully' <./console
grep -F "$(${lib.getExe pkgs.hello})" <./console
Expand All @@ -71,15 +74,13 @@
nix flake init --template ''${DEVENV_ROOT}#flake-parts
nix flake update \
--override-input devenv ''${DEVENV_ROOT}
nix develop --impure --command echo nix-develop started succesfully |& tee ./console
nix develop --accept-flake-config --impure --command echo nix-develop started succesfully |& tee ./console
grep -F 'nix-develop started succesfully' <./console
grep -F "$(${lib.getExe pkgs.hello})" <./console
# Test that a container can be built
nix build --impure .#container-processes
nix build --impure --accept-flake-config .#container-processes
popd
rm -rf "$tmp"
# TODO: test DIRENV_ACTIVE
'';
scripts.devenv-test-all-examples.exec = ''
for dir in $(ls examples); do
Expand Down
91 changes: 84 additions & 7 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
url = "github:domenkozar/nix/relaxed-flakes";
inputs.nixpkgs.follows = "nixpkgs";
};
inputs.poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};

outputs = { self, nixpkgs, pre-commit-hooks, nix, ... }@inputs:
let
systems = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = f: builtins.listToAttrs (map (name: { inherit name; value = f name; }) systems);
mkPackage = pkgs: import ./src/devenv.nix {
inherit pkgs nix;
};
mkPackage = pkgs: import ./package.nix { inherit pkgs inputs; };
mkDevShellPackage = config: pkgs: import ./src/devenv-devShell.nix { inherit config pkgs; };
mkDocOptions = pkgs:
let
Expand Down
31 changes: 31 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ pkgs, inputs }:

let
python_slim = pkgs.python311.override {
mimetypesSupport = false;
x11Support = false;
stripConfig = true;
stripIdlelib = true;
stripTests = true;
stripTkinter = true;
rebuildBytecode = true;
stripBytecode = true;
includeSiteCustomize = false;
enableOptimizations = false;
bzip2 = null;
gdbm = null;
xz = null;
ncurses = null;
readline = null;
sqlite = null;
tzdata = null;
};
in
(inputs.poetry2nix.legacyPackages.${pkgs.stdenv.system}.mkPoetryApplication {
projectDir = ./.;
python = python_slim;
}).overrideAttrs (old: {
makeWrapperArgs = [
"--set DEVENV_NIX ${inputs.nix.packages.${pkgs.stdenv.system}.nix}"
];
})
Loading

0 comments on commit 941b1bd

Please sign in to comment.