From e7c07009592b1aa6d1c0fbdeaa6d62a95d991803 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 28 Dec 2020 23:08:11 -0700 Subject: [PATCH 1/2] factor out a generic fetch from nixpkgs-compat Create fetch function which takes a valid flake input, and calls fetchTarball with the revision and hash information from the flake.lock. Useful for pulling the exact revision of flake inputs from not flake expressions, such as those in shell.nix. --- compat/fetch.nix | 17 +++++++++++++++++ compat/nixpkgs.nix | 5 +++++ nixpkgs-compat.nix | 13 ------------- shell.nix | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 compat/fetch.nix create mode 100644 compat/nixpkgs.nix delete mode 100644 nixpkgs-compat.nix diff --git a/compat/fetch.nix b/compat/fetch.nix new file mode 100644 index 00000000..01f0f02f --- /dev/null +++ b/compat/fetch.nix @@ -0,0 +1,17 @@ +let + inherit (builtins) + fetchTarball + fromJSON + readFile + ; + lockfile = fromJSON (readFile ../flake.lock); +in +input: +let + locked = lockfile.nodes."${input}".locked; + inherit (locked) rev narHash owner repo; +in +fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; +} diff --git a/compat/nixpkgs.nix b/compat/nixpkgs.nix new file mode 100644 index 00000000..3dd503a9 --- /dev/null +++ b/compat/nixpkgs.nix @@ -0,0 +1,5 @@ +let + fetch = import ./fetch.nix; + nixpkgs = fetch "nixos"; +in +nixpkgs diff --git a/nixpkgs-compat.nix b/nixpkgs-compat.nix deleted file mode 100644 index 08b07372..00000000 --- a/nixpkgs-compat.nix +++ /dev/null @@ -1,13 +0,0 @@ -let - inherit (builtins) - fetchTarball - fromJSON - readFile - ; - nixos = (fromJSON (readFile ./flake.lock)).nodes.nixos.locked; - nixpkgs = fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/${nixos.rev}.tar.gz"; - sha256 = nixos.narHash; - }; -in -nixpkgs diff --git a/shell.nix b/shell.nix index 5aae2efc..dadb9e7f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,5 @@ let - nixpkgs' = import ./nixpkgs-compat.nix; + nixpkgs = import ./compat/nixpkgs.nix; in { pkgs ? import nixpkgs { }, nixpkgs ? nixpkgs' }: let From 893e09278bdacbc486866759987367316a3577ef Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 28 Dec 2020 23:12:27 -0700 Subject: [PATCH 2/2] shell: switch to using mkDevShell --- flake.lock | 16 ++++++++++++++++ flake.nix | 8 ++++---- profiles/develop/zsh/default.nix | 1 + shell.nix | 30 ++++++++++++++++-------------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/flake.lock b/flake.lock index a456c693..609c2d33 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "devshell": { + "locked": { + "lastModified": 1607956014, + "narHash": "sha256-kcmh1ZO56GFYStDeM2VngJSvx/e8aKhFSYqLwfiq+Es=", + "owner": "numtide", + "repo": "devshell", + "rev": "17f46732ce299daa2977be2978f60d258c2d1b41", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1605370193, @@ -93,6 +108,7 @@ }, "root": { "inputs": { + "devshell": "devshell", "flake-utils": "flake-utils", "home": "home", "master": "master", diff --git a/flake.nix b/flake.nix index e10ad293..91b990c2 100644 --- a/flake.nix +++ b/flake.nix @@ -7,9 +7,10 @@ nixos.url = "nixpkgs/release-20.09"; home.url = "github:nix-community/home-manager/release-20.09"; flake-utils.url = "github:numtide/flake-utils"; + devshell.url = "github:numtide/devshell"; }; - outputs = inputs@{ self, home, nixos, master, flake-utils, nur }: + outputs = inputs@{ self, home, nixos, master, flake-utils, nur, devshell }: let inherit (builtins) attrNames attrValues readDir elem pathExists filter; inherit (flake-utils.lib) eachDefaultSystem mkApp; @@ -23,7 +24,7 @@ system = "x86_64-linux"; - externOverlays = [ nur.overlay ]; + externOverlays = [ nur.overlay devshell.overlay ]; externModules = [ home.nixosModules.home-manager ]; pkgset = @@ -57,7 +58,7 @@ pkgs' = pkgImport { pkgs = master; system = system'; - overlays = [ ]; + overlays = [ devshell.overlay ]; }; packages' = genPackages { @@ -79,7 +80,6 @@ { devShell = import ./shell.nix { pkgs = pkgs'; - nixpkgs = nixos; }; apps = diff --git a/profiles/develop/zsh/default.nix b/profiles/develop/zsh/default.nix index 4493b609..7491dcd2 100644 --- a/profiles/develop/zsh/default.nix +++ b/profiles/develop/zsh/default.nix @@ -46,6 +46,7 @@ in systemPackages = with pkgs; [ bat bzip2 + devshell exa gitAndTools.hub gzip diff --git a/shell.nix b/shell.nix index dadb9e7f..27bb9200 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,11 @@ let nixpkgs = import ./compat/nixpkgs.nix; + fetch = import ./compat/fetch.nix; + + devshell' = fetch "devshell"; + pkgs' = import devshell' { inherit nixpkgs; }; in -{ pkgs ? import nixpkgs { }, nixpkgs ? nixpkgs' }: +{ pkgs ? pkgs', ... }: let configs = "${toString ./.}#nixosConfigurations"; build = "config.system.build"; @@ -22,14 +26,20 @@ let sudo nixos-rebuild --flake ".#$1" $@ fi ''; + + nix = pkgs.writeShellScriptBin "nix" '' + ${pkgs.nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@" + ''; in -pkgs.mkShell { +pkgs.mkDevShell { name = "nixflk"; - nativeBuildInputs = with pkgs; with installPkgs; [ + + packages = with pkgs; with installPkgs; [ git git-crypt flk - nix-zsh-completions + nix + nixpkgs-fmt python38Packages.grip nixos-install nixos-generate-config @@ -37,14 +47,6 @@ pkgs.mkShell { nixos-rebuild ]; - shellHook = '' - mkdir -p secrets - if ! nix flake show &> /dev/null; then - PATH=${ - pkgs.writeShellScriptBin "nix" '' - ${pkgs.nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@" - '' - }/bin:$PATH - fi - ''; + env = { }; + }