diff --git a/doc/flk/update.md b/doc/flk/update.md index 84f25208..8163ddab 100644 --- a/doc/flk/update.md +++ b/doc/flk/update.md @@ -1,16 +1,22 @@ # update The `update` subcommand is a simple alias for: ```sh -nix flake update --recreate-lock-file --commit-lock-file +nix flake update ``` -As it sounds, this will update your lock file, and commit it. +As it sounds, this will update your lock file. ## Updating Package Sources -If you pass an input name then it will only update that input. +If you pass directory name then it will update that input if the directory +contains a flake.nix, with an optional arguement to update only a specific +input in the subflake. For example, you can update any [package sources](../../pkgs#automatic-source-updates) you may have declared in _pkgs/flake.nix_: ```sh -flk update srcs +flk update pkgs +``` +or just its _nixpkgs_: +```sh +flk update pkgs nixpkgs ``` diff --git a/extern/default.nix b/extern/default.nix index 07f983cc..ecfffcd6 100644 --- a/extern/default.nix +++ b/extern/default.nix @@ -9,11 +9,13 @@ in ]; overlays = [ + nix.overlay nur.overlay devshell.overlay (final: prev: { deploy-rs = deploy.packages.${prev.system}.deploy-rs; }) + pkgs.overlay ]; # passed to all nixos modules diff --git a/flake.lock b/flake.lock index bb6b51d6..9605a99f 100644 --- a/flake.lock +++ b/flake.lock @@ -152,6 +152,25 @@ "type": "github" } }, + "nix": { + "inputs": { + "nixpkgs": [ + "nixos" + ] + }, + "locked": { + "lastModified": 1615476733, + "narHash": "sha256-iae4JMAl2KAaPhUGLMf4/DEejWjs5fWfEU1ccVF8s6Q=", + "owner": "NixOS", + "repo": "nix", + "rev": "8127094f767b6caae145bc395a504ca62f30af3e", + "type": "github" + }, + "original": { + "id": "nix", + "type": "indirect" + } + }, "nixos": { "locked": { "lastModified": 1614531331, @@ -210,6 +229,22 @@ "type": "indirect" } }, + "pkgs": { + "inputs": { + "nixpkgs": [ + "nixos" + ] + }, + "locked": { + "narHash": "sha256-sBVaeGxxs7sk7PodW1mqJbF0CqUqUar0GUdd+OPnZ8o=", + "path": "./pkgs", + "type": "path" + }, + "original": { + "path": "./pkgs", + "type": "path" + } + }, "pre-commit-hooks-nix": { "flake": false, "locked": { @@ -235,25 +270,15 @@ "flake-compat": "flake-compat", "home": "home", "naersk": "naersk", + "nix": "nix", "nixos": "nixos", "nixos-hardware": "nixos-hardware", "nur": "nur", "override": "override", - "srcs": "srcs", + "pkgs": "pkgs", "utils": "utils" } }, - "srcs": { - "locked": { - "narHash": "sha256-Ot96/oKT5+A5kdqkfYyT45cfEiqhI5UyPdEfEZjbXaA=", - "path": "./pkgs", - "type": "path" - }, - "original": { - "path": "./pkgs", - "type": "path" - } - }, "utils": { "locked": { "lastModified": 1608663846, diff --git a/flake.nix b/flake.nix index 7a55dfe7..ad399369 100644 --- a/flake.nix +++ b/flake.nix @@ -22,12 +22,14 @@ home.inputs.nixpkgs.follows = "nixos"; naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "override"; + nix.inputs.nixpkgs.follows = "nixos"; nixos-hardware.url = "github:nixos/nixos-hardware"; utils.url = "github:numtide/flake-utils/flatten-tree-system"; - srcs.url = "path:./pkgs"; + pkgs.url = "path:./pkgs"; + pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: + outputs = inputs@{ deploy, nixos, nur, nix, self, utils, ... }: let inherit (self) lib; inherit (lib) os; diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix index 5fe48dbf..f9e53e71 100644 --- a/lib/devos/mkPkgs.nix +++ b/lib/devos/mkPkgs.nix @@ -14,42 +14,6 @@ in (overridesOverlay overridePkgs) self.overlay (final: prev: { - srcs = - let - mkVersion = name: input: - let - inputs = (builtins.fromJSON - (builtins.readFile ../../flake.lock)).nodes; - - ref = - if lib.hasAttrByPath [ name "original" "ref" ] inputs - then inputs.${name}.original.ref - else ""; - - version = - let version' = builtins.match - "[[:alpha:]]*[-._]?([0-9]+(\.[0-9]+)*)+" - ref; - in - if lib.isList version' - then lib.head version' - else if input ? lastModifiedDate && input ? shortRev - then "${lib.substring 0 8 input.lastModifiedDate}_${input.shortRev}" - else null; - in - version; - in - lib.mapAttrs - (name: input: - let - version = mkVersion name input; - in - input // lib.optionalAttrs (! isNull version) - { - inherit version; - } - ) - self.inputs.srcs.inputs; lib = prev.lib.extend (lfinal: lprev: { inherit dev; inherit (lib) nixosSystem; diff --git a/overlays/nixFlakes.nix b/overlays/nixFlakes.nix index 54c8a0d5..1ff88677 100644 --- a/overlays/nixFlakes.nix +++ b/overlays/nixFlakes.nix @@ -1,5 +1,5 @@ final: prev: { - nixFlakes = prev.nixFlakes.overrideAttrs + nixFlakes = final.nix.overrideAttrs (self: let oldPatches = self.patches or [ ]; diff --git a/overrides/default.nix b/overrides/default.nix index 47a5a236..78e6ee85 100644 --- a/overrides/default.nix +++ b/overrides/default.nix @@ -9,12 +9,12 @@ # packages pulled from override packages = pkgs: final: prev: { inherit (pkgs) + cachix dhall discord element-desktop manix nixpkgs-fmt - nixFlakes qutebrowser signal-desktop starship; diff --git a/pkgs/flake.lock b/pkgs/flake.lock new file mode 100644 index 00000000..15754953 --- /dev/null +++ b/pkgs/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1615769536, + "narHash": "sha256-oah5pb8kXyFa6ZcccvfREuY9VXHkUTNaoClXW7H1XUw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63a9f162355ec84c423690869a97848d73409fb8", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/pkgs/flake.nix b/pkgs/flake.nix index 257fbe3b..1b6cc0a2 100644 --- a/pkgs/flake.nix +++ b/pkgs/flake.nix @@ -1,7 +1,52 @@ { - description = "Package sources"; + description = "Package Sources"; inputs = { }; - outputs = { ... }: { }; + outputs = { self, nixpkgs, ... }: { + overlay = final: prev: { + inherit (self) srcs; + }; + + srcs = + let + inherit (nixpkgs) lib; + + mkVersion = name: input: + let + inputs = (builtins.fromJSON + (builtins.readFile ./flake.lock)).nodes; + + ref = + if lib.hasAttrByPath [ name "original" "ref" ] inputs + then inputs.${name}.original.ref + else ""; + + version = + let version' = builtins.match + "[[:alpha:]]*[-._]?([0-9]+(\.[0-9]+)*)+" + ref; + in + if lib.isList version' + then lib.head version' + else if input ? lastModifiedDate && input ? shortRev + then "${lib.substring 0 8 input.lastModifiedDate}_${input.shortRev}" + else null; + in + version; + in + lib.mapAttrs + (pname: input: + let + version = mkVersion pname input; + in + input // { inherit pname; } + // lib.optionalAttrs (! isNull version) + { + inherit version; + } + ) + (lib.filterAttrs (n: _: n != "nixpkgs") + self.inputs); + }; } diff --git a/shell/default.nix b/shell/default.nix index a7de9830..d6b48833 100644 --- a/shell/default.nix +++ b/shell/default.nix @@ -22,6 +22,7 @@ pkgs.devshell.mkShell nixos-install nixos-generate-config nixos-enter + pkgs.nixFlakes ]; git.hooks = { diff --git a/shell/devshell.toml b/shell/devshell.toml index 1b869441..f261fdc3 100644 --- a/shell/devshell.toml +++ b/shell/devshell.toml @@ -25,8 +25,5 @@ category = "documentation" package = "mdbook" category = "documentation" -[[commands]] -package = "nixFlakes" - [git.hooks] enable = true diff --git a/shell/flk.sh b/shell/flk.sh index 32b0a210..875e7559 100755 --- a/shell/flk.sh +++ b/shell/flk.sh @@ -50,9 +50,14 @@ case "$1" in "update") if [[ -n "$2" ]]; then - nix flake update --update-input "$2" --commit-lock-file "$DEVSHELL_ROOT" + if [[ -n "$3" ]]; then + (cd $2; nix flake list-inputs --update-input "$3") + else + (cd $2; nix flake update) + fi + nix flake list-inputs --update-input "$2" "$DEVSHELL_ROOT" else - nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT" + nix flake update "$DEVSHELL_ROOT" fi ;;