subflakes: make first class citizens

Subflakes should provide their wares as outputs, so wire up the pkgs
flake to reflect that.

Due to the unstable nature of flakes, updating the root flake doesn't
currently update the subflake lock file. Therefore, add additional
logic to flk update script in order to do this behind the scenes.

Nix is now pulled in from the "nix" registry flake in order for users
to take advantage of improvements to the UI since its last update in
nixpkgs.
This commit is contained in:
Timothy DeHerrera 2021-03-14 21:27:58 -06:00
parent d7f15a664d
commit d51cd34fb7
No known key found for this signature in database
GPG Key ID: 8985725DB5B0C122
12 changed files with 135 additions and 63 deletions

View File

@ -1,16 +1,22 @@
# update # update
The `update` subcommand is a simple alias for: The `update` subcommand is a simple alias for:
```sh ```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 ## 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 For example, you can update any
[package sources](../../pkgs#automatic-source-updates) you may have declared [package sources](../../pkgs#automatic-source-updates) you may have declared
in _pkgs/flake.nix_: in _pkgs/flake.nix_:
```sh ```sh
flk update srcs flk update pkgs
```
or just its _nixpkgs_:
```sh
flk update pkgs nixpkgs
``` ```

2
extern/default.nix vendored
View File

@ -9,11 +9,13 @@ in
]; ];
overlays = [ overlays = [
nix.overlay
nur.overlay nur.overlay
devshell.overlay devshell.overlay
(final: prev: { (final: prev: {
deploy-rs = deploy.packages.${prev.system}.deploy-rs; deploy-rs = deploy.packages.${prev.system}.deploy-rs;
}) })
pkgs.overlay
]; ];
# passed to all nixos modules # passed to all nixos modules

View File

@ -152,6 +152,25 @@
"type": "github" "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": { "nixos": {
"locked": { "locked": {
"lastModified": 1614531331, "lastModified": 1614531331,
@ -210,6 +229,22 @@
"type": "indirect" "type": "indirect"
} }
}, },
"pkgs": {
"inputs": {
"nixpkgs": [
"nixos"
]
},
"locked": {
"narHash": "sha256-sBVaeGxxs7sk7PodW1mqJbF0CqUqUar0GUdd+OPnZ8o=",
"path": "./pkgs",
"type": "path"
},
"original": {
"path": "./pkgs",
"type": "path"
}
},
"pre-commit-hooks-nix": { "pre-commit-hooks-nix": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -235,25 +270,15 @@
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"home": "home", "home": "home",
"naersk": "naersk", "naersk": "naersk",
"nix": "nix",
"nixos": "nixos", "nixos": "nixos",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nur": "nur", "nur": "nur",
"override": "override", "override": "override",
"srcs": "srcs", "pkgs": "pkgs",
"utils": "utils" "utils": "utils"
} }
}, },
"srcs": {
"locked": {
"narHash": "sha256-Ot96/oKT5+A5kdqkfYyT45cfEiqhI5UyPdEfEZjbXaA=",
"path": "./pkgs",
"type": "path"
},
"original": {
"path": "./pkgs",
"type": "path"
}
},
"utils": { "utils": {
"locked": { "locked": {
"lastModified": 1608663846, "lastModified": 1608663846,

View File

@ -22,12 +22,14 @@
home.inputs.nixpkgs.follows = "nixos"; home.inputs.nixpkgs.follows = "nixos";
naersk.url = "github:nmattia/naersk"; naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "override"; naersk.inputs.nixpkgs.follows = "override";
nix.inputs.nixpkgs.follows = "nixos";
nixos-hardware.url = "github:nixos/nixos-hardware"; nixos-hardware.url = "github:nixos/nixos-hardware";
utils.url = "github:numtide/flake-utils/flatten-tree-system"; 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 let
inherit (self) lib; inherit (self) lib;
inherit (lib) os; inherit (lib) os;

View File

@ -14,42 +14,6 @@ in
(overridesOverlay overridePkgs) (overridesOverlay overridePkgs)
self.overlay self.overlay
(final: prev: { (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: { lib = prev.lib.extend (lfinal: lprev: {
inherit dev; inherit dev;
inherit (lib) nixosSystem; inherit (lib) nixosSystem;

View File

@ -1,5 +1,5 @@
final: prev: { final: prev: {
nixFlakes = prev.nixFlakes.overrideAttrs nixFlakes = final.nix.overrideAttrs
(self: (self:
let let
oldPatches = self.patches or [ ]; oldPatches = self.patches or [ ];

View File

@ -9,12 +9,12 @@
# packages pulled from override # packages pulled from override
packages = pkgs: final: prev: { packages = pkgs: final: prev: {
inherit (pkgs) inherit (pkgs)
cachix
dhall dhall
discord discord
element-desktop element-desktop
manix manix
nixpkgs-fmt nixpkgs-fmt
nixFlakes
qutebrowser qutebrowser
signal-desktop signal-desktop
starship; starship;

25
pkgs/flake.lock Normal file
View File

@ -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
}

View File

@ -1,7 +1,52 @@
{ {
description = "Package sources"; description = "Package Sources";
inputs = { }; 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);
};
} }

View File

@ -22,6 +22,7 @@ pkgs.devshell.mkShell
nixos-install nixos-install
nixos-generate-config nixos-generate-config
nixos-enter nixos-enter
pkgs.nixFlakes
]; ];
git.hooks = { git.hooks = {

View File

@ -25,8 +25,5 @@ category = "documentation"
package = "mdbook" package = "mdbook"
category = "documentation" category = "documentation"
[[commands]]
package = "nixFlakes"
[git.hooks] [git.hooks]
enable = true enable = true

View File

@ -50,9 +50,14 @@ case "$1" in
"update") "update")
if [[ -n "$2" ]]; then 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 else
nix flake update --recreate-lock-file --commit-lock-file "$DEVSHELL_ROOT" nix flake update "$DEVSHELL_ROOT"
fi fi
;; ;;